Skip to content

Commit

Permalink
Merge pull request #3745 from plotly/mapbox-scrollzoom-fix
Browse files Browse the repository at this point in the history
Disable mapbox scroll zoom on init, when required
  • Loading branch information
etpinard authored Apr 8, 2019
2 parents 5baa139 + 57a06e5 commit e111300
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/plots/mapbox/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 11 additions & 1 deletion test/jasmine/tests/mapbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++; });

Expand All @@ -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');
Expand All @@ -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);
Expand Down

0 comments on commit e111300

Please sign in to comment.