Commit fe52bed0 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

first approach to search Db Ovelay

clicking on map access appropriate elements vi api
parent 0b8a49b6
......@@ -43,13 +43,6 @@ ServerConnector.formIdentifier = "_gmapForm";
ServerConnector._customMap = null;
/**
* Sets search query that will be handled by server.
*/
ServerConnector.setSearchQuery = function(value) {
document.getElementById(ServerConnector.formIdentifier + ':mapParam').value = "" + value;
};
/**
* Sets data mining query that will be handled by server.
*/
......@@ -153,11 +146,6 @@ ServerConnector.updateOverlayCollection = function(overlayName, data, fitBounds)
}
};
/**
* Name of the overlay for 'search' overlay.
*/
ServerConnector.SEARCH_OVERLAY_NAME = 'search';
/**
* Name of the overlay for 'data mining' overlay.
*/
......@@ -178,30 +166,6 @@ ServerConnector.CHEMICAL_OVERLAY_NAME = 'chemical';
*/
ServerConnector.MI_RNA_OVERLAY_NAME = 'mirna';
/**
* Register 'search' overlay on the server.
*/
ServerConnector.registerSearchOverlay = function() {
_registerSearchOverlayCollection([ {
name : "overlayName",
value : ServerConnector.SEARCH_OVERLAY_NAME,
} ]);
};
/**
* Sends request to the server to refresh data in 'search' overlay.
*/
ServerConnector.refreshSearchOverlay = function() {
_refreshSearchOverlayCollection();
};
/**
* Clear data related to 'search' overlay..
*/
ServerConnector.clearSearchOverlay = function() {
_clearSearchOverlayCollection();
};
/**
* Register 'data mining' overlay on the server.
*/
......@@ -351,15 +315,6 @@ ServerConnector.clearMiRnaOverlay = function() {
_clearMiRnaOverlayCollection();
};
/**
* Define pack of methods for 'search' overlay.
*/
ServerConnector._overlayMethods[ServerConnector.SEARCH_OVERLAY_NAME] = {
initFunction : ServerConnector.registerSearchOverlay,
refreshFunction : ServerConnector.refreshSearchOverlay,
clearFunction : ServerConnector.clearSearchOverlay,
};
/**
* Define pack of methods for 'data minig' overlay.
*/
......@@ -495,19 +450,6 @@ ServerConnector.addReactions = function(jsonReactions) {
this.getCustomMap().addReactions(jsonReactions);
};
ServerConnector.searchByCoord = function(modelId, latLngCoordinates) {
_searchByCoord([ {
name : 'submodelId',
value : modelId
}, {
name : 'latCoord',
value : latLngCoordinates.lat()
}, {
name : 'lngCoord',
value : latLngCoordinates.lng()
} ]);
};
ServerConnector.sendReferenceGenomeDetailRequest = function(type, version) {
logger.debug("Send request", type, version);
_sendReferenceGenomeDetailRequest([ {
......@@ -726,7 +668,7 @@ ServerConnector.idsToString = function (ids) {
};
ServerConnector.pointToString = function (point) {
return point.x+","+point.y;
return point.x.toFixed(2)+","+point.y.toFixed(2);
};
ServerConnector.columnsToString = function (columns) {
......@@ -781,13 +723,15 @@ ServerConnector.getClosestElementsByCoordinatesUrl = function(params) {
var projectId = params.projectId;
var modelId = params.modelId;
var token = params.token;
var count = params.count;
return this.getApiUrl({type:"project",
method:"getClosestElementsByCoordinates",
params: {
projectId: projectId,
coordinates: coordinates,
modelId: modelId,
modelId: modelId,
count: count,
token: token},
});
};
......@@ -1020,13 +964,13 @@ ServerConnector.getSessionData = function(project) {
ServerConnector.getClosestElementsByCoordinates = function(params) {
var self = this;
var projectId;
return new Promise(function(resolve, reject) {
return self.getProjectId(params.projectId).then(function(result) {
projectId = result;
params.projectId = result;
return self.getToken();
}).then(function(token) {
return self.readFile(self.getClosestElementsByCoordinatesUrl({projectId:projectId, token:token, modelId:params.modelId, coordinates: params.coordinates}));
params.token = token;
return self.readFile(self.getClosestElementsByCoordinatesUrl(params));
}).then(function(content) {
var array=JSON.parse(content);
var result = [];
......
......@@ -313,7 +313,11 @@ AbstractCustomMap.prototype.registerMapClickEvents = function() {
// search event
google.maps.event.addListener(this.getGoogleMap(), 'click', function(mouseEvent) {
ServerConnector.searchByCoord(self.getId(), mouseEvent.latLng);
var point = self.fromLatLngToPoint(mouseEvent.latLng);
var searchDb = customMap.getOverlayByName('search');
return searchDb.searchByCoordinates(self.getModel(), point).then(function() {
return customMap.updateOverlayCollection(searchDb, false);
}).catch(GuiConnector.alert);
});
// select last clicked map
......@@ -685,8 +689,8 @@ AbstractCustomMap.prototype.getAliasVisibleLayoutsData = function(aliasId) {
for (var i = 0; i < layoutIds.length; i++) {
promises.push(this.getModel().getLayoutDataById(layoutIds[i]));
}
return new Promise(function(resolve){
return Promise.all(promises).then(function(layouts){
return new Promise(function(resolve) {
return Promise.all(promises).then(function(layouts) {
var result = [];
for (var i = 0; i < layouts.length; i++) {
var layout = layouts[i];
......
......@@ -16,6 +16,7 @@ var PointMarker = require('./marker/PointMarker');
var ReactionMarker = require('./marker/ReactionMarker');
var ReactionOverlay = require('./overlay/ReactionOverlay');
var ReferenceGenome = require('./data/ReferenceGenome');
var SearchDbCollection = require('./overlay/SearchDbOverlay');
var Submap = require('./Submap');
var TouchMap = require('./TouchMap');
......@@ -214,7 +215,9 @@ CustomMap.prototype.refreshOverlays = function() {
for ( var overlayName in this.overlayCollections) {
if (this.overlayCollections.hasOwnProperty(overlayName)) {
var collection = this.overlayCollections[overlayName];
promises.push(collection.refresh());
if (!collection instanceof SearchDbCollection) {
promises.push(collection.refresh());
}
}
}
return Promise.all(promises);
......@@ -549,25 +552,16 @@ CustomMap.prototype.refreshOverlayMarkers = function(overlay) {
if (overlay.reactionMarkers.hasOwnProperty(reactionKey) && overlay.reactionMarkers[reactionKey] !== undefined
&& overlay.reactionMarkers[reactionKey] !== null) {
var reactionOverlay = overlay.reactionMarkers[reactionKey];
if (reactionOverlay.getReactionData() === null || reactionOverlay.getReactionData() === undefined) {
reactionOverlay.getCustomMap().getModel().getReactionById(reactionOverlay.getId()).then(function(reactionData) {
reactionOverlay.setReactionData(reactionData);
reactionOverlay.init();
reactionOverlay.show();
updated = true;
bounds = reactionOverlay.getBounds();
boundsArray[reactionOverlay.getCustomMap().getId()].extend(bounds.getNorthEast());
boundsArray[reactionOverlay.getCustomMap().getId()].extend(bounds.getSouthWest());
});
} else {
bounds = reactionOverlay.getBounds();
if (!this.isMarkerOptimization()) {
reactionOverlay.hide();
reactionOverlay.show();
}
boundsArray[reactionOverlay.getCustomMap().getId()].extend(bounds.getNorthEast());
boundsArray[reactionOverlay.getCustomMap().getId()].extend(bounds.getSouthWest());
if (!reactionOverlay.isShown()) {
reactionOverlay.show();
}
bounds = reactionOverlay.getBounds();
if (!this.isMarkerOptimization()) {
reactionOverlay.hide();
reactionOverlay.show();
}
boundsArray[reactionOverlay.getCustomMap().getId()].extend(bounds.getNorthEast());
boundsArray[reactionOverlay.getCustomMap().getId()].extend(bounds.getSouthWest());
}
}
......@@ -1356,70 +1350,75 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
fitBounds = overlayCollection.fitBounds;
overlayCollection = overlayCollection.overlayCollection;
}
var elements;
return overlayCollection.getIdentifiedElements().then(function(identifiedElements){
elements = identifiedElements;
var boundsArray = [];
boundsArray[self.getId()] = new google.maps.LatLngBounds();
for (var j = 0; j < self.submaps.length; j++) {
boundsArray[self.submaps[j].getId()] = new google.maps.LatLngBounds();
}
var elements = overlayCollection.getIdentifiedElements();
var boundsArray = [];
boundsArray[this.getId()] = new google.maps.LatLngBounds();
for (var j = 0; j < this.submaps.length; j++) {
boundsArray[this.submaps[j].getId()] = new google.maps.LatLngBounds();
}
var bounds;
return Promise.each(
elements,
function(element) {
var model = self.getSubmodelById(element.modelId);
if (element.getType() === "ALIAS") {
if (overlayCollection.aliasMarkers[element.getId()] !== undefined) {
logger.warn("More than one marker in " + overlayCollection.name + " for alias " + element.getId()
+ ". Skipping duplicates.");
return null;
} else {
return model.getModel().getAliasById(element.getId()).then(function(aliasData) {
var aliasMarker = new AliasMarker(element.getId(), element.icon, aliasData, model);
overlayCollection.aliasMarkers[element.getId()] = aliasMarker;
bounds = aliasMarker.getBounds();
var bounds;
return Promise.each(
elements,
function(element) {
var model = self.getSubmodelById(element.modelId);
if (element.getType() === "ALIAS") {
if (overlayCollection.aliasMarkers[element.getId()] !== undefined) {
logger.warn("More than one marker in " + overlayCollection.name + " for alias " + element.getId()
+ ". Skipping duplicates.");
return null;
} else {
return model.getModel().getAliasById(element.getId()).then(function(aliasData) {
var aliasMarker = new AliasMarker(element.getId(), element.icon, aliasData, model);
overlayCollection.aliasMarkers[element.getId()] = aliasMarker;
bounds = aliasMarker.getBounds();
boundsArray[element.getModelId()].extend(bounds.getNorthEast());
boundsArray[element.getModelId()].extend(bounds.getSouthWest());
return aliasMarker;
});
}
} else if (element.getType() === "REACTION") {
return model.getModel().getReactionById(element.getId()).then(function(reactionData) {
var marker = null;
var icon = element.getIcon();
if (icon === null || icon === undefined) {
// this should happen when we visualize search data (there is
// no marker, but only flat overlay of the reaction lines)
//
marker = new ReactionOverlay(null, reactionData, model, false, element.getId());
} else {
// when we have icon defined (for instance when it comes from
// comment) then we don't want to have overlayed reaction lines
// but icon marker
marker = new ReactionMarker(element.getId(), icon, reactionData, model);
}
marker.show();
overlayCollection.reactionMarkers[element.getId()] = marker;
bounds = marker.getBounds();
boundsArray[element.getModelId()].extend(bounds.getNorthEast());
boundsArray[element.getModelId()].extend(bounds.getSouthWest());
return aliasMarker;
return marker;
});
}
} else if (element.getType() === "REACTION") {
return model.getModel().getReactionById(element.getId()).then(function(reactionData) {
var marker = null;
var icon = element.getIcon();
if (icon === null || icon === undefined) {
// this should happen when we visualize search data (there is
// no marker, but only flat overlay of the reaction lines)
//
marker = new ReactionOverlay(null, reactionData, model, false, element.getId());
} else {
// when we have icon defined (for instance when it comes from
// comment) then we don't want to have overlayed reaction lines
// but icon marker
marker = new ReactionMarker(element.getId(), icon, reactionData, model);
}
overlayCollection.reactionMarkers[element.getId()] = marker;
bounds = marker.getBounds();
} else if (element.getType() === "POINT") {
var pointData = model.getModel().getPointDataByPoint(element.getPoint());
var pointMarker = new PointMarker(pointData, element.icon, model);
overlayCollection.pointMarkers[pointData.getId()] = pointMarker;
bounds = pointMarker.getBounds();
boundsArray[element.getModelId()].extend(bounds.getNorthEast());
boundsArray[element.getModelId()].extend(bounds.getSouthWest());
return marker;
});
} else if (element.getType() === "POINT") {
var pointData = model.getModel().getPointDataByPoint(element.getPoint());
var pointMarker = new PointMarker(pointData, element.icon, model);
overlayCollection.pointMarkers[pointData.getId()] = pointMarker;
bounds = pointMarker.getBounds();
boundsArray[element.getModelId()].extend(bounds.getNorthEast());
boundsArray[element.getModelId()].extend(bounds.getSouthWest());
return pointMarker;
} else {
throw new Error("Unknown type of the element in overlay: " + element.type);
}
}).then(function() {
return pointMarker;
} else {
throw new Error("Unknown type of the element in overlay: " + element.type);
}
});
}).then(function() {
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
var infoWindow = self.getInfoWindowForIdentifiedElement(element);
......@@ -1447,6 +1446,8 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
});
};
/**
......@@ -1646,6 +1647,10 @@ CustomMap.prototype.getOverlayDataForIdentifiedElement = function(identifiedElem
});
};
CustomMap.prototype.getOverlayByName = function(name) {
return this.overlayCollections[name];
};
/**
* Returns {@link AbstractInfoWindow} for element identified by the parameter.
*
......
......@@ -21,15 +21,15 @@ function IdentifiedElement(javaObject) {
if (javaObject instanceof Alias) {
this.setId(javaObject.getId());
this.setModelId(javaObject.getModelId());
this.type = "ALIAS";
this.setType("ALIAS");
} else if (javaObject instanceof Reaction) {
this.setId(javaObject.getId());
this.setModelId(javaObject.getModelId());
this.type = "REACTION";
this.setType("REACTION");
} else if (javaObject instanceof PointData) {
this.setId(javaObject.getId());
this.setModelId(javaObject.getModelId());
this.type = "POINT";
this.setType("POINT");
} else {
// identifier of the object to visualize
if (javaObject.objectId === undefined) {
......@@ -38,19 +38,14 @@ function IdentifiedElement(javaObject) {
this.setId(javaObject.objectId);
}
// which marker should be used to show this object
this.icon = javaObject.icon;
this.setIcon(javaObject.icon);
// on which model the element is located
this.setModelId(javaObject.modelId);
// what kind of object we are talking about
this.type = javaObject.type;
this.setType(javaObject.type);
}
if (this.type === undefined || this.type === null) {
throw new Error("Type not defined for element: " + javaObject);
}
this.type = this.type.toUpperCase();
if (this.type === "POINT") {
if (this.getType() === "POINT") {
var tmp = this.getId();
if (tmp.indexOf("Point2D.Double") >= 0) {
tmp = tmp.replace("Point2D.Double", "");
......@@ -63,8 +58,8 @@ function IdentifiedElement(javaObject) {
var x = parseFloat(tmp[0]).toFixed(2);
var y = parseFloat(tmp[1]).toFixed(2);
this._point = new google.maps.Point(x, y);
} else if (this.type !== "ALIAS" && this.type !== "REACTION") {
throw new Error("Unknown type of identified element: " + this.type);
} else if (this.getType() !== "ALIAS" && this.getType() !== "REACTION") {
throw new Error("Unknown type of identified element: " + this.getType());
}
if (this.getId() === undefined || this.getId() === null) {
......@@ -137,6 +132,14 @@ IdentifiedElement.prototype.getType = function() {
return this.type;
};
IdentifiedElement.prototype.setType = function(type) {
if (type === undefined || type === null) {
throw new Error("Type not defined");
}
this.type = type.toUpperCase();
};
/**
* Returns icon that should be used for visualization.
*
......@@ -146,4 +149,8 @@ IdentifiedElement.prototype.getIcon = function() {
return this.icon;
};
IdentifiedElement.prototype.setIcon = function(icon) {
this.icon = icon;
};
module.exports = IdentifiedElement;
......@@ -177,7 +177,7 @@ MapModel.prototype.getReactionById = function(id, complete) {
MapModel.prototype.getCompleteReactionById = function(id) {
var self = this;
return new Promise(function(resolve) {
if (self._reactions[id]!==undefined && self._reactions[id].isComplete()) {
if (self._reactions[id] instanceof Reaction && self._reactions[id].isComplete()) {
resolve(self._reactions[id]);
} else {
var result;
......@@ -296,7 +296,6 @@ MapModel.prototype.getMissingElements = function(elements) {
}
}
return new Promise(function(resolve, reject) {
Promise.all([reactionPromise, aliasPromise]).then(function(values) {
var result = [], i;
......
......@@ -39,7 +39,7 @@ function Reaction(javaObject) {
}
this.setCenter(javaObject.centerPoint);
this.setModelId(javaObject.modelId);
this.setCompletness(false);
this.setIsComplete(false);
this.update(javaObject);
}
}
......@@ -112,12 +112,12 @@ Reaction.prototype.update = function(javaObject) {
}
};
Reaction.prototype.getCompletness = function() {
return this._completness;
Reaction.prototype.isComplete = function() {
return this._complete;
};
Reaction.prototype.setCompletness = function(completness) {
this._completness = completness;
Reaction.prototype.setIsComplete = function(complete) {
this._complete = complete;
};
Reaction.prototype.getReactionId = function() {
......@@ -144,6 +144,14 @@ Reaction.prototype.getProducts = function() {
return this._products;
};
Reaction.prototype.getElements = function() {
var result = [];
result = result.concat(this.getReactants());
result = result.concat(this.getProducts());
result = result.concat(this.getModifiers());
return result;
};
Reaction.prototype.setModifiers = function(modifiers) {
this._modifiers = modifiers;
};
......
......@@ -43,14 +43,17 @@ CommentDbOverlay.prototype._getDetailArrayByIdentifiedElement = function(element
CommentDbOverlay.prototype.getIdentifiedElements = function(){
var result = [];
for (var i=0;i<this.elements.length;i++) {
//we return only elements that are pinned to the map and weren't removed
if (!this.elements[i].isRemoved()) {
result.push(this.elements[i].getIdentifiedElement());
var self = this;
return new Promise(function(resolve){
var result = [];
for (var i=0;i<self.elements.length;i++) {
// we return only elements that are pinned to the map and weren't removed
if (!self.elements[i].isRemoved()) {
result.push(self.elements[i].getIdentifiedElement());
}
}
}
return result;
resolve(result);
});
};
......
......@@ -236,8 +236,34 @@ OverlayCollection.prototype.setAllowGeneralSearch = function(allowGeneralSearch)
}
};
OverlayCollection.prototype.getIdentifiedElements = function(){
return this.elements;
OverlayCollection.prototype.getIdentifiedElements = function() {
var self = this;
return new Promise(function(resolve) {
resolve(self.elements);
});
};
OverlayCollection.prototype.setIconType = function(iconType) {
return this._iconType = iconType;
};
OverlayCollection.prototype.setIconStart = function(iconStart) {
return this._iconStart = iconStart;
};
OverlayCollection.IconColors = [ "red", "blue", "green", "purple", "yellow", "pink", "paleblue", "brown", "orange" ];
OverlayCollection.prototype.getColor = function(colorId) {
var id = colorId + this._iconStart;
id %= OverlayCollection.IconColors.length;
return OverlayCollection.IconColors[id];
}
OverlayCollection.prototype.getIcon = function(colorId, id) {
if (id >= 100) {
id = 1;
}
var color = this.getColor(colorId);
return "marker/" + this._iconType + "/" + this._iconType + "_" + color + "_" + id + ".png";
};
module.exports = OverlayCollection;
"use strict";
var Promise = require("bluebird");
var Alias = require('../data/Alias');
var IdentifiedElement = require('../data/IdentifiedElement');
var OverlayCollection = require('./OverlayCollection');
var logger = require('../../logger');
function SearchDbOverlay(params) {
// call super constructor
OverlayCollection.call(this, params);
this.setIconType("marker");
this.setIconStart(0);
this._elementsByQuery = [];
}