@@ -32,9 +32,6 @@ function Mapbox(opts) {
3232 // unique id for this Mapbox instance
3333 this . uid = fullLayout . _uid + '-' + this . id ;
3434
35- // full mapbox options (N.B. needs to be updated on every updates)
36- this . opts = fullLayout [ this . id ] ;
37-
3835 // create framework on instantiation for a smoother first plot call
3936 this . div = null ;
4037 this . xaxis = null ;
@@ -57,9 +54,7 @@ module.exports = function createMapbox(opts) {
5754
5855proto . plot = function ( calcData , fullLayout , promises ) {
5956 var self = this ;
60-
61- // feed in new mapbox options
62- var opts = self . opts = fullLayout [ this . id ] ;
57+ var opts = fullLayout [ self . id ] ;
6358
6459 // remove map and create a new map if access token has change
6560 if ( self . map && ( opts . accesstoken !== self . accessToken ) ) {
@@ -88,7 +83,7 @@ proto.plot = function(calcData, fullLayout, promises) {
8883proto . createMap = function ( calcData , fullLayout , resolve , reject ) {
8984 var self = this ;
9085 var gd = self . gd ;
91- var opts = self . opts ;
86+ var opts = fullLayout [ self . id ] ;
9287
9388 // store style id and URL or object
9489 var styleObj = self . styleObj = getStyleObj ( opts . style ) ;
@@ -147,14 +142,16 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
147142 // duplicate 'plotly_relayout' events.
148143
149144 if ( eventData . originalEvent || wheeling ) {
150- var view = self . getView ( ) ;
145+ var optsNow = gd . _fullLayout [ self . id ] ;
146+ Registry . call ( '_storeDirectGUIEdit' , gd . layout , gd . _fullLayout . _preGUI , self . getViewEdits ( optsNow ) ) ;
151147
152- opts . _input . center = opts . center = view . center ;
153- opts . _input . zoom = opts . zoom = view . zoom ;
154- opts . _input . bearing = opts . bearing = view . bearing ;
155- opts . _input . pitch = opts . pitch = view . pitch ;
148+ var viewNow = self . getView ( ) ;
149+ optsNow . _input . center = optsNow . center = viewNow . center ;
150+ optsNow . _input . zoom = optsNow . zoom = viewNow . zoom ;
151+ optsNow . _input . bearing = optsNow . bearing = viewNow . bearing ;
152+ optsNow . _input . pitch = optsNow . pitch = viewNow . pitch ;
156153
157- emitRelayoutFromView ( view ) ;
154+ gd . emit ( 'plotly_relayout' , self . getViewEdits ( viewNow ) ) ;
158155 }
159156 wheeling = false ;
160157 } ) ;
@@ -186,35 +183,25 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
186183 map . on ( 'zoomstart' , unhover ) ;
187184
188185 map . on ( 'dblclick' , function ( ) {
189- gd . emit ( 'plotly_doubleclick' , null ) ;
186+ var optsNow = gd . _fullLayout [ self . id ] ;
187+ Registry . call ( '_storeDirectGUIEdit' , gd . layout , gd . _fullLayout . _preGUI , self . getViewEdits ( optsNow ) ) ;
190188
191189 var viewInitial = self . viewInitial ;
192-
193190 map . setCenter ( convertCenter ( viewInitial . center ) ) ;
194191 map . setZoom ( viewInitial . zoom ) ;
195192 map . setBearing ( viewInitial . bearing ) ;
196193 map . setPitch ( viewInitial . pitch ) ;
197194
198195 var viewNow = self . getView ( ) ;
196+ optsNow . _input . center = optsNow . center = viewNow . center ;
197+ optsNow . _input . zoom = optsNow . zoom = viewNow . zoom ;
198+ optsNow . _input . bearing = optsNow . bearing = viewNow . bearing ;
199+ optsNow . _input . pitch = optsNow . pitch = viewNow . pitch ;
199200
200- opts . _input . center = opts . center = viewNow . center ;
201- opts . _input . zoom = opts . zoom = viewNow . zoom ;
202- opts . _input . bearing = opts . bearing = viewNow . bearing ;
203- opts . _input . pitch = opts . pitch = viewNow . pitch ;
204-
205- emitRelayoutFromView ( viewNow ) ;
201+ gd . emit ( 'plotly_doubleclick' , null ) ;
202+ gd . emit ( 'plotly_relayout' , self . getViewEdits ( viewNow ) ) ;
206203 } ) ;
207204
208- function emitRelayoutFromView ( view ) {
209- var id = self . id ;
210- var evtData = { } ;
211- for ( var k in view ) {
212- evtData [ id + '.' + k ] = view [ k ] ;
213- }
214- Registry . call ( '_storeDirectGUIEdit' , gd . layout , gd . _fullLayout . _preGUI , evtData ) ;
215- gd . emit ( 'plotly_relayout' , evtData ) ;
216- }
217-
218205 // define event handlers on map creation, to keep one ref per map,
219206 // so that map.on / map.off in updateFx works as expected
220207 self . clearSelect = function ( ) {
@@ -248,10 +235,11 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
248235proto . updateMap = function ( calcData , fullLayout , resolve , reject ) {
249236 var self = this ;
250237 var map = self . map ;
238+ var opts = fullLayout [ this . id ] ;
251239
252240 self . rejectOnError ( reject ) ;
253241
254- var styleObj = getStyleObj ( self . opts . style ) ;
242+ var styleObj = getStyleObj ( opts . style ) ;
255243
256244 if ( self . styleObj . id !== styleObj . id ) {
257245 self . styleObj = styleObj ;
@@ -309,14 +297,14 @@ proto.updateData = function(calcData) {
309297
310298proto . updateLayout = function ( fullLayout ) {
311299 var map = this . map ;
312- var opts = this . opts ;
300+ var opts = fullLayout [ this . id ] ;
313301
314302 map . setCenter ( convertCenter ( opts . center ) ) ;
315303 map . setZoom ( opts . zoom ) ;
316304 map . setBearing ( opts . bearing ) ;
317305 map . setPitch ( opts . pitch ) ;
318306
319- this . updateLayers ( ) ;
307+ this . updateLayers ( fullLayout ) ;
320308 this . updateFramework ( fullLayout ) ;
321309 this . updateFx ( fullLayout ) ;
322310 this . map . resize ( ) ;
@@ -463,8 +451,8 @@ proto.updateFramework = function(fullLayout) {
463451 this . yaxis . _length = size . h * ( domain . y [ 1 ] - domain . y [ 0 ] ) ;
464452} ;
465453
466- proto . updateLayers = function ( ) {
467- var opts = this . opts ;
454+ proto . updateLayers = function ( fullLayout ) {
455+ var opts = fullLayout [ this . id ] ;
468456 var layers = opts . layers ;
469457 var layerList = this . layerList ;
470458 var i ;
@@ -519,7 +507,6 @@ proto.project = function(v) {
519507// get map's current view values in plotly.js notation
520508proto . getView = function ( ) {
521509 var map = this . map ;
522-
523510 var mapCenter = map . getCenter ( ) ;
524511 var center = { lon : mapCenter . lng , lat : mapCenter . lat } ;
525512
@@ -531,6 +518,19 @@ proto.getView = function() {
531518 } ;
532519} ;
533520
521+ proto . getViewEdits = function ( cont ) {
522+ var id = this . id ;
523+ var keys = [ 'center' , 'zoom' , 'bearing' , 'pitch' ] ;
524+ var obj = { } ;
525+
526+ for ( var i = 0 ; i < keys . length ; i ++ ) {
527+ var k = keys [ i ] ;
528+ obj [ id + '.' + k ] = cont [ k ] ;
529+ }
530+
531+ return obj ;
532+ } ;
533+
534534function getStyleObj ( val ) {
535535 var styleValues = layoutAttributes . style . values ;
536536 var styleDflt = layoutAttributes . style . dflt ;
0 commit comments