Skip to content

Mapbox react updates #4418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 16, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/plots/mapbox/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ function Mapbox(gd, id) {
this.traceHash = {};
this.layerList = [];
this.belowLookup = {};
this.dragging = false;
this.wheeling = false;
}

var proto = Mapbox.prototype;
Expand Down Expand Up @@ -351,10 +353,12 @@ proto.updateLayout = function(fullLayout) {
var map = this.map;
var opts = fullLayout[this.id];

map.setCenter(convertCenter(opts.center));
map.setZoom(opts.zoom);
map.setBearing(opts.bearing);
map.setPitch(opts.pitch);
if(!this.dragging && !this.wheeling) {
map.setCenter(convertCenter(opts.center));
map.setZoom(opts.zoom);
map.setBearing(opts.bearing);
map.setPitch(opts.pitch);
}

this.updateLayers(fullLayout);
this.updateFramework(fullLayout);
Expand Down Expand Up @@ -435,8 +439,6 @@ proto.initFx = function(calcData, fullLayout) {
var gd = self.gd;
var map = self.map;

var wheeling = false;

// keep track of pan / zoom in user layout and emit relayout event
map.on('moveend', function(evt) {
if(!self.map) return;
Expand All @@ -451,7 +453,7 @@ proto.initFx = function(calcData, fullLayout) {
// mouse target (filtering out API calls) to not
// duplicate 'plotly_relayout' events.

if(evt.originalEvent || wheeling) {
if(evt.originalEvent || self.wheeling) {
var optsNow = fullLayoutNow[self.id];
Registry.call('_storeDirectGUIEdit', gd.layout, fullLayoutNow._preGUI, self.getViewEdits(optsNow));

Expand All @@ -460,18 +462,21 @@ proto.initFx = function(calcData, fullLayout) {
optsNow._input.zoom = optsNow.zoom = viewNow.zoom;
optsNow._input.bearing = optsNow.bearing = viewNow.bearing;
optsNow._input.pitch = optsNow.pitch = viewNow.pitch;

gd.emit('plotly_relayout', self.getViewEditsWithDerived(viewNow));
}
wheeling = false;
if(evt.originalEvent && evt.originalEvent.type === 'mouseup') {
self.dragging = false;
} else if(self.wheeling) {
self.wheeling = false;
}

if(fullLayoutNow._rehover) {
fullLayoutNow._rehover();
}
});

map.on('wheel', function() {
wheeling = true;
self.wheeling = true;
});

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

map.on('dragstart', unhover);
map.on('dragstart', function() {
self.dragging = true;
unhover();
});
map.on('zoomstart', unhover);

map.on('mouseout', function() {
Expand Down