Skip to content

Commit 16a01e7

Browse files
committed
implement scrollZoom:false for mapbox subplots
1 parent 26618dd commit 16a01e7

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/plots/mapbox/mapbox.js

+6
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ proto.updateMap = function(calcData, fullLayout, resolve, reject) {
258258
self.updateLayout(fullLayout);
259259
self.resolveOnRender(resolve);
260260
}
261+
262+
if(this.gd._context._scrollZoom.mapbox) {
263+
map.scrollZoom.enable();
264+
} else {
265+
map.scrollZoom.disable();
266+
}
261267
};
262268

263269
proto.updateData = function(calcData) {

test/jasmine/tests/mapbox_test.js

+45
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,51 @@ describe('@noCI, mapbox plots', function() {
976976
.then(done);
977977
}, LONG_TIMEOUT_INTERVAL);
978978

979+
it('should respect scrollZoom config option', function(done) {
980+
var relayoutCnt = 0;
981+
gd.on('plotly_relayout', function() { relayoutCnt++; });
982+
983+
function _scroll() {
984+
relayoutCnt = 0;
985+
return new Promise(function(resolve) {
986+
mouseEvent('mousemove', pointPos[0], pointPos[1]);
987+
mouseEvent('scroll', pointPos[0], pointPos[1], {deltaY: -400});
988+
setTimeout(resolve, 500);
989+
});
990+
}
991+
992+
var zoom = getMapInfo(gd).zoom;
993+
expect(zoom).toBeCloseTo(1.234);
994+
995+
_scroll().then(function() {
996+
expect(relayoutCnt).toBe(1, 'scroll relayout cnt');
997+
998+
var zoomNew = getMapInfo(gd).zoom;
999+
expect(zoomNew).toBeGreaterThan(zoom);
1000+
zoom = zoomNew;
1001+
})
1002+
.then(function() { return Plotly.plot(gd, [], {}, {scrollZoom: false}); })
1003+
.then(_scroll)
1004+
.then(function() {
1005+
expect(relayoutCnt).toBe(0, 'no additional relayout call');
1006+
1007+
var zoomNew = getMapInfo(gd).zoom;
1008+
expect(zoomNew).toBe(zoom);
1009+
zoom = zoomNew;
1010+
})
1011+
.then(function() { return Plotly.plot(gd, [], {}, {scrollZoom: true}); })
1012+
.then(_scroll)
1013+
.then(function() {
1014+
expect(relayoutCnt).toBe(1, 'scroll relayout cnt');
1015+
1016+
var zoomNew = getMapInfo(gd).zoom;
1017+
expect(zoomNew).toBeGreaterThan(zoom);
1018+
zoom = zoomNew;
1019+
})
1020+
.catch(failTest)
1021+
.then(done);
1022+
}, LONG_TIMEOUT_INTERVAL);
1023+
9791024
function getMapInfo(gd) {
9801025
var subplot = gd._fullLayout.mapbox._subplot;
9811026
var map = subplot.map;

0 commit comments

Comments
 (0)