Skip to content

Commit 36a2650

Browse files
committed
Don't update map view while dragging/wheeling
1 parent cf2c4fc commit 36a2650

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/plots/mapbox/mapbox.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ function Mapbox(gd, id) {
4949
this.traceHash = {};
5050
this.layerList = [];
5151
this.belowLookup = {};
52+
this.dragging = false;
53+
this.wheeling = false;
5254
}
5355

5456
var proto = Mapbox.prototype;
@@ -351,10 +353,12 @@ proto.updateLayout = function(fullLayout) {
351353
var map = this.map;
352354
var opts = fullLayout[this.id];
353355

354-
map.setCenter(convertCenter(opts.center));
355-
map.setZoom(opts.zoom);
356-
map.setBearing(opts.bearing);
357-
map.setPitch(opts.pitch);
356+
if(!this.dragging && !this.wheeling) {
357+
map.setCenter(convertCenter(opts.center));
358+
map.setZoom(opts.zoom);
359+
map.setBearing(opts.bearing);
360+
map.setPitch(opts.pitch);
361+
}
358362

359363
this.updateLayers(fullLayout);
360364
this.updateFramework(fullLayout);
@@ -435,8 +439,6 @@ proto.initFx = function(calcData, fullLayout) {
435439
var gd = self.gd;
436440
var map = self.map;
437441

438-
var wheeling = false;
439-
440442
// keep track of pan / zoom in user layout and emit relayout event
441443
map.on('moveend', function(evt) {
442444
if(!self.map) return;
@@ -451,7 +453,7 @@ proto.initFx = function(calcData, fullLayout) {
451453
// mouse target (filtering out API calls) to not
452454
// duplicate 'plotly_relayout' events.
453455

454-
if(evt.originalEvent || wheeling) {
456+
if(evt.originalEvent || self.wheeling) {
455457
var optsNow = fullLayoutNow[self.id];
456458
Registry.call('_storeDirectGUIEdit', gd.layout, fullLayoutNow._preGUI, self.getViewEdits(optsNow));
457459

@@ -460,18 +462,21 @@ proto.initFx = function(calcData, fullLayout) {
460462
optsNow._input.zoom = optsNow.zoom = viewNow.zoom;
461463
optsNow._input.bearing = optsNow.bearing = viewNow.bearing;
462464
optsNow._input.pitch = optsNow.pitch = viewNow.pitch;
463-
464465
gd.emit('plotly_relayout', self.getViewEditsWithDerived(viewNow));
465466
}
466-
wheeling = false;
467+
if(evt.originalEvent && evt.originalEvent.type === 'mouseup') {
468+
self.dragging = false;
469+
} else if(self.wheeling) {
470+
self.wheeling = false;
471+
}
467472

468473
if(fullLayoutNow._rehover) {
469474
fullLayoutNow._rehover();
470475
}
471476
});
472477

473478
map.on('wheel', function() {
474-
wheeling = true;
479+
self.wheeling = true;
475480
});
476481

477482
map.on('mousemove', function(evt) {
@@ -500,7 +505,10 @@ proto.initFx = function(calcData, fullLayout) {
500505
Fx.loneUnhover(fullLayout._hoverlayer);
501506
}
502507

503-
map.on('dragstart', unhover);
508+
map.on('dragstart', function() {
509+
self.dragging = true;
510+
unhover();
511+
});
504512
map.on('zoomstart', unhover);
505513

506514
map.on('mouseout', function() {

0 commit comments

Comments
 (0)