From 156b42131d347809c1f777dd741b451e65e2b191 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Mon, 3 Jul 2017 10:27:29 +0200 Subject: [PATCH] common functionality extarcted to AbstractSurface --- .../js/map/surface/AbstractSurfaceElement.js | 16 +++++++++++++++- .../src/main/js/map/surface/AliasSurface.js | 14 ++++---------- .../src/main/js/map/surface/ReactionSurface.js | 15 +-------------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/frontend-js/src/main/js/map/surface/AbstractSurfaceElement.js b/frontend-js/src/main/js/map/surface/AbstractSurfaceElement.js index 50036f25fa..83156cb3e6 100644 --- a/frontend-js/src/main/js/map/surface/AbstractSurfaceElement.js +++ b/frontend-js/src/main/js/map/surface/AbstractSurfaceElement.js @@ -4,7 +4,8 @@ * Class representing abstract overlay element on the map relevant for a * specific layout. */ -function AbstractOverlayElement() { +function AbstractOverlayElement(params) { + this.setCustomMap(params.map); } AbstractOverlayElement.prototype.getIdentifiedElement = function() { @@ -21,4 +22,17 @@ AbstractOverlayElement.prototype.setIdentifiedElement = function(identifiedEleme this._identifiedElement = identifiedElement; }; +/** + * Returns {@link AbstractCustomMap} where surface is located. + * + * @returns {@link AbstractCustomMap} where surface is located + */ +AbstractOverlayElement.prototype.getCustomMap = function() { + return this._customMap; +}; + +AbstractOverlayElement.prototype.setCustomMap = function(customMap) { + this._customMap = customMap; +}; + module.exports = AbstractOverlayElement; diff --git a/frontend-js/src/main/js/map/surface/AliasSurface.js b/frontend-js/src/main/js/map/surface/AliasSurface.js index 89caad078d..4ded4d3fa6 100644 --- a/frontend-js/src/main/js/map/surface/AliasSurface.js +++ b/frontend-js/src/main/js/map/surface/AliasSurface.js @@ -14,14 +14,11 @@ var IdentifiedElement = require('../data/IdentifiedElement'); */ function AliasSurface(params) { // call super constructor - AbstractSurfaceElement.call(); + AbstractSurfaceElement.call(this, params); // google map object associated with the alias this.gmapObj = params.gmapObj; - // AbstractCustomMap where the alias is located - this.customMap = params.map; - // original data this.aliasData = params.alias; @@ -30,7 +27,7 @@ function AliasSurface(params) { var aliasOverlayData = self; return function() { self.getCustomMap() - .openInfoWindowForAlias(aliasOverlayData.aliasData.getId(), aliasOverlayData.customMap.getId()); + .openInfoWindowForAlias(aliasOverlayData.aliasData.getId(), aliasOverlayData.getCustomMap().getId()); }; })(); google.maps.event.addListener(this.gmapObj, 'click', onclick); @@ -49,9 +46,6 @@ AliasSurface.prototype.setMap = function(map) { this.gmapObj.setMap(map); }; -AliasSurface.prototype.getCustomMap = function() { - return this.customMap; -}; AliasSurface.prototype.setColor = function(color) { this._color = color; this.gmapObj.setOptions({ @@ -73,8 +67,8 @@ AliasSurface.prototype.setBoundsForAlias = function(startX, endX) { var pointA = new google.maps.Point(this.aliasData.x + startX * this.aliasData.width, this.aliasData.y); var pointB = new google.maps.Point(this.aliasData.x + endX * this.aliasData.width, this.aliasData.y + this.aliasData.height); - var latLngA = this.customMap.fromPointToLatLng(pointA); - var latLngB = this.customMap.fromPointToLatLng(pointB); + var latLngA = this.getCustomMap().fromPointToLatLng(pointA); + var latLngB = this.getCustomMap().fromPointToLatLng(pointB); var bounds = new google.maps.LatLngBounds(); bounds.extend(latLngA); diff --git a/frontend-js/src/main/js/map/surface/ReactionSurface.js b/frontend-js/src/main/js/map/surface/ReactionSurface.js index 1a38b8d182..76383c3c19 100644 --- a/frontend-js/src/main/js/map/surface/ReactionSurface.js +++ b/frontend-js/src/main/js/map/surface/ReactionSurface.js @@ -25,11 +25,10 @@ var IdentifiedElement = require('../data/IdentifiedElement'); */ function ReactionSurface(params) { // call super constructor - AbstractSurfaceElement.call(); + AbstractSurfaceElement.call(this, params); var overlayData = params.layoutReaction; this.setReactionData(params.reaction); - this.setCustomMap(params.map); var color = params.color; this.width = 5.0; @@ -273,18 +272,6 @@ ReactionSurface.prototype.getReactionData = function() { return this.reactionData; }; -/** - * Returns {@link AbstractCustomMap} where marker is located. - * - * @returns {@link AbstractCustomMap} where marker is located - */ -ReactionSurface.prototype.getCustomMap = function() { - return this.customMap; -}; - -ReactionSurface.prototype.setCustomMap = function(customMap) { - this.customMap = customMap; -}; ReactionSurface.prototype.getId = function() { return this._id; -- GitLab