From a873d592c8136e787044740d145ca04c5370dd9a Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Wed, 24 May 2017 16:49:45 +0200 Subject: [PATCH] fix on setzoom for submaps + docs --- frontend-js/src/main/js/map/CustomMap.js | 32 ++++++++++++++----- frontend-js/src/test/js/google-map-mock.js | 1 + frontend-js/src/test/js/map/CustomMap-test.js | 9 ++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/frontend-js/src/main/js/map/CustomMap.js b/frontend-js/src/main/js/map/CustomMap.js index 7310e2ca29..f55e2ce91c 100644 --- a/frontend-js/src/main/js/map/CustomMap.js +++ b/frontend-js/src/main/js/map/CustomMap.js @@ -448,6 +448,14 @@ 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.getSubmodelById(mapIdentifier); if (submap !== null) { @@ -464,16 +472,24 @@ CustomMap.prototype.setCenter = function(mapIdentifier, 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 + */ CustomMap.prototype.setZoom = function(mapIdentifier, zoom) { - if (this.getModel().getId() === mapIdentifier) { - this.getGoogleMap().setZoom(zoom); - } else { - GuiConnector.openDialog(mapIdentifier); - for (var i = 0; i < this.submaps.length; i++) { - if (this.submaps[i].getId() === mapIdentifier) { - this.submaps[i].getGoogleMap().setZoom(zoom); - } + var submap = this.getSubmodelById(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); } }; diff --git a/frontend-js/src/test/js/google-map-mock.js b/frontend-js/src/test/js/google-map-mock.js index 53261aa0a5..243606a9c8 100644 --- a/frontend-js/src/test/js/google-map-mock.js +++ b/frontend-js/src/test/js/google-map-mock.js @@ -184,6 +184,7 @@ var google = { }, setZoom : function(zoom) { data.zoom = zoom; + google.maps.event.trigger(this, "zoom_changed", zoom); }, getCenter : function() { return data.center; diff --git a/frontend-js/src/test/js/map/CustomMap-test.js b/frontend-js/src/test/js/map/CustomMap-test.js index f0181916cb..70c78caaf2 100644 --- a/frontend-js/src/test/js/map/CustomMap-test.js +++ b/frontend-js/src/test/js/map/CustomMap-test.js @@ -734,4 +734,13 @@ describe('CustomMap', function() { assert.ok(ServerConnector.getSessionData().getCenter(submodel)); }); + it("setZoom on submap", function() { + var options = helper.createCustomMapOptions(); + + var map = new CustomMap(options); + + map.setZoom(map.getId(), 3); + assert.equal(3, ServerConnector.getSessionData().getZoomLevel(map.getModel())); + }); + }); -- GitLab