diff --git a/frontend-js/src/main/js/map/AbstractCustomMap.js b/frontend-js/src/main/js/map/AbstractCustomMap.js index d0a9fa31c2b48810a211bcd1b4ac7c55292c66fc..125289b6b14deb88e90fcb427d8fd697ce25dc40 100644 --- a/frontend-js/src/main/js/map/AbstractCustomMap.js +++ b/frontend-js/src/main/js/map/AbstractCustomMap.js @@ -9,6 +9,7 @@ var AliasInfoWindow = require('./window/AliasInfoWindow'); var AliasMarker = require('./marker/AliasMarker'); var AliasSurface = require('./surface/AliasSurface'); var ObjectWithListeners = require('../ObjectWithListeners'); +var PointData = require('./data/PointData'); var PointInfoWindow = require('./window/PointInfoWindow'); var PointMarker = require('./marker/PointMarker'); var ReactionInfoWindow = require('./window/ReactionInfoWindow'); @@ -716,63 +717,63 @@ AbstractCustomMap.prototype._refreshInfoWindows = function() { * @param marker * marker for which we are opening window */ -AbstractCustomMap.prototype._openInfoWindowForMarker = function(marker) { - var markerId = marker.getId(); +AbstractCustomMap.prototype._openInfoWindowForIdentifiedElement = function(element, googleMarker) { var self = this; - if (marker instanceof AliasMarker) { - var aliasInfoWindow = this.getAliasInfoWindowById(markerId); - if (aliasInfoWindow !== null && aliasInfoWindow !== undefined) { - if (!aliasInfoWindow.isOpened()) { - aliasInfoWindow.open(); - } else { - logger.warn("Info window for alias: " + markerId + " is already opened"); - } - return Promise.resolve(); - } else { - this._aliasInfoWindow[markerId] = new AliasInfoWindow({ - alias : marker.getAliasData(), - map : self, - marker : marker.getGoogleMarker(), - }); - return this._aliasInfoWindow[markerId].init(); - } - } else if (marker instanceof PointMarker) { - var infoWindow = this.getPointInfoWindowById(markerId); - if (infoWindow !== null && infoWindow !== undefined) { - if (!infoWindow.isOpened()) { - infoWindow.open(); - } else { - logger.warn("Info window for point: " + markerId + " is already opened"); - } - return Promise.resolve(); + if (element.getType() === "ALIAS") { + return self.getModel().getByIdentifiedElement(element).then(function(alias) { + return self._openInfoWindowForAlias(alias, googleMarker); + }); + } else if (element.getType() === "POINT") { + return self._openInfoWindowForPoint(new PointData(element), googleMarker); + } else if (element.getType() === "REACTION") { + return self.getModel().getByIdentifiedElement(element).then(function(reaction) { + return self._openInfoWindowForReaction(reaction, googleMarker); + }); + } else { + throw new Error("Unknown element type: " + element.getType()); + } +}; + +AbstractCustomMap.prototype._openInfoWindowForReaction= function(reaction, googleMarker) { + var self = this; + + var reactionInfoWindow = this.getReactionInfoWindowById(reaction.getId()); + if (reactionInfoWindow !== null && reactionInfoWindow !== undefined) { + if (!reactionInfoWindow.isOpened()) { + reactionInfoWindow.open(); } else { - this._pointInfoWindow[markerId] = new PointInfoWindow({ - point : marker.getPointData(), - map : self, - marker : marker.getGoogleMarker(), - }); - return Promise.resolve(); + logger.warn("Info window for reaction: " + reaction.getId() + " is already opened"); } - } else if (marker instanceof ReactionMarker) { - var reactionInfoWindow = this.getReactionInfoWindowById(markerId); - if (reactionInfoWindow !== null && reactionInfoWindow !== undefined) { - if (!reactionInfoWindow.isOpened()) { - reactionInfoWindow.open(); - } else { - logger.warn("Info window for reaction: " + markerId + " is already opened"); - } - return Promise.resolve(); + return Promise.resolve(); + } else { + this._reactionInfoWindow[reaction.getId()] = new ReactionInfoWindow({ + reaction : reaction, + map : self, + marker : googleMarker, + }); + return this._reactionInfoWindow[reaction.getId()].init(); + } +}; + +AbstractCustomMap.prototype._openInfoWindowForPoint = function(pointData, googleMarker) { + var self = this; + + var infoWindow = this.getPointInfoWindowById(pointData.getId()); + if (infoWindow !== null && infoWindow !== undefined) { + if (!infoWindow.isOpened()) { + infoWindow.open(); } else { - this._reactionInfoWindow[markerId] = new ReactionInfoWindow({ - reaction : marker.getReactionData(), - map : self, - marker : marker.getGoogleMarker(), - }); - return this._reactionInfoWindow[markerId].init(); + logger.warn("Info window for point: " + element.getId() + " is already opened"); } } else { - throw new Error("Unknown marker type: ", marker); + infoWindow = new PointInfoWindow({ + point : pointData, + map : self, + marker : googleMarker, + }); + this._pointInfoWindow[pointData.getId()] = infoWindow; } + return Promise.resolve(infoWindow); }; /** @@ -809,7 +810,7 @@ AbstractCustomMap.prototype.getId = function() { * @param reactionId * reaction identifier */ -AbstractCustomMap.prototype._openInfoWindowForReaction = function(reaction, marker) { +AbstractCustomMap.prototype._openInfoWindowForReaction = function(reaction, googleMarker) { var infoWindow = this.getReactionInfoWindowById(reaction.getId()); var self = this; if (infoWindow !== null && infoWindow !== undefined) { @@ -824,11 +825,11 @@ AbstractCustomMap.prototype._openInfoWindowForReaction = function(reaction, mark infoWindow = new ReactionInfoWindow({ reaction : reaction, map : self, - marker:marker, + marker : googleMarker, }); self._reactionInfoWindow[reaction.getId()] = infoWindow; return infoWindow.init(); - }).then(function(){ + }).then(function() { return infoWindow; }); } diff --git a/frontend-js/src/main/js/map/CustomMap.js b/frontend-js/src/main/js/map/CustomMap.js index cb33a48871b2cfa8554e64915faaff41c5ce3c8f..b49d055cd5d4ed65a95c0dee948d9bd94273b1e6 100644 --- a/frontend-js/src/main/js/map/CustomMap.js +++ b/frontend-js/src/main/js/map/CustomMap.js @@ -683,10 +683,10 @@ CustomMap.prototype.refreshInfoWindows = function() { * @param modelId * identifier of {@link AbstractCustomMap} */ -CustomMap.prototype.openInfoWindowForAlias = function(alias) { +CustomMap.prototype.openInfoWindowForAlias = function(alias, marker) { logger.debug("Opening info window for alias: " + alias.getId() + ", model: " + alias.getModelId()); var submap = this.getSubmapById(alias.getModelId()); - return submap._openInfoWindowForAlias(alias); + return submap._openInfoWindowForAlias(alias, marker); }; /** @@ -807,17 +807,18 @@ CustomMap.prototype.openInfoWindowForMarker = function(marker) { var elementType = marker.getType(); // open AliasInfoWindow in a right model - return model._openInfoWindowForMarker(marker).then(function() { - var infoWindow = model.returnInfoWindowForMarker(marker); - - var element = new IdentifiedElement({ - objectId : markerId, - modelId : modelId, - type : elementType - }); + return model._openInfoWindowForIdentifiedElement(marker.getIdentifiedElement(), marker.getGoogleMarker()).then( + function() { + var infoWindow = model.returnInfoWindowForMarker(marker); + + var element = new IdentifiedElement({ + objectId : markerId, + modelId : modelId, + type : elementType + }); - return self.retrieveOverlayDetailDataForElement(element, infoWindow.getOverlayFullViewArray()); - }); + return self.retrieveOverlayDetailDataForElement(element, infoWindow.getOverlayFullViewArray()); + }); }; diff --git a/frontend-js/src/main/js/map/data/PointData.js b/frontend-js/src/main/js/map/data/PointData.js index 1331a89579cd6b4ace466d8a80edfcdb1a85be94..9c95d6e6237351799250e1b775f0b21653bfb505 100644 --- a/frontend-js/src/main/js/map/data/PointData.js +++ b/frontend-js/src/main/js/map/data/PointData.js @@ -6,6 +6,8 @@ function PointData(javaObject, modelId) { if (javaObject instanceof google.maps.Point) { this._point = javaObject; + } else if (javaObject.constructor.name === "IdentifiedElement") { + this._point = javaObject.getPoint(); } else { var tmp = javaObject.idObject; tmp = javaObject.idObject.replace("Point2D.Double", ""); @@ -14,7 +16,7 @@ function PointData(javaObject, modelId) { var y = parseFloat(tmp[1]).toFixed(2); this._point = new google.maps.Point(x, y); } - this._id = "(" + this._point.x + "," + this._point.y + ")"; + this._id = "(" + parseFloat(this._point.x).toFixed(2) + "," + parseFloat(this._point.y).toFixed(2) + ")"; this._modelId = modelId; } diff --git a/frontend-js/src/main/js/map/marker/AbstractMarker.js b/frontend-js/src/main/js/map/marker/AbstractMarker.js index 9abae7876bb4f480aea97ea20ee741a1e8f8e87f..eb180f5851e7c5052b1c1aa6fe5e24541dfbaeb5 100644 --- a/frontend-js/src/main/js/map/marker/AbstractMarker.js +++ b/frontend-js/src/main/js/map/marker/AbstractMarker.js @@ -127,12 +127,9 @@ AbstractMarker.prototype._init = function() { id : self.getId() }); - var onclick = (function() { - var aliasMarker = self; - return function() { - return aliasMarker.getCustomMap().getTopMap().openInfoWindowForMarker(aliasMarker); - }; - })(); + var onclick = function() { + return self.getCustomMap().getTopMap().openInfoWindowForMarker(self); + }; google.maps.event.addListener(this.getGoogleMarker(), 'click', onclick); return Promise.resolve(); }; diff --git a/frontend-js/src/test/js/map/AbstractCustomMap-test.js b/frontend-js/src/test/js/map/AbstractCustomMap-test.js index a912d0d45e2e23b921ccaac7c1bd802cf54d7602..6a828aa632ad97319f749b1b0663f28d9d0e20f0 100644 --- a/frontend-js/src/test/js/map/AbstractCustomMap-test.js +++ b/frontend-js/src/test/js/map/AbstractCustomMap-test.js @@ -289,7 +289,7 @@ describe('AbstractCustomMap', function() { }); - describe("_openInfoWindowForMarker", function() { + describe("_openInfoWindowForIdentifiedElement", function() { it("for AliasMarker", function() { var map; var alias, marker; @@ -307,7 +307,7 @@ describe('AbstractCustomMap', function() { return marker.init(); }).then(function() { assert.equal(null, map.getAliasInfoWindowById(alias.getId())); - return map._openInfoWindowForMarker(marker).then(function() { + return map._openInfoWindowForIdentifiedElement(marker).then(function() { assert.ok(map.getAliasInfoWindowById(alias.getId())); }); }); @@ -324,7 +324,7 @@ describe('AbstractCustomMap', function() { marker = new ReactionMarker(reaction.getId(), "empty.png", reaction, map); assert.equal(null, map.getReactionInfoWindowById(reaction.getId())); - return map._openInfoWindowForMarker(marker).then(function() { + return map._openInfoWindowForIdentifiedElement(marker).then(function() { assert.ok(map.getReactionInfoWindowById(reaction.getId())); }); }); @@ -347,9 +347,9 @@ describe('AbstractCustomMap', function() { var pointMarker = new PointMarker(pointData, "empty.png", mockObject); assert.equal(null, mockObject.getPointInfoWindowById(pointData.getId())); - mockObject._openInfoWindowForMarker(pointMarker); - assert.ok(mockObject.getPointInfoWindowById(pointData.getId())); - + return mockObject._openInfoWindowForIdentifiedElement(pointMarker.getIdentifiedElement()).then(function(){ + assert.ok(mockObject.getPointInfoWindowById(pointData.getId())); + }); }); });