diff --git a/frontend-js/src/main/js/map/AbstractCustomMap.js b/frontend-js/src/main/js/map/AbstractCustomMap.js index 1ce26116786354b940fa788969cf7725888c63cd..e7a5907998b09ee8d163786fbb6dfcd0daf1cfe9 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 7156e413da97d1d7b3ffbe8996dd1d682a283734..255f1841e0ff426ac7658227e4671e2998b67bb8 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 ff2af600f62540def1c55f6143b0d746e4cd2adf..90e95a14fb85acc77823dfe7ea14d5cbcb0926e5 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())); });