Skip to content

Commit f2478f9

Browse files
authored
Merge pull request #2709 from plotly/mapbox-scroll
plotly_relayout on mapbox scroll
2 parents 95c88e6 + 6903320 commit f2478f9

14 files changed

+62
-284
lines changed

package-lock.json

+35-271
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"glslify": "^6.1.1",
8787
"has-hover": "^1.0.1",
8888
"has-passive-events": "^1.0.0",
89-
"mapbox-gl": "0.44.1",
89+
"mapbox-gl": "0.45.0",
9090
"matrix-camera-controller": "^2.1.3",
9191
"mouse-change": "^1.4.0",
9292
"mouse-event-offset": "^3.0.2",

src/plots/mapbox/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
'use strict';
1010

11-
var requiredVersion = '0.44.1';
11+
var requiredVersion = '0.45.0';
1212

1313
module.exports = {
1414
requiredVersion: requiredVersion,

src/plots/mapbox/mapbox.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
130130

131131
if(self.isStatic) return;
132132

133+
var wheeling = false;
134+
133135
// keep track of pan / zoom in user layout and emit relayout event
134136
map.on('moveend', function(eventData) {
135137
if(!self.map) return;
@@ -149,11 +151,16 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
149151
// mouse target (filtering out API calls) to not
150152
// duplicate 'plotly_relayout' events.
151153

152-
if(eventData.originalEvent) {
154+
if(eventData.originalEvent || wheeling) {
153155
var update = {};
154156
update[self.id] = Lib.extendFlat({}, view);
155157
gd.emit('plotly_relayout', update);
156158
}
159+
wheeling = false;
160+
});
161+
162+
map.on('wheel', function() {
163+
wheeling = true;
157164
});
158165

159166
map.on('mousemove', function(evt) {

test/image/baselines/mapbox_0.png

89 Bytes
Loading
7 KB
Loading
709 Bytes
Loading
71 Bytes
Loading
-48 Bytes
Loading
-15.1 KB
Loading

test/image/baselines/mapbox_fill.png

-26 Bytes
Loading
711 Bytes
Loading
-105 Bytes
Loading

test/jasmine/tests/mapbox_test.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,14 @@ describe('@noCI, mapbox plots', function() {
827827
doubleClickCnt++;
828828
});
829829

830+
function _scroll(p) {
831+
return new Promise(function(resolve) {
832+
mouseEvent('mousemove', p[0], p[1]);
833+
mouseEvent('scroll', p[0], p[1], {deltaY: -400});
834+
setTimeout(resolve, 1000);
835+
});
836+
}
837+
830838
function assertLayout(center, zoom, opts) {
831839
var mapInfo = getMapInfo(gd),
832840
layout = gd.layout.mapbox;
@@ -858,14 +866,18 @@ describe('@noCI, mapbox plots', function() {
858866
.then(function() {
859867
expect(doubleClickCnt).toBe(1, 'double click cnt');
860868
assertLayout([-4.710, 19.475], 1.234);
869+
870+
return _scroll(pointPos);
871+
})
872+
.then(function() {
873+
expect(getMapInfo(gd).zoom).toBeGreaterThan(1.234);
874+
expect(relayoutCnt).toBe(2);
861875
})
862876
.catch(failTest)
863877
.then(done);
864-
865-
// TODO test scroll
866-
867878
}, LONG_TIMEOUT_INTERVAL);
868879

880+
869881
it('should respond to click interactions by', function(done) {
870882
var ptData;
871883

@@ -1001,13 +1013,8 @@ describe('@noCI, mapbox plots', function() {
10011013
}
10021014

10031015
function _click(pos, cb) {
1004-
var promise = _mouseEvent('mousemove', pos, noop).then(function() {
1005-
return _mouseEvent('mousedown', pos, noop);
1006-
}).then(function() {
1007-
return _mouseEvent('click', pos, cb);
1008-
});
1009-
1010-
return promise;
1016+
mouseEvent('mousemove', pos[0], pos[1]);
1017+
return _mouseEvent('click', pos, cb);
10111018
}
10121019

10131020
function _doubleClick(pos) {

0 commit comments

Comments
 (0)