diff --git a/frontend-js/src/main/js/map/AbstractCustomMap.js b/frontend-js/src/main/js/map/AbstractCustomMap.js index 10cc77ed9362755a3ff84256833118259b58f1df..6d10e69789c5f0031be91544541883e657ebb8c4 100644 --- a/frontend-js/src/main/js/map/AbstractCustomMap.js +++ b/frontend-js/src/main/js/map/AbstractCustomMap.js @@ -79,9 +79,9 @@ AbstractCustomMap.prototype.constructor = AbstractCustomMap; /** * Assigns layouts with images to the google map (which set of images should be * used by google maps api for which layout). - * + * */ -AbstractCustomMap.prototype.setupLayouts = function() { +AbstractCustomMap.prototype.setupLayouts = function () { for (var i = 0; i < this.getLayouts().length; i++) { var layout = this.getLayouts()[i]; var typeOptions = this.createTypeOptions(layout); @@ -93,9 +93,9 @@ AbstractCustomMap.prototype.setupLayouts = function() { /** * Creates general google maps options used in this map. - * + * */ -AbstractCustomMap.prototype.creatMapOptions = function() { +AbstractCustomMap.prototype.creatMapOptions = function () { var self = this; var centerPoint = this.getModel().getCenterLatLng(); @@ -107,19 +107,19 @@ AbstractCustomMap.prototype.creatMapOptions = function() { } var result = { - center : centerPoint, - rotateControl : true, - panControl : true, - mapTypeControl : false, - zoom : this.getMinZoom(), - streetViewControl : false, - - panControlOptions : { - position : google.maps.ControlPosition.LEFT_TOP + center: centerPoint, + rotateControl: true, + panControl: true, + mapTypeControl: false, + zoom: this.getMinZoom(), + streetViewControl: false, + + panControlOptions: { + position: google.maps.ControlPosition.LEFT_TOP }, - zoomControlOptions : { - style : google.maps.ZoomControlStyle.LARGE, - position : google.maps.ControlPosition.LEFT_TOP + zoomControlOptions: { + style: google.maps.ZoomControlStyle.LARGE, + position: google.maps.ControlPosition.LEFT_TOP } }; @@ -128,16 +128,16 @@ AbstractCustomMap.prototype.creatMapOptions = function() { /** * Create google maps configuration options object for a specific layout. - * + * * @param param * object with information about layout */ -AbstractCustomMap.prototype.createTypeOptions = function(param) { +AbstractCustomMap.prototype.createTypeOptions = function (param) { var self = this; var result = { // this is a function that will retrieve valid url to png images for // tiles on different zoom levels - getTileUrl : function(coord, zoom) { + getTileUrl: function (coord, zoom) { // we have 1 tile on self.getConfiguration().MIN_ZOOM and // therefore must limit tails according to this /* jshint bitwise: false */ @@ -148,28 +148,28 @@ AbstractCustomMap.prototype.createTypeOptions = function(param) { var addr = "../map_images/" + param.getDirectory() + "/" + zoom + "/" + coord.x + "/" + coord.y + ".PNG"; return addr; }, - tileSize : new google.maps.Size(this.getTileSize(), this.getTileSize()), - maxZoom : this.getMaxZoom(), - minZoom : this.getMinZoom(), - radius : 360, - name : param.name + tileSize: new google.maps.Size(this.getTileSize(), this.getTileSize()), + maxZoom: this.getMaxZoom(), + minZoom: this.getMinZoom(), + radius: 360, + name: param.name }; return result; }; /** * Sets maximum zoom level on google map. - * + * */ -AbstractCustomMap.prototype.setMaxZoomLevel = function() { +AbstractCustomMap.prototype.setMaxZoomLevel = function () { this.getGoogleMap().setZoom(this.getMaxZoom()); }; /** * Returns mouse coordinate on the map in lat,lng system. - * + * */ -AbstractCustomMap.prototype.getMouseLatLng = function() { +AbstractCustomMap.prototype.getMouseLatLng = function () { // this method is tricky, the main problem is how to map mouse coordinate to // google map // to do that we need a point of reference in both systems (x,y and lat,lng) @@ -190,19 +190,19 @@ AbstractCustomMap.prototype.getMouseLatLng = function() { } var offset = { - x : lx, - y : ly + x: lx, + y: ly }; var center = { - x : self.getGoogleMap().getDiv().offsetWidth / 2, - y : self.getGoogleMap().getDiv().offsetHeight / 2 + x: self.getGoogleMap().getDiv().offsetWidth / 2, + y: self.getGoogleMap().getDiv().offsetHeight / 2 }; // and now find how far from center point we are (in pixels) var relativeDist = { - x : (GuiConnector.xPos - offset.x - center.x), - y : (GuiConnector.yPos - offset.y - center.y) + x: (GuiConnector.xPos - offset.x - center.x), + y: (GuiConnector.yPos - offset.y - center.y) }; // transform pixels into x,y distance @@ -220,14 +220,14 @@ AbstractCustomMap.prototype.getMouseLatLng = function() { /** * Transform distance (coordinates) in pixels into x,y distance on the map. - * + * * @param pixels * x,y distance in pixels * @param zoomLevel * at which zoom level this pixels where mesaured - * + * */ -AbstractCustomMap.prototype.fromPixelsToPoint = function(pixels, zoomLevel) { +AbstractCustomMap.prototype.fromPixelsToPoint = function (pixels, zoomLevel) { var zoomScale = this.getPictureSize() / (Math.pow(2, zoomLevel - this.getMinZoom()) * this.getTileSize()); var pointx = pixels.x * zoomScale; var pointy = pixels.y * zoomScale; @@ -237,13 +237,13 @@ AbstractCustomMap.prototype.fromPixelsToPoint = function(pixels, zoomLevel) { /** * Transforms coordinates on the map from google.maps.LatLng to * google.maps.Point - * + * * @param latlng * cooordinates in x,y format * @param coordinates * in lat,lng format */ -AbstractCustomMap.prototype.fromLatLngToPoint = function(latLng) { +AbstractCustomMap.prototype.fromLatLngToPoint = function (latLng) { var me = this; var point = new google.maps.Point(0, 0); var origin = me.pixelOrigin_; @@ -265,12 +265,12 @@ AbstractCustomMap.prototype.fromLatLngToPoint = function(latLng) { /** * Transforms coordinates on the map from google.maps.Point to * google.maps.LatLng - * + * * @param point * coordinates in standard x,y format * @return cooordinates in lat,lng format */ -AbstractCustomMap.prototype.fromPointToLatLng = function(point) { +AbstractCustomMap.prototype.fromPointToLatLng = function (point) { var me = this; // rescale the point (all computations are done assuming that we work on @@ -286,26 +286,26 @@ AbstractCustomMap.prototype.fromPointToLatLng = function(point) { /** * Transforms google.maps.LatLng to tile coordinate (for instance on which tile * mouse clicked). - * - * + * + * * @param latlng * coordinates in latlng format * @param z * zoom level at which we want to find coordinates of tile * @return cooordinates of a tile */ -AbstractCustomMap.prototype.latLngToTile = function(latLng, z) { +AbstractCustomMap.prototype.latLngToTile = function (latLng, z) { var worldCoordinate = this.fromLatLngToPoint(latLng); var pixelCoordinate = new google.maps.Point(worldCoordinate.x * Math.pow(2, z), worldCoordinate.y * Math.pow(2, z)); var tileCoordinate = new google.maps.Point(Math.floor(pixelCoordinate.x / this.getTileSize()), Math - .floor(pixelCoordinate.y / this.getTileSize())); + .floor(pixelCoordinate.y / this.getTileSize())); return tileCoordinate; }; /** * Register events responsible for click events */ -AbstractCustomMap.prototype.registerMapClickEvents = function() { +AbstractCustomMap.prototype.registerMapClickEvents = function () { // find top map (CustomMap) // @@ -314,30 +314,30 @@ AbstractCustomMap.prototype.registerMapClickEvents = function() { var self = this; // search event - google.maps.event.addListener(this.getGoogleMap(), 'click', function(mouseEvent) { + google.maps.event.addListener(this.getGoogleMap(), 'click', function (mouseEvent) { var point = self.fromLatLngToPoint(mouseEvent.latLng); var searchDb = customMap.getOverlayByName('search'); return searchDb.searchByCoordinates({ - modelId : self.getModel().getId(), - coordinates : point, - zoom : self.getGoogleMap().getZoom() + modelId: self.getModel().getId(), + coordinates: point, + zoom: self.getGoogleMap().getZoom() }).then(null, GuiConnector.alert); }); // select last clicked map - google.maps.event.addListener(this.getGoogleMap(), 'click', function(mouseEvent) { + google.maps.event.addListener(this.getGoogleMap(), 'click', function (mouseEvent) { customMap.setActiveSubmapId(self.getId()); customMap.setActiveSubmapClickCoordinates(self.fromLatLngToPoint(mouseEvent.latLng)); }); // select last clicked map - google.maps.event.addListener(this.getGoogleMap(), 'rightclick', function(mouseEvent) { + google.maps.event.addListener(this.getGoogleMap(), 'rightclick', function (mouseEvent) { customMap.setActiveSubmapId(self.getId()); customMap.setActiveSubmapClickCoordinates(self.fromLatLngToPoint(mouseEvent.latLng)); }); // prepare for image export - google.maps.event.addListener(this.getGoogleMap(), 'rightclick', function() { + google.maps.event.addListener(this.getGoogleMap(), 'rightclick', function () { var bounds = self.getGoogleMap().getBounds(); var polygon = ""; @@ -364,7 +364,7 @@ AbstractCustomMap.prototype.registerMapClickEvents = function() { }); // context menu event - google.maps.event.addListener(this.getGoogleMap(), 'rightclick', function() { + google.maps.event.addListener(this.getGoogleMap(), 'rightclick', function () { self.getTopMap().getContextMenu().open(GuiConnector.xPos, GuiConnector.yPos); }); }; @@ -372,9 +372,9 @@ AbstractCustomMap.prototype.registerMapClickEvents = function() { /** * It toggle drawing manager used on the map: if it's on then it will turn it * off, if it's off it will turn it on - * + * */ -AbstractCustomMap.prototype._turnOnOffDrawing = function() { +AbstractCustomMap.prototype._turnOnOffDrawing = function () { if (this.isDrawingOn()) { this.turnOffDrawing(); } else { @@ -384,16 +384,16 @@ AbstractCustomMap.prototype._turnOnOffDrawing = function() { /** * Checks if the drawing manager for the map is on. - * + * */ -AbstractCustomMap.prototype.isDrawingOn = function() { +AbstractCustomMap.prototype.isDrawingOn = function () { return this._drawingManager !== null; }; /** * Turns on drawing manager on the map. */ -AbstractCustomMap.prototype.turnOnDrawing = function() { +AbstractCustomMap.prototype.turnOnDrawing = function () { if (this.isDrawingOn()) { logger.warn("Trying to turn on drawing manager, but it is already available."); return; @@ -401,28 +401,28 @@ AbstractCustomMap.prototype.turnOnDrawing = function() { var customMap = this.getTopMap(); var self = this; this._drawingManager = new google.maps.drawing.DrawingManager({ - drawingMode : google.maps.drawing.OverlayType.MARKER, - drawingControl : true, - drawingControlOptions : { - position : google.maps.ControlPosition.TOP_CENTER, - drawingModes : [ google.maps.drawing.OverlayType.POLYGON, ] + drawingMode: google.maps.drawing.OverlayType.MARKER, + drawingControl: true, + drawingControlOptions: { + position: google.maps.ControlPosition.TOP_CENTER, + drawingModes: [google.maps.drawing.OverlayType.POLYGON,] }, - markerOptions : { - icon : 'images/beachflag.png' + markerOptions: { + icon: 'images/beachflag.png' }, - circleOptions : { - fillColor : '#ffff00', - fillOpacity : 1, - strokeWeight : 5, - clickable : false, - editable : true, - zIndex : 1 + circleOptions: { + fillColor: '#ffff00', + fillOpacity: 1, + strokeWeight: 5, + clickable: false, + editable: true, + zIndex: 1 } }); this._drawingManager.setMap(this.getGoogleMap()); this._drawingManager.setDrawingMode(google.maps.drawing.OverlayType.POLYGON); - google.maps.event.addListener(this._drawingManager, 'overlaycomplete', function(e) { + google.maps.event.addListener(this._drawingManager, 'overlaycomplete', function (e) { if (e.type !== google.maps.drawing.OverlayType.MARKER) { // Switch back to non-drawing mode after drawing a shape. self._drawingManager.setDrawingMode(null); @@ -431,7 +431,7 @@ AbstractCustomMap.prototype.turnOnDrawing = function() { // user mouses down on it. var newShape = e.overlay; newShape.type = e.type; - google.maps.event.addListener(newShape, 'rightclick', function(e) { + google.maps.event.addListener(newShape, 'rightclick', function (e) { // select map that was clicked customMap.setActiveSubmapId(self.getId()); @@ -449,25 +449,25 @@ AbstractCustomMap.prototype.turnOnDrawing = function() { /** * Sets selectedArea on this map. - * + * */ -AbstractCustomMap.prototype.setSelectedArea = function(area) { +AbstractCustomMap.prototype.setSelectedArea = function (area) { this._selectedArea = area; }; /** * Returns selectedArea on this map. - * + * */ -AbstractCustomMap.prototype.getSelectedArea = function() { +AbstractCustomMap.prototype.getSelectedArea = function () { return this._selectedArea; }; /** * Transforms google.maps.Polygon into string with coordinates. - * + * */ -AbstractCustomMap.prototype.areaToString = function(area) { +AbstractCustomMap.prototype.areaToString = function (area) { var len = area.getPath().length; var path = area.getPath(); var res = ""; @@ -481,7 +481,7 @@ AbstractCustomMap.prototype.areaToString = function(area) { /** * Removes selected area (polygon) from the map. */ -AbstractCustomMap.prototype._removeSelection = function() { +AbstractCustomMap.prototype._removeSelection = function () { if (this._selectedArea) { this._selectedArea.setMap(null); this._selectedArea = null; @@ -493,7 +493,7 @@ AbstractCustomMap.prototype._removeSelection = function() { /** * Turns off drawing manager on the map. */ -AbstractCustomMap.prototype.turnOffDrawing = function() { +AbstractCustomMap.prototype.turnOffDrawing = function () { if (this.isDrawingOn()) { this._drawingManager.setMap(null); this._drawingManager = null; @@ -506,10 +506,10 @@ AbstractCustomMap.prototype.turnOffDrawing = function() { * Returns top map. TODO implementation of this function should be probably * moved to Submap and CustomMap classes and here only abstract function * definition - * + * * @returns {CustomMap} */ -AbstractCustomMap.prototype.getTopMap = function() { +AbstractCustomMap.prototype.getTopMap = function () { logger.fatal("Not implemented"); }; @@ -519,7 +519,7 @@ AbstractCustomMap.prototype.getTopMap = function() { * visualized at the same time then index contains information where this new * layout is placed in the list (starting from 0) and length contains * information how many layouts we visualize in total. - * + * * @param layoutId * identifier of a layout * @param index @@ -529,9 +529,9 @@ AbstractCustomMap.prototype.getTopMap = function() { * @param length * number of layouts that are currently visualized */ -AbstractCustomMap.prototype._resizeSelectedLayout = function(layoutId, index, length) { +AbstractCustomMap.prototype._resizeSelectedLayout = function (layoutId, index, length) { var self = this; - return new Promise(function(resolve) { + return new Promise(function (resolve) { // if map is not initialized then don't perform this operation if (!self.initialized) { logger.debug("Model " + self.getId() + " not initialized"); @@ -555,7 +555,7 @@ AbstractCustomMap.prototype._resizeSelectedLayout = function(layoutId, index, le * the same time then index contains information where this new layout is placed * in the list (starting from 0) and length contains information how many * layouts we visualize in total. - * + * * @param layoutId * identifier of a layout * @param index @@ -565,10 +565,10 @@ AbstractCustomMap.prototype._resizeSelectedLayout = function(layoutId, index, le * @param length * number of layouts that are currently visualized */ -AbstractCustomMap.prototype._showSelectedLayout = function(layoutId, index, length) { +AbstractCustomMap.prototype._showSelectedLayout = function (layoutId, index, length) { var self = this; // if map is not initialized then don't perform this operation - return new Promise(function(resolve, reject) { + return new Promise(function (resolve, reject) { if (!self.initialized) { logger.debug("Model " + self.getId() + " not initialized"); resolve(); @@ -587,49 +587,64 @@ AbstractCustomMap.prototype._showSelectedLayout = function(layoutId, index, leng var layoutAliases; var layoutReactions; - return self.getTopMap().getModel().getLayoutDataById(layoutId).then(function(layout) { + return self.getTopMap().getModel().getLayoutDataById(layoutId).then(function (layout) { layoutAliases = layout.getAliases(); layoutReactions = layout.getReactions(); - return Promise.each(layoutAliases, function(layoutAlias) { + var identifiedElements = []; + var i; + for (i = 0; i < layoutAliases.length; i++) { + if (layoutAliases[i].getModelId() === self.getId()) { + identifiedElements.push(new IdentifiedElement(layoutAliases[i])); + } + } + var reactionIds = []; + for (i = 0; i < layoutReactions.length; i++) { + if (layoutReactions[i].getModelId() === self.getId()) { + identifiedElements.push(new IdentifiedElement(layoutReactions[i])); + } + } + return self.getModel().getByIdentifiedElements(identifiedElements, false); + }).then(function () { + return Promise.each(layoutAliases, function (layoutAlias) { if (layoutAlias.getModelId() === self.getId()) { var surface; var element; - return self.getModel().getAliasById(layoutAlias.getId()).then(function(aliasData) { + return self.getModel().getAliasById(layoutAlias.getId()).then(function (aliasData) { element = new IdentifiedElement(aliasData); return AliasSurface.create({ - overlayAlias : layoutAlias, - alias : aliasData, - map : self, - startX : startX, - endX : endX, - onClick : [ function() { + overlayAlias: layoutAlias, + alias: aliasData, + map: self, + startX: startX, + endX: endX, + onClick: [function () { return self._openInfoWindowForAlias(aliasData, surface.getGoogleMarker()); - }, function() { + }, function () { return self.getTopMap().callListeners("onBioEntityClick", element); - } ] + }] }); - }).then(function(result) { + }).then(function (result) { surface = result; self.selectedLayoutOverlays[layoutId].push(surface); }); } }); - }).then(function() { - return Promise.each(layoutReactions, function(layoutReaction) { + }).then(function () { + return Promise.each(layoutReactions, function (layoutReaction) { if (layoutReaction.getModelId() === self.getId()) { - return self.getModel().getReactionById(layoutReaction.getId()).then(function(reactionData) { + return self.getModel().getReactionById(layoutReaction.getId()).then(function (reactionData) { var element = new IdentifiedElement(reactionData); var surface = new ReactionSurface({ - layoutReaction : layoutReaction, - reaction : reactionData, - map : self, - onClick : [ function() { + layoutReaction: layoutReaction, + reaction: reactionData, + map: self, + onClick: [function () { return self._openInfoWindowForReaction(reactionData, surface.getGoogleMarker()); - }, function() { + }, function () { return self.getTopMap().callListeners("onBioEntityClick", element); - } ], - customized : (length === 1) + }], + customized: (length === 1) }); self.selectedLayoutOverlays[layoutId].push(surface); @@ -637,7 +652,7 @@ AbstractCustomMap.prototype._showSelectedLayout = function(layoutId, index, leng }); } }); - }).then(function() { + }).then(function () { resolve(); }).then(null, reject); }); @@ -645,11 +660,11 @@ AbstractCustomMap.prototype._showSelectedLayout = function(layoutId, index, leng /** * Hides all elements from layout. - * + * * @param layoutId * identifier of a layout */ -AbstractCustomMap.prototype._hideSelectedLayout = function(layoutId) { +AbstractCustomMap.prototype._hideSelectedLayout = function (layoutId) { // if map is not initialized then don't perform this operation if (!this.initialized) { logger.debug("Model " + this.getId() + " not initialized"); @@ -663,11 +678,11 @@ AbstractCustomMap.prototype._hideSelectedLayout = function(layoutId) { /** * Opens {@link AliasInfoWindow} for given alias. - * + * * @param aliasId * identifier of the alias */ -AbstractCustomMap.prototype._openInfoWindowForAlias = function(alias, googleMarker) { +AbstractCustomMap.prototype._openInfoWindowForAlias = function (alias, googleMarker) { var self = this; var infoWindow = this.getAliasInfoWindowById(alias.getId()); @@ -680,9 +695,9 @@ AbstractCustomMap.prototype._openInfoWindowForAlias = function(alias, googleMark return Promise.resolve(infoWindow); } else { self._aliasInfoWindow[alias.getId()] = new AliasInfoWindow({ - alias : alias, - map : self, - marker : googleMarker, + alias: alias, + map: self, + marker: googleMarker, }); return self._aliasInfoWindow[alias.getId()].init(); } @@ -691,15 +706,15 @@ AbstractCustomMap.prototype._openInfoWindowForAlias = function(alias, googleMark /** * Returns promise of a list of {@link LayoutAlias} information for a given * {@link Alias} in all currently visualized layouts. - * + * * @param aliasId * identifier of the {@link Alias} * @returns promise of an {Array} with list of {@link LayoutAlias} information * for a given {@link Alias} in all currently visualized layouts */ -AbstractCustomMap.prototype.getAliasVisibleLayoutsData = function(aliasId) { +AbstractCustomMap.prototype.getAliasVisibleLayoutsData = function (aliasId) { var self = this; - return self.getTopMap().getVisibleDataOverlays().then(function(visibleDataOverlays) { + return self.getTopMap().getVisibleDataOverlays().then(function (visibleDataOverlays) { var result = []; for (var i = 0; i < visibleDataOverlays.length; i++) { var layout = visibleDataOverlays[i]; @@ -712,16 +727,16 @@ AbstractCustomMap.prototype.getAliasVisibleLayoutsData = function(aliasId) { /** * Refresh content of all {@link AliasInfoWindow} in this map. */ -AbstractCustomMap.prototype._refreshInfoWindows = function() { +AbstractCustomMap.prototype._refreshInfoWindows = function () { var promises = []; - for ( var key in this._pointInfoWindow) { + for (var key in this._pointInfoWindow) { if (this._pointInfoWindow.hasOwnProperty(key)) { if (this._pointInfoWindow[key].isOpened()) { promises.push(this._pointInfoWindow[key].update()); } } } - for ( var aliasKey in this._aliasInfoWindow) { + for (var aliasKey in this._aliasInfoWindow) { if (this._aliasInfoWindow.hasOwnProperty(aliasKey)) { if (this._aliasInfoWindow[aliasKey].isOpened()) { promises.push(this._aliasInfoWindow[aliasKey].update()); @@ -734,11 +749,11 @@ AbstractCustomMap.prototype._refreshInfoWindows = function() { /** * Opens {@link ReactionInfoWindow} for given reaction identifier. - * + * * @param reactionId * reaction identifier */ -AbstractCustomMap.prototype._openInfoWindowForReaction = function(reaction, googleMarker) { +AbstractCustomMap.prototype._openInfoWindowForReaction = function (reaction, googleMarker) { var infoWindow = this.getReactionInfoWindowById(reaction.getId()); var self = this; if (infoWindow !== null && infoWindow !== undefined) { @@ -749,21 +764,21 @@ AbstractCustomMap.prototype._openInfoWindowForReaction = function(reaction, goog } return Promise.resolve(infoWindow); } else { - return self.getModel().getReactionById(reaction.getId()).then(function(reaction) { + return self.getModel().getReactionById(reaction.getId()).then(function (reaction) { infoWindow = new ReactionInfoWindow({ - reaction : reaction, - map : self, - marker : googleMarker, + reaction: reaction, + map: self, + marker: googleMarker, }); self._reactionInfoWindow[reaction.getId()] = infoWindow; return infoWindow.init(); - }).then(function() { + }).then(function () { return infoWindow; }); } }; -AbstractCustomMap.prototype._openInfoWindowForPoint = function(pointData, googleMarker) { +AbstractCustomMap.prototype._openInfoWindowForPoint = function (pointData, googleMarker) { var self = this; var infoWindow = this.getPointInfoWindowById(pointData.getId()); @@ -775,9 +790,9 @@ AbstractCustomMap.prototype._openInfoWindowForPoint = function(pointData, google } } else { infoWindow = new PointInfoWindow({ - point : pointData, - map : self, - marker : googleMarker, + point: pointData, + map: self, + marker: googleMarker, }); this._pointInfoWindow[pointData.getId()] = infoWindow; } @@ -786,11 +801,11 @@ AbstractCustomMap.prototype._openInfoWindowForPoint = function(pointData, google /** * Opens {@link AbstractInfoWindow} for a marker. - * + * * @param marker * marker for which we are opening window */ -AbstractCustomMap.prototype.returnInfoWindowForIdentifiedElement = function(element) { +AbstractCustomMap.prototype.returnInfoWindowForIdentifiedElement = function (element) { var markerId = element.getId(); if (element.getType() === "ALIAS") { return this.getAliasInfoWindowById(markerId); @@ -805,30 +820,30 @@ AbstractCustomMap.prototype.returnInfoWindowForIdentifiedElement = function(elem /** * Returns identifier. - * + * * @returns identifier */ -AbstractCustomMap.prototype.getId = function() { +AbstractCustomMap.prototype.getId = function () { return this.getModel().getId(); }; -AbstractCustomMap.prototype.getConfiguration = function() { +AbstractCustomMap.prototype.getConfiguration = function () { return this._configuration; }; -AbstractCustomMap.prototype.setConfiguration = function(configuration) { +AbstractCustomMap.prototype.setConfiguration = function (configuration) { this._configuration = configuration; }; -AbstractCustomMap.prototype._createMapChangedCallbacks = function() { +AbstractCustomMap.prototype._createMapChangedCallbacks = function () { var self = this; var sessionData = ServerConnector.getSessionData(self.getTopMap().getProject()); // listener for changing zoom level - google.maps.event.addListener(this.getGoogleMap(), 'zoom_changed', function() { + google.maps.event.addListener(this.getGoogleMap(), 'zoom_changed', function () { sessionData.setZoomLevel(self.getModel(), self.getGoogleMap().getZoom()); }); // listener for changing location of the map (moving left/reght/top/bottom - google.maps.event.addListener(this.getGoogleMap(), 'center_changed', function() { + google.maps.event.addListener(this.getGoogleMap(), 'center_changed', function () { var coord = self.getGoogleMap().getCenter(); var point = self.fromLatLngToPoint(coord); sessionData.setCenter(self.getModel(), point); @@ -837,62 +852,62 @@ AbstractCustomMap.prototype._createMapChangedCallbacks = function() { /** * Returns {@link ReactionInfoWindow} for given reaction identifier - * + * * @param reactionId * reaction identifier * @returns {@link ReactionInfoWindow} for given reaction identifier */ -AbstractCustomMap.prototype.getReactionInfoWindowById = function(reactionId) { +AbstractCustomMap.prototype.getReactionInfoWindowById = function (reactionId) { return this._reactionInfoWindow[reactionId]; }; /** * Returns {@link AliasInfoWindow} for given alias identifier - * + * * @param aliasId * alias identifier * @returns {@link AliasInfoWindow} for given alias identifier */ -AbstractCustomMap.prototype.getAliasInfoWindowById = function(aliasId) { +AbstractCustomMap.prototype.getAliasInfoWindowById = function (aliasId) { return this._aliasInfoWindow[aliasId]; }; /** * Returns {@link PointInfoWindow} for given point identifier - * + * * @param pointId * point identifier * @returns {@link PointInfoWindow} for given point identifier */ -AbstractCustomMap.prototype.getPointInfoWindowById = function(pointId) { +AbstractCustomMap.prototype.getPointInfoWindowById = function (pointId) { return this._pointInfoWindow[pointId]; }; -AbstractCustomMap.prototype.getModel = function() { +AbstractCustomMap.prototype.getModel = function () { return this._model; }; -AbstractCustomMap.prototype.setModel = function(model) { +AbstractCustomMap.prototype.setModel = function (model) { this._model = model; }; -AbstractCustomMap.prototype.getTileSize = function() { +AbstractCustomMap.prototype.getTileSize = function () { return this.getModel().getTileSize(); }; -AbstractCustomMap.prototype.getMinZoom = function() { +AbstractCustomMap.prototype.getMinZoom = function () { return this.getModel().getMinZoom(); }; -AbstractCustomMap.prototype.getMaxZoom = function() { +AbstractCustomMap.prototype.getMaxZoom = function () { return this.getModel().getMaxZoom(); }; -AbstractCustomMap.prototype.getLayouts = function() { +AbstractCustomMap.prototype.getLayouts = function () { return this.getModel().getLayouts(); }; -AbstractCustomMap.prototype.getPictureSize = function() { +AbstractCustomMap.prototype.getPictureSize = function () { return this.getModel().getPictureSize(); }; @@ -900,45 +915,45 @@ AbstractCustomMap.prototype.getPictureSize = function() { * Returns array containining elements that are presented on a specific layout * (set of google map objects representing lines/areas that are associated with * layout). - * + * * @returns {Array} containining elements that are presented on a specific * layout (set of google map objects representing lines/areas that are * associated with layout). */ -AbstractCustomMap.prototype.getSelectedLayoutOverlays = function() { +AbstractCustomMap.prototype.getSelectedLayoutOverlays = function () { return this.selectedLayoutOverlays; }; /** * Returns google.maps.map object used to representing data. - * + * * @returns google.maps.map object used to representing data */ -AbstractCustomMap.prototype.getGoogleMap = function() { +AbstractCustomMap.prototype.getGoogleMap = function () { return this._map; }; /** * Sets google.maps.map object used to representing data. - * + * */ -AbstractCustomMap.prototype.setGoogleMap = function(gmap) { +AbstractCustomMap.prototype.setGoogleMap = function (gmap) { this._map = gmap; }; -AbstractCustomMap.prototype.isMarkerOptimization = function() { +AbstractCustomMap.prototype.isMarkerOptimization = function () { return this._markerOptimization; }; -AbstractCustomMap.prototype.isBigLogo = function() { +AbstractCustomMap.prototype.isBigLogo = function () { return this._bigLogo; }; -AbstractCustomMap.prototype.isCustomTouchInterface = function() { +AbstractCustomMap.prototype.isCustomTouchInterface = function () { return this._customTouchInterface; }; -AbstractCustomMap.prototype.setDebug = function(debug) { +AbstractCustomMap.prototype.setDebug = function (debug) { if (debug !== undefined) { if (typeof debug !== "boolean") { logger.warn("param must be boolean"); @@ -947,32 +962,32 @@ AbstractCustomMap.prototype.setDebug = function(debug) { } }; -AbstractCustomMap.prototype.isDebug = function() { +AbstractCustomMap.prototype.isDebug = function () { return this._debug === true; }; -AbstractCustomMap.prototype.getTopLeftLatLng = function() { +AbstractCustomMap.prototype.getTopLeftLatLng = function () { return this.getModel().getTopLeftLatLng(); }; -AbstractCustomMap.prototype.getBottomRightLatLng = function() { +AbstractCustomMap.prototype.getBottomRightLatLng = function () { return this.getModel().getBottomRightLatLng(); }; -AbstractCustomMap.prototype.getElement = function() { +AbstractCustomMap.prototype.getElement = function () { return this._element; }; -AbstractCustomMap.prototype.setElement = function(element) { +AbstractCustomMap.prototype.setElement = function (element) { this._element = element; }; /** * Sets center point for google maps. - * + * * @param coordinates * new center point on map */ -AbstractCustomMap.prototype.setCenter = function(coordinates) { +AbstractCustomMap.prototype.setCenter = function (coordinates) { if (coordinates instanceof google.maps.Point) { coordinates = this.fromPointToLatLng(coordinates); } @@ -986,13 +1001,13 @@ AbstractCustomMap.prototype.setCenter = function(coordinates) { /** * Sets zoom level for google maps. - * + * * @param mapIdentifier * id of the model for which we change zoom level * @param zoom * new zoom level on map */ -AbstractCustomMap.prototype.setZoom = function(zoom) { +AbstractCustomMap.prototype.setZoom = function (zoom) { if (this.initialized) { return Promise.resolve(this.getGoogleMap().setZoom(zoom)); } else { @@ -1001,7 +1016,7 @@ AbstractCustomMap.prototype.setZoom = function(zoom) { } }; -AbstractCustomMap.prototype.fitBounds = function(markers) { +AbstractCustomMap.prototype.fitBounds = function (markers) { var self = this; var map = self.getGoogleMap(); if (map !== undefined) { diff --git a/frontend-js/src/main/js/map/data/IdentifiedElement.js b/frontend-js/src/main/js/map/data/IdentifiedElement.js index caa6ef2d22e5905e2006c75bb849dfdc9de85f15..bf6d87ecfbd8e946ea531894ca2e31b2012cb7d8 100644 --- a/frontend-js/src/main/js/map/data/IdentifiedElement.js +++ b/frontend-js/src/main/js/map/data/IdentifiedElement.js @@ -3,6 +3,7 @@ var Alias = require('./Alias'); var LayoutAlias = require('./LayoutAlias'); var Reaction = require('./Reaction'); +var LayoutReaction = require('./LayoutReaction'); var PointData = require('./PointData'); var logger = require('../../logger'); @@ -32,6 +33,10 @@ function IdentifiedElement(javaObject) { this.setId(javaObject.getId()); this.setModelId(javaObject.getModelId()); this.setType("REACTION"); + } else if (javaObject instanceof LayoutReaction) { + this.setId(javaObject.getId()); + this.setModelId(javaObject.getModelId()); + this.setType("REACTION"); } else if (javaObject instanceof PointData) { this.setId(javaObject.getId()); this.setModelId(javaObject.getModelId()); diff --git a/frontend-js/src/main/js/map/data/MapModel.js b/frontend-js/src/main/js/map/data/MapModel.js index 47a3a085e7ee0673369847cef5e36b2f3971d429..da7ef90962065c696b5b547f610579736a1ff55c 100644 --- a/frontend-js/src/main/js/map/data/MapModel.js +++ b/frontend-js/src/main/js/map/data/MapModel.js @@ -277,7 +277,7 @@ MapModel.prototype.getMissingElements = function(elements) { var reactions = layout.getReactions(); for (var k = 0; k < reactions.length; k++) { - var reaction = reactions[j]; + var reaction = reactions[k]; if (this._reactions[reaction.getId()] === undefined && this._missingReactions[reaction.getId()] === undefined) { this._missingReactions[reaction.getId()] = reaction.getId(); reactionIds.push(reaction.getId()); @@ -670,7 +670,7 @@ MapModel.prototype.getByIdentifiedElements = function(identifiedElements, comple return self.getMissingElements({ aliasIds : missingAliases, reactionIds : missingReactions, - complete : true + complete : complete }).then(function() { var promises = []; for (var i = 0; i < identifiedElements.length; i++) { diff --git a/frontend-js/src/test/js/helper.js b/frontend-js/src/test/js/helper.js index caf31be8d1bfd7f3797bc413c4e50db0ab7cd638..97165ac923f42ebeee442c566f97276c0cb7503f 100644 --- a/frontend-js/src/test/js/helper.js +++ b/frontend-js/src/test/js/helper.js @@ -36,78 +36,78 @@ function Helper(configuration) { this.idCounter = 1000000; } -Helper.prototype.setConfiguration = function(configuration) { +Helper.prototype.setConfiguration = function (configuration) { this._configuration = configuration; }; -Helper.prototype.getConfiguration = function() { +Helper.prototype.getConfiguration = function () { return this._configuration; }; -Helper.prototype.createCommentDbOverlay = function(map) { +Helper.prototype.createCommentDbOverlay = function (map) { var result = new CommentDbOverlay({ - map : map, - name : "comment", - allowGeneralSearch : true + map: map, + name: "comment", + allowGeneralSearch: true }); map.registerDbOverlay(result); return result; }; -Helper.prototype.createSearchDbOverlay = function(map) { +Helper.prototype.createSearchDbOverlay = function (map) { var result = new SearchDbOverlay({ - map : map, - name : "search", + map: map, + name: "search", }); map.registerDbOverlay(result); return result; }; -Helper.prototype.createDbOverlay = function(map) { +Helper.prototype.createDbOverlay = function (map) { var result = new AbstractDbOverlay({ - map : map, - name : "search", + map: map, + name: "search", }); - result.clear = function() { + result.clear = function () { logger.debug("Clear mock"); }; map.registerDbOverlay(result); return result; }; -Helper.prototype.createDrugDbOverlay = function(map) { +Helper.prototype.createDrugDbOverlay = function (map) { var result = new DrugDbOverlay({ - map : map, - name : "drug", - allowGeneralSearch : true, - allowSearchById : true, + map: map, + name: "drug", + allowGeneralSearch: true, + allowSearchById: true, }); map.registerDbOverlay(result); return result; }; -Helper.prototype.createChemicalDbOverlay = function(map) { +Helper.prototype.createChemicalDbOverlay = function (map) { var result = new ChemicalDbOverlay({ - map : map, - name : "chemical", - allowGeneralSearch : true, - allowSearchById : true, + map: map, + name: "chemical", + allowGeneralSearch: true, + allowSearchById: true, }); map.registerDbOverlay(result); return result; }; -Helper.prototype.createMiRnaDbOverlay = function(map) { +Helper.prototype.createMiRnaDbOverlay = function (map) { var result = new MiRnaDbOverlay({ - map : map, - name : "mirna", - allowGeneralSearch : true, - allowSearchById : true, + map: map, + name: "mirna", + allowGeneralSearch: true, + allowSearchById: true, }); map.registerDbOverlay(result); return result; }; -Helper.prototype.createComment = function(element) { +Helper.prototype.createComment = function (element) { var elementType = "ALIAS"; var elementId = this.idCounter++; var id = this.idCounter++; @@ -124,25 +124,25 @@ Helper.prototype.createComment = function(element) { } var result = new Comment({ - elementId : elementId, - type : elementType, - modelId : modelId, - icon : "icons/comment.png", - id : id, - pinned : true, - coord : { - x : 321.5, - y : 289.0 + elementId: elementId, + type: elementType, + modelId: modelId, + icon: "icons/comment.png", + id: id, + pinned: true, + coord: { + x: 321.5, + y: 289.0 }, - removed : false, - title : "title fo comment: " + id, - content : "content of the comment # " + id + removed: false, + title: "title fo comment: " + id, + content: "content of the comment # " + id }); return result; }; -Helper.prototype.createProject = function() { +Helper.prototype.createProject = function () { var result = new Project(); result.setProjectId("testId"); result.setId(this.idCounter++); @@ -150,17 +150,17 @@ Helper.prototype.createProject = function() { return result; }; -Helper.prototype.createUser = function() { +Helper.prototype.createUser = function () { var result = new User({ - login : "testlogin", - id : this.idCounter++, - name : "some name", - surname : "surn", + login: "testlogin", + id: this.idCounter++, + name: "some name", + surname: "surn", }); return result; }; -Helper.prototype.createAlias = function(map) { +Helper.prototype.createAlias = function (map) { var mapId; if (map === undefined) { mapId = this.idCounter++; @@ -168,17 +168,17 @@ Helper.prototype.createAlias = function(map) { mapId = map.getId(); } var result = new Alias({ - idObject : this.idCounter++, - name : "Test element", - type : "RNA", - modelId : mapId, - bounds : { - x : 10.0, - y : 20.0, - width : 30.0, - height : 40.0, + idObject: this.idCounter++, + name: "Test element", + type: "RNA", + modelId: mapId, + bounds: { + x: 10.0, + y: 20.0, + width: 30.0, + height: 40.0, }, - references : [], + references: [], }); if (map !== undefined) { map.getModel().addAlias(result); @@ -186,55 +186,63 @@ Helper.prototype.createAlias = function(map) { return result; }; -Helper.prototype.createLayoutAlias = function(alias) { +Helper.prototype.createLayoutAlias = function (alias) { var id; + var modelId; if (alias instanceof Alias) { id = alias.getId(); + modelId = alias.getModelId(); } else { id = this.idCounter++; + modelId = this.idCounter++; } var result = new LayoutAlias({ - idObject : id, - value : 0.2, - color : { - a : 23 + idObject: id, + value: 0.2, + color: { + a: 23 }, - geneVariations : [ {} ] + modelId: modelId, + geneVariations: [{}] }); return result; }; -Helper.prototype.createLayoutReaction = function(reaction) { +Helper.prototype.createLayoutReaction = function (reaction) { var reactionId; + var modelId; if (reaction instanceof Reaction) { reactionId = reaction.getId(); + modelId = reaction.getModelId(); } else { reactionId = this.idCounter++; + modelId = this.idCounter++; } var result = new LayoutReaction({ - idObject : reactionId, - width : 3.4, - color : { - a : 24, + idObject: reactionId, + modelId: modelId, + width: 3.4, + color: { + a: 24, }, - reverse : true + reverse: true }); return result; }; -Helper.prototype.createIdentifiedElement = function(element) { +Helper.prototype.createIdentifiedElement = function (element) { if (element === undefined) { return new IdentifiedElement({ - type : "ALIAS", - id : this.idCounter++, - modelId : this.idCounter++, + type: "ALIAS", + id: this.idCounter++, + modelId: this.idCounter++, }); } return new IdentifiedElement(element); }; -Helper.prototype.createReaction = function(map) { +Helper.prototype.createReaction = function (map) { var mapId = null; if (map !== undefined) { mapId = map.getId(); @@ -242,49 +250,49 @@ Helper.prototype.createReaction = function(map) { mapId = this.idCounter++; } var result = new Reaction({ - idObject : this.idCounter++, - lines : [ { - start : { - x : 434.8904109589041, - y : 85.0 + idObject: this.idCounter++, + lines: [{ + start: { + x: 434.8904109589041, + y: 85.0 }, - end : { - x : 410.8341500923087, - y : 104.95576185524392 + end: { + x: 410.8341500923087, + y: 104.95576185524392 }, - type : "START" + type: "START" }, { - start : { - x : 404.6769250286157, - y : 110.06345991944379 + start: { + x: 404.6769250286157, + y: 110.06345991944379 }, - end : { - x : 380.62066416202026, - y : 130.0192217746877 + end: { + x: 380.62066416202026, + y: 130.0192217746877 }, - type : "END" - } ], - centerPoint : new google.maps.Point(0, 0), - modelId : mapId, - references : [], + type: "END" + }], + centerPoint: new google.maps.Point(0, 0), + modelId: mapId, + references: [], }); return result; }; -Helper.prototype.createOptions = function(project) { +Helper.prototype.createOptions = function (project) { if (project === undefined) { project = this.createProject(); } var options = { - mapDiv : testDiv, - element : testDiv, - project : project, + mapDiv: testDiv, + element: testDiv, + project: project, }; return options; }; -Helper.prototype.createModel = function() { +Helper.prototype.createModel = function () { var result = new Model(); result.setId(this.idCounter++); result.setTileSize(256); @@ -293,16 +301,16 @@ Helper.prototype.createModel = function() { result.setMaxZoom(8); result.setMinZoom(2); result.setCenterLatLng({ - lat : 10, - lng : 20 + lat: 10, + lng: 20 }); result.setTopLeftLatLng({ - lat : 8, - lng : 8 + lat: 8, + lng: 8 }); result.setBottomRightLatLng({ - lat : 30, - lng : 30 + lat: 30, + lng: 30 }); var layout = this.createLayout(); @@ -310,51 +318,51 @@ Helper.prototype.createModel = function() { return result; }; -Helper.prototype.createLayout = function() { +Helper.prototype.createLayout = function () { var id = this.idCounter++; var layout = new LayoutData({ - idObject : id, - name : "testLayout" + id, + idObject: id, + name: "testLayout" + id, }); return layout; }; -Helper.prototype.createGoogleMap = function() { +Helper.prototype.createGoogleMap = function () { var result = new google.maps.Map(testDiv, { - center : { - lat : -34.397, - lng : 150.644 + center: { + lat: -34.397, + lng: 150.644 }, - scrollwheel : false, - zoom : 8 + scrollwheel: false, + zoom: 8 }); return result; }; -Helper.prototype.createCustomMapOptions = function(project) { +Helper.prototype.createCustomMapOptions = function (project) { if (project === undefined) { project = this.createProject(); } var result = new CustomMapOptions({ - markerOptimization : true, - project : project, - element : testDiv, - mapDiv : testDiv, - configuration : this.getConfiguration(), + markerOptimization: true, + project: project, + element: testDiv, + mapDiv: testDiv, + configuration: this.getConfiguration(), }); return result; }; -Helper.prototype.createAbstractCustomMap = function() { +Helper.prototype.createAbstractCustomMap = function () { var options = this.createCustomMapOptions(); var result = new AbstractCustomMap(options.getProject().getModel(), options); return result; }; -Helper.prototype.createCustomMap = function(project) { +Helper.prototype.createCustomMap = function (project) { if (project === null) { throw new Error("Project cannot be null"); } @@ -366,12 +374,12 @@ Helper.prototype.createCustomMap = function(project) { /** * Changes url but saves the cookies. */ -Helper.prototype.setUrl = function(url) { +Helper.prototype.setUrl = function (url) { var cookies = Cookies.get(); global.dom.reconfigure({ - url : url + url: url }); - for ( var cookie in cookies) { + for (var cookie in cookies) { Cookies.set(cookie, cookies[cookie]); } GuiConnector.init(); diff --git a/frontend-js/src/test/js/map/CustomMap-test.js b/frontend-js/src/test/js/map/CustomMap-test.js index 3c434c3198f62fb471c0981e85acc049982341f4..ccef0aab0a0865668b57ecfe6558b6255ab7d577 100644 --- a/frontend-js/src/test/js/map/CustomMap-test.js +++ b/frontend-js/src/test/js/map/CustomMap-test.js @@ -116,24 +116,19 @@ describe('CustomMap', function() { it("simple", function() { var map = helper.createCustomMap(); - var alias = helper.createAlias(); - alias.setModelId(map.getId()); + var alias = helper.createAlias(map); map.getModel().addAlias(alias); - var reaction = helper.createReaction(); + var reaction = helper.createReaction(map); map.getModel().addReaction(reaction); var layout = helper.createLayout(); layout.setInputDataAvailable(true); layout.setInitialized(true); - var layoutAlias = helper.createLayoutAlias(); - layoutAlias.setId(alias.getId()); - layoutAlias.setModelId(map.getId()); + var layoutAlias = helper.createLayoutAlias(alias); layout.addAlias(layoutAlias); - var layoutReaction = helper.createLayoutReaction(); - layoutReaction.setId(reaction.getId()); - layoutReaction.setModelId(map.getId()); + var layoutReaction = helper.createLayoutReaction(reaction); layout.addReaction(layoutReaction); map.getModel().addLayout(layout);