From 267c74e20f7b78d3aa4989a539bd6c68d2b34c7e Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Fri, 26 May 2017 16:46:44 +0200 Subject: [PATCH] setZoom and setCenter methodes removed to abstract map class --- .../src/main/js/map/AbstractCustomMap.js | 34 ++++++++++ frontend-js/src/main/js/map/CustomMap.js | 62 ++----------------- frontend-js/src/test/js/map/CustomMap-test.js | 8 +-- 3 files changed, 44 insertions(+), 60 deletions(-) diff --git a/frontend-js/src/main/js/map/AbstractCustomMap.js b/frontend-js/src/main/js/map/AbstractCustomMap.js index 1ce2611678..e7a5907998 100644 --- a/frontend-js/src/main/js/map/AbstractCustomMap.js +++ b/frontend-js/src/main/js/map/AbstractCustomMap.js @@ -985,5 +985,39 @@ 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) { + if (coordinates instanceof google.maps.Point) { + coordinates = this.fromPointToLatLng(coordinates); + } + if (this.initialized) { + this.getGoogleMap().setCenter(coordinates); + } else { + logger.warn("cannot center map that is not opened yet"); + } +}; + + +/** + * 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) { + if (this.initialized) { + this.getGoogleMap().setZoom(zoom); + } else { + logger.warn("cannot center map that is not opened yet"); + } +}; + module.exports = AbstractCustomMap; diff --git a/frontend-js/src/main/js/map/CustomMap.js b/frontend-js/src/main/js/map/CustomMap.js index 7156e413da..255f1841e0 100644 --- a/frontend-js/src/main/js/map/CustomMap.js +++ b/frontend-js/src/main/js/map/CustomMap.js @@ -464,50 +464,6 @@ CustomMap.prototype.customizeGoogleMapView = function(div) { } }; -/** - * Sets center point for google maps. - * - * @param mapIdentifier - * id of the model for which we change center - * @param coordinates - * new center point on map - */ -CustomMap.prototype.setCenter = function(mapIdentifier, coordinates) { - var submap = this.getSubmapById(mapIdentifier); - if (submap !== null) { - if (coordinates instanceof google.maps.Point) { - coordinates = submap.fromPointToLatLng(coordinates); - } - if (submap.initialized) { - submap.getGoogleMap().setCenter(coordinates); - } else { - logger.warn("cannot center map that is not opened yet"); - } - } else { - throw new Error("cannot find submap with id: " + mapIdentifier); - } -}; - -/** - * 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 - */ -CustomMap.prototype.setZoom = function(mapIdentifier, zoom) { - var submap = this.getSubmapById(mapIdentifier); - if (submap !== null) { - if (submap.initialized) { - submap.getGoogleMap().setZoom(zoom); - } else { - logger.warn("cannot center map that is not opened yet"); - } - } else { - throw new Error("cannot find submap with id: " + mapIdentifier); - } -}; /** * Creates listeners for google.maps.Map object that will actualize the data in @@ -570,16 +526,10 @@ CustomMap.prototype.removeSelection = function() { }; CustomMap.prototype.showModel = function(id, point, zoomLevel) { - if (point !== undefined) { - this.setCenter(id, point); - } else { - logger.warn("Center point undefined..."); - } - if (zoomLevel !== undefined) { - this.setZoom(id, zoomLevel); - } else { - logger.warn("Zoom level undefined..."); - } + this.openSubmap(id); + var submap = this.getSubmapById(id); + submap.setCenter(point); + submap.setZoom(zoomLevel); }; /** @@ -1039,11 +989,11 @@ CustomMap.prototype.getOverlayByName = function(name) { CustomMap.prototype.getDbOverlays = function() { var result = []; - for (var overlayName in this.overlayCollections) { + for ( var overlayName in this.overlayCollections) { if (this.overlayCollections.hasOwnProperty(overlayName)) { result.push(this.overlayCollections[overlayName]); } - } + } return result; }; diff --git a/frontend-js/src/test/js/map/CustomMap-test.js b/frontend-js/src/test/js/map/CustomMap-test.js index ff2af600f6..90e95a14fb 100644 --- a/frontend-js/src/test/js/map/CustomMap-test.js +++ b/frontend-js/src/test/js/map/CustomMap-test.js @@ -745,7 +745,7 @@ describe('CustomMap', function() { var map = new CustomMap(options); - map.setCenter(map.getId(), new google.maps.LatLng(10, 20)); + map.setCenter(new google.maps.LatLng(10, 20)); assert.ok(ServerConnector.getSessionData().getCenter(map.getModel())); }); @@ -757,16 +757,16 @@ describe('CustomMap', function() { var map = new CustomMap(options); map.openSubmap(submodel.getId()); - map.setCenter(submodel.getId(), new google.maps.LatLng(10, 20)); + map.setCenter(new google.maps.LatLng(10, 20)); assert.ok(ServerConnector.getSessionData().getCenter(submodel)); }); - it("setZoom on submap", function() { + it("setZoom", function() { var options = helper.createCustomMapOptions(); var map = new CustomMap(options); - map.setZoom(map.getId(), 3); + map.setZoom(3); assert.equal(3, ServerConnector.getSessionData().getZoomLevel(map.getModel())); }); -- GitLab