Commit 4ab7be22 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

rendering of overlay moved to markerSurfaceCollection

parent b041deba
......@@ -648,12 +648,11 @@ CustomMap.prototype.refreshInfoWindows = function () {
};
/**
* Opens {@link AliasInfoWindow} for an {@link Alias} in a given model/submodel.
* Opens {@link AliasInfoWindow} for an {@link Alias}.
*
* @param aliasId
* identifier of {@link Alias}
* @param modelId
* identifier of {@link AbstractCustomMap}
* @param alias
* {@link Alias}
* @param marker google.maps.Marker object
*/
CustomMap.prototype.openInfoWindowForAlias = function (alias, marker) {
logger.debug("Opening info window for alias: " + alias.getId() + ", model: " + alias.getModelId());
......@@ -664,10 +663,9 @@ CustomMap.prototype.openInfoWindowForAlias = function (alias, marker) {
/**
* Renders markers, lines, etc. for elements highlighted in OverlayCollection.
*
* @param overlayCollection
* {@link OverlayCollection} to be processed
* @param fitBounds
* <code>true</code> if the borders should fit bounds after creating
* @param params: {overlayCollection, fitBounds}
* overlayCollection - to be processed
* fitBounds - <code>true</code> if the borders should fit bounds after creating
* all elements
*/
CustomMap.prototype.renderOverlayCollection = function (params) {
......@@ -678,29 +676,19 @@ CustomMap.prototype.renderOverlayCollection = function (params) {
var elements;
var markers = [];
var submaps = self.getSubmaps().concat([self]);
return overlayCollection.getIdentifiedElements().then(function (identifiedElements) {
elements = identifiedElements;
return Promise.each(elements, function (element) {
var icon = element.getIcon();
if (icon !== null && icon !== undefined) {
return self.getSubmapById(element.getModelId()).getMarkerSurfaceCollection().createMarkerForDbOverlay(element, overlayCollection).then(function (marker) {
markers.push(marker);
});
} else {
return self.getSubmapById(element.getModelId()).getMarkerSurfaceCollection().createSurfaceForDbOverlay(element, overlayCollection).then(function (mapOverlay) {
markers.push(mapOverlay);
});
}
});
}).then(function () {
self.getMarkerSurfaceCollection().removeUnmodifiedMarkersAndSurfaces(markers, overlayCollection);
var submaps = self.getSubmaps();
var promises = [];
for (var i = 0; i < submaps.length; i++) {
submaps[i].getMarkerSurfaceCollection().removeUnmodifiedMarkersAndSurfaces(markers, overlayCollection);
promises.push(submaps[i].getMarkerSurfaceCollection().renderOverlay(identifiedElements, overlayCollection));
}
return Promise.all(promises);
}).then(function (mapMarkers) {
for (var i = 0; i < mapMarkers.length; i++) {
markers = markers.concat(mapMarkers[i]);
}
return Promise.each(elements, function (element) {
var infoWindow = self.getInfoWindowForIdentifiedElement(element);
if (infoWindow !== null && infoWindow !== undefined) {
......@@ -711,9 +699,8 @@ CustomMap.prototype.renderOverlayCollection = function (params) {
});
}).then(function () {
if (elements.length > 0 && fitBounds) {
self.fitBounds(markers);
for (var j = 0; j < self.submaps.length; j++) {
self.submaps[j].fitBounds(markers);
for (var j = 0; j < submaps.length; j++) {
submaps[j].fitBounds(markers);
}
}
});
......
......@@ -44,4 +44,8 @@ PointData.prototype.getModelId = function() {
return this._modelId;
};
PointData.prototype.isComplete = function() {
return true;
};
module.exports = PointData;
......@@ -9,7 +9,7 @@ var logger = require('../../logger');
/**
* Class representing reaction data.
*
*
* @param javaObject
* object de-serialized from ajax query to the server side
*/
......@@ -55,11 +55,11 @@ function Reaction(javaObject) {
Reaction.prototype = Object.create(BioEntity.prototype);
Reaction.prototype.constructor = Reaction;
Reaction.prototype.getCenter = function() {
Reaction.prototype.getCenter = function () {
return this._center;
};
Reaction.prototype.getLines = function() {
Reaction.prototype.getLines = function () {
var result = [];
result = result.concat(this.startLines);
result = result.concat(this.endLines);
......@@ -67,24 +67,24 @@ Reaction.prototype.getLines = function() {
return result;
};
Reaction.prototype.getMidLines = function() {
Reaction.prototype.getMidLines = function () {
return this.midLines;
};
Reaction.prototype.getStartLines = function() {
Reaction.prototype.getStartLines = function () {
return this.startLines;
};
Reaction.prototype.getEndLines = function() {
Reaction.prototype.getEndLines = function () {
return this.endLines;
};
Reaction.prototype.setCenter = function(center) {
Reaction.prototype.setCenter = function (center) {
if (center === null || center === undefined) {
throw new Error("Setting undefined center: ", center);
}
this._center = center;
};
Reaction.prototype.update = function(javaObject) {
Reaction.prototype.update = function (javaObject) {
if (javaObject.reactionId === undefined) {
return;
}
......@@ -123,85 +123,87 @@ Reaction.prototype.update = function(javaObject) {
this.setIsComplete(true);
};
Reaction.prototype.isComplete = function() {
Reaction.prototype.isComplete = function () {
var self = this;
var result = self._complete;
var reactants = self.getReactants();
if (reactants.length === 0) {
result = false;
} else {
if (!(self.getReactants()[0] instanceof Alias)) {
if (result) {
var reactants = self.getReactants();
if (reactants.length === 0) {
result = false;
} else {
if (!(self.getReactants()[0] instanceof Alias)) {
result = false;
}
}
}
return result;
};
Reaction.prototype.getReactionId = function() {
Reaction.prototype.getReactionId = function () {
return this._reactionId;
};
Reaction.prototype.setReactionId = function(reactionId) {
Reaction.prototype.setReactionId = function (reactionId) {
this._reactionId = reactionId;
};
Reaction.prototype.getMechanicalConfidenceScore = function() {
Reaction.prototype.getMechanicalConfidenceScore = function () {
return this._mechanicalConfidenceScore;
};
Reaction.prototype.setMechanicalConfidenceScore = function(mechanicalConfidenceScore) {
Reaction.prototype.setMechanicalConfidenceScore = function (mechanicalConfidenceScore) {
this._mechanicalConfidenceScore = mechanicalConfidenceScore;
};
Reaction.prototype.getLowerBound = function() {
Reaction.prototype.getLowerBound = function () {
return this._lowerBound;
};
Reaction.prototype.setLowerBound = function(lowerBound) {
Reaction.prototype.setLowerBound = function (lowerBound) {
this._lowerBound = lowerBound;
};
Reaction.prototype.getUpperBound = function() {
Reaction.prototype.getUpperBound = function () {
return this._upperBound;
};
Reaction.prototype.setUpperBound = function(upperBound) {
Reaction.prototype.setUpperBound = function (upperBound) {
this._upperBound = upperBound;
};
Reaction.prototype.setGeneProteinReaction = function(geneProteinReaction) {
Reaction.prototype.setGeneProteinReaction = function (geneProteinReaction) {
this._geneProteinReaction = geneProteinReaction;
};
Reaction.prototype.getGeneProteinReaction = function() {
Reaction.prototype.getGeneProteinReaction = function () {
return this._geneProteinReaction;
};
Reaction.prototype.setSubsystem = function(subsystem) {
Reaction.prototype.setSubsystem = function (subsystem) {
this._subsystem = subsystem;
};
Reaction.prototype.getSubsystem = function() {
Reaction.prototype.getSubsystem = function () {
return this._subsystem;
};
Reaction.prototype.getReactants = function() {
Reaction.prototype.getReactants = function () {
return this._reactants;
};
Reaction.prototype.setReactants = function(reactants) {
Reaction.prototype.setReactants = function (reactants) {
this._reactants = reactants;
};
Reaction.prototype.setProducts = function(products) {
Reaction.prototype.setProducts = function (products) {
this._products = products;
};
Reaction.prototype.getProducts = function() {
Reaction.prototype.getProducts = function () {
return this._products;
};
Reaction.prototype.getElements = function() {
Reaction.prototype.getElements = function () {
var result = [];
result = result.concat(this.getReactants());
result = result.concat(this.getProducts());
......@@ -209,11 +211,11 @@ Reaction.prototype.getElements = function() {
return result;
};
Reaction.prototype.setModifiers = function(modifiers) {
Reaction.prototype.setModifiers = function (modifiers) {
this._modifiers = modifiers;
};
Reaction.prototype.getModifiers = function() {
Reaction.prototype.getModifiers = function () {
return this._modifiers;
};
......
......@@ -298,5 +298,34 @@ MarkerSurfaceCollection.prototype.removeUnmodifiedMarkersAndSurfaces = function
}
};
MarkerSurfaceCollection.prototype.renderOverlay = function (allElements, overlay) {
var self = this;
var elements = [];
for (var i = 0; i < allElements.length; i++) {
if (allElements[i].getModelId() === self.getMap().getId()) {
elements.push(allElements[i]);
}
}
var markers = [];
//first get full data about all elements in one go (not one-by-one queries)
return self.getMap().getModel().getByIdentifiedElements(elements).then(function () {
return Promise.each(elements, function (element) {
var icon = element.getIcon();
if (icon !== null && icon !== undefined) {
return self.createMarkerForDbOverlay(element, overlay).then(function (marker) {
markers.push(marker);
});
} else {
return self.createSurfaceForDbOverlay(element, overlay).then(function (mapOverlay) {
markers.push(mapOverlay);
});
}
});
}).then(function () {
self.removeUnmodifiedMarkersAndSurfaces(markers, overlay);
return markers;
});
};
module.exports = MarkerSurfaceCollection;
......@@ -239,13 +239,13 @@ Helper.prototype.createIdentifiedElement = function (element) {
return new IdentifiedElement({
type: "ALIAS",
id: this.idCounter++,
modelId: this.idCounter++,
modelId: this.idCounter++
});
}
return new IdentifiedElement(element);
};
Helper.prototype.createReaction = function (map) {
Helper.prototype.createReaction = function (map, complete) {
var mapId = null;
if (map !== undefined) {
mapId = map.getId();
......@@ -277,8 +277,14 @@ Helper.prototype.createReaction = function (map) {
}],
centerPoint: new google.maps.Point(0, 0),
modelId: mapId,
references: [],
references: []
});
if (complete) {
result.setIsComplete(true);
result.setReactants([this.createAlias(map)]);
result.setProducts([this.createAlias(map)]);
result.setModifiers([]);
}
return result;
};
......
......@@ -274,7 +274,7 @@ describe('CustomMap', function () {
it("alias re-rendering with different icon", function () {
var map = helper.createCustomMap();
var reaction = helper.createReaction(map);
var reaction = helper.createReaction(map, true);
var alias = helper.createAlias(map);
map.getModel().addAlias(alias);
map.getModel().addReaction(reaction);
......@@ -366,7 +366,7 @@ describe('CustomMap', function () {
it("for reaction", function () {
var map = helper.createCustomMap();
var reaction = helper.createReaction(map);
var reaction = helper.createReaction(map, true);
map.getModel().addReaction(reaction);
var oc = helper.createDbOverlay(map);
......
......@@ -151,8 +151,7 @@ describe('MinervaPluginProxy', function () {
});
});
it('no listeners', function () {
var callbackOk = false;
var map, options;
var map;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment