From 57a06e5771305043dc08a7a6b9650e79374b103d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 8 Apr 2019 14:09:44 -0400 Subject: [PATCH] disable mapbox scroll zoom on init, when required --- src/plots/mapbox/mapbox.js | 12 ++++++------ test/jasmine/tests/mapbox_test.js | 12 +++++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/plots/mapbox/mapbox.js b/src/plots/mapbox/mapbox.js index 51e8ea9372d..12494985486 100644 --- a/src/plots/mapbox/mapbox.js +++ b/src/plots/mapbox/mapbox.js @@ -258,12 +258,6 @@ proto.updateMap = function(calcData, fullLayout, resolve, reject) { self.updateLayout(fullLayout); self.resolveOnRender(resolve); } - - if(this.gd._context._scrollZoom.mapbox) { - map.scrollZoom.enable(); - } else { - map.scrollZoom.disable(); - } }; proto.updateData = function(calcData) { @@ -314,6 +308,12 @@ proto.updateLayout = function(fullLayout) { this.updateFramework(fullLayout); this.updateFx(fullLayout); this.map.resize(); + + if(this.gd._context._scrollZoom.mapbox) { + map.scrollZoom.enable(); + } else { + map.scrollZoom.disable(); + } }; proto.resolveOnRender = function(resolve) { diff --git a/test/jasmine/tests/mapbox_test.js b/test/jasmine/tests/mapbox_test.js index a0881b6c17b..b97d0d0ff27 100644 --- a/test/jasmine/tests/mapbox_test.js +++ b/test/jasmine/tests/mapbox_test.js @@ -977,6 +977,9 @@ describe('@noCI, mapbox plots', function() { }, LONG_TIMEOUT_INTERVAL); it('should respect scrollZoom config option', function(done) { + var mockCopy2 = Lib.extendDeep({}, mock); + mockCopy2.config = {scrollZoom: false}; + var relayoutCnt = 0; gd.on('plotly_relayout', function() { relayoutCnt++; }); @@ -991,6 +994,7 @@ describe('@noCI, mapbox plots', function() { var zoom = getMapInfo(gd).zoom; expect(zoom).toBeCloseTo(1.234); + var zoom0 = zoom; _scroll().then(function() { expect(relayoutCnt).toBe(1, 'scroll relayout cnt'); @@ -1015,7 +1019,13 @@ describe('@noCI, mapbox plots', function() { var zoomNew = getMapInfo(gd).zoom; expect(zoomNew).toBeGreaterThan(zoom); - zoom = zoomNew; + }) + .then(function() { return Plotly.newPlot(gd, mockCopy2); }) + .then(_scroll) + .then(function() { + // see https://github.com/plotly/plotly.js/issues/3738 + var zoomNew = getMapInfo(gd).zoom; + expect(zoomNew).toBe(zoom0); }) .catch(failTest) .then(done);