diff --git a/frontend-js/src/main/js/map/CustomMap.js b/frontend-js/src/main/js/map/CustomMap.js index 882a665b97767d31e7f0e4142de2827917192df0..26824f4642b5aecc05381ef15e6723cc2e1152c6 100644 --- a/frontend-js/src/main/js/map/CustomMap.js +++ b/frontend-js/src/main/js/map/CustomMap.js @@ -37,6 +37,7 @@ function CustomMap(options) { this.registerListenerType("onBioEntityClick"); this.registerListenerType("onShowOverlay"); this.registerListenerType("onHideOverlay"); + this.registerListenerType("onBackgroundOverlayChange"); this._selectedOverlays = []; @@ -230,14 +231,18 @@ CustomMap.prototype.openDataOverlay = function (param) { }); } } else { - self.getGoogleMap().setMapTypeId(identifier.toString()); + if (identifier.toString() === self.getGoogleMap().getMapTypeId()) { + return Promise.resolve(); + } else { + self.getGoogleMap().setMapTypeId(identifier.toString()); - var submaps = self.getSubmaps(); - for (var i = 0; i < submaps.length; i++) { - var submap = submaps[i]; - submap.openDataOverlay(identifier); + var submaps = self.getSubmaps(); + for (var i = 0; i < submaps.length; i++) { + var submap = submaps[i]; + submap.openDataOverlay(identifier); + } + return self.callListeners("onBackgroundOverlayChange", identifier); } - return Promise.resolve(); } }).then(function () { return self.callListeners("onShowOverlay", overlayToOpen); diff --git a/frontend-js/src/test/js/map/CustomMap-test.js b/frontend-js/src/test/js/map/CustomMap-test.js index 6c14e03b7afa5b4a32510ed961baaadd070d47f2..f2aac9e96cded5bf6715c33f0ca1a398ff6b8446 100644 --- a/frontend-js/src/test/js/map/CustomMap-test.js +++ b/frontend-js/src/test/js/map/CustomMap-test.js @@ -132,6 +132,35 @@ describe('CustomMap', function () { }); }); + it("check backgroundChangeListener", function () { + var map = helper.createCustomMap(); + var overlay = helper.createOverlay(); + overlay.setInitialized(true); + overlay.setInputDataAvailable(true); + map.getProject().addDataOverlay(overlay); + var overlay2 = helper.createOverlay(); + overlay2.setInitialized(true); + overlay2.setInputDataAvailable(true); + map.getProject().addDataOverlay(overlay2); + + var emptyBackground = helper.createOverlay(); + emptyBackground.setInputDataAvailable(false); + emptyBackground.setName("Empty"); + map.getProject().addDataOverlay(emptyBackground); + + var counter = 0; + map.addListener("onBackgroundOverlayChange", function () { + counter++; + }); + + return map.openDataOverlay(overlay.getId()).then(function () { + assert.equal(1, counter, "listener wasn't fired"); + return map.openDataOverlay(overlay2.getId()); + }).then(function () { + assert.equal(1, counter, "listener shouldn't be fired again because nothing changed"); + }); + }); + it("simple", function () { var map = helper.createCustomMap(); var alias = helper.createAlias(map);