@@ -172,17 +172,9 @@ proto.createMap = function (calcData, fullLayout, resolve, reject) {
172172 . then ( function ( ) {
173173 // Capture the auto-framed view so subsequent updateLayout/resetView
174174 // calls don't reset to the schema defaults
175- if ( fitBounds ) {
176- const { center, zoom } = self . getView ( ) ;
177- opts . _input . center = opts . center = center ;
178- opts . _input . zoom = opts . zoom = zoom ;
179- self . viewInitial = {
180- center : Lib . extendFlat ( { } , center ) ,
181- bearing : opts . bearing ,
182- pitch : opts . pitch ,
183- zoom
184- } ;
185- }
175+ if ( fitBounds ) saveViewToLayout ( self , opts ) ;
176+ // Save viewInitial here to get values from the post-load map view
177+ updateViewInitial ( self , opts ) ;
186178 self . fillBelowLookup ( calcData , fullLayout ) ;
187179 self . updateData ( calcData ) ;
188180 self . updateLayout ( fullLayout ) ;
@@ -222,12 +214,46 @@ proto.updateMap = function (calcData, fullLayout, resolve, reject) {
222214 . then ( function ( ) {
223215 self . fillBelowLookup ( calcData , fullLayout ) ;
224216 self . updateData ( calcData ) ;
217+ const fitBounds = opts . _fitBounds ;
218+ if ( fitBounds ) {
219+ // Apply new bounds via map.fitBounds since map already exists
220+ map . fitBounds (
221+ [
222+ [ fitBounds . west , fitBounds . south ] ,
223+ [ fitBounds . east , fitBounds . north ]
224+ ] ,
225+ // Don't animate to get proper transform values immediately
226+ // (we need the values after the view transition; not before or mid)
227+ { padding : constants . fitBoundsPadding , animate : false }
228+ ) ;
229+ saveViewToLayout ( self , opts ) ;
230+ updateViewInitial ( self , opts ) ;
231+ }
225232 self . updateLayout ( fullLayout ) ;
226233 self . resolveOnRender ( resolve ) ;
227234 } )
228235 . catch ( reject ) ;
229236} ;
230237
238+ // Persist the current map view state
239+ function saveViewToLayout ( self , opts ) {
240+ const view = self . getView ( ) ;
241+ opts . _input . center = opts . center = view . center ;
242+ opts . _input . zoom = opts . zoom = view . zoom ;
243+ }
244+
245+ // Snapshot the current map view state for the Reset view modebar
246+ // button and dblclick handler
247+ function updateViewInitial ( self , opts ) {
248+ const view = self . getView ( ) ;
249+ self . viewInitial = {
250+ center : Lib . extendFlat ( { } , view . center ) ,
251+ bearing : opts . bearing ,
252+ pitch : opts . pitch ,
253+ zoom : view . zoom
254+ } ;
255+ }
256+
231257proto . fillBelowLookup = function ( calcData , fullLayout ) {
232258 var opts = fullLayout [ this . id ] ;
233259 var layers = opts . layers ;
0 commit comments