Skip to content
Prev Previous commit
Next Next commit
refactor out getViewEditsWithDerived method
  • Loading branch information
jonmmease committed Dec 7, 2019
commit 45ddd806fd4679486c71dd52ebc92c6af5079688
18 changes: 11 additions & 7 deletions src/plots/mapbox/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ proto.initFx = function(calcData, fullLayout) {
optsNow._input.bearing = optsNow.bearing = viewNow.bearing;
optsNow._input.pitch = optsNow.pitch = viewNow.pitch;

gd.emit('plotly_relayout', self.getViewEdits(viewNow, true));
gd.emit('plotly_relayout', self.getViewEditsWithDerived(viewNow));
}
wheeling = false;

Expand Down Expand Up @@ -509,7 +509,7 @@ proto.initFx = function(calcData, fullLayout) {

function emitUpdate() {
var viewNow = self.getView();
gd.emit('plotly_relayouting', self.getViewEdits(viewNow, true));
gd.emit('plotly_relayouting', self.getViewEditsWithDerived(viewNow));
}

map.on('drag', emitUpdate);
Expand All @@ -532,7 +532,7 @@ proto.initFx = function(calcData, fullLayout) {
optsNow._input.pitch = optsNow.pitch = viewNow.pitch;

gd.emit('plotly_doubleclick', null);
gd.emit('plotly_relayout', self.getViewEdits(viewNow, true));
gd.emit('plotly_relayout', self.getViewEditsWithDerived(viewNow));
});

// define event handlers on map creation, to keep one ref per map,
Expand Down Expand Up @@ -771,12 +771,9 @@ proto.getView = function() {
};
};

proto.getViewEdits = function(cont, derived) {
proto.getViewEdits = function(cont) {
var id = this.id;
var keys = ['center', 'zoom', 'bearing', 'pitch'];
if(derived === true) {
keys.push('_derived');
}
var obj = {};

for(var i = 0; i < keys.length; i++) {
Expand All @@ -787,6 +784,13 @@ proto.getViewEdits = function(cont, derived) {
return obj;
};

proto.getViewEditsWithDerived = function(cont) {
var id = this.id;
var obj = this.getViewEdits(cont);
obj[id + '._derived'] = cont._derived;
return obj;
};

function getStyleObj(val) {
var styleObj = {};

Expand Down