Skip to content

Commit 6552ad0

Browse files
committed
emit plotly_relayout on mapbox scroll
1 parent 211368d commit 6552ad0

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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/jasmine/tests/mapbox_test.js

+15-3
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

0 commit comments

Comments
 (0)