Disable fit and zoom logic on data refresh
Current State: When using auto refresh, the map automatically re-centres and adjusts the zoom level every time the panel refreshes. As a result, if a user has zoomed into a specific area or moved the map to a location of interest, their view is reset whenever new data is loaded.
Desired State The requirements for this dashboard are to have the auto refresh, and also if a user zooms into a specific location covering multiple vehicles at the time should stay at the same position after it refreshes. The current state returns the dashboard in default mode, zoomed out to the overall NSW area.
Suggested Fix: Modification to the following file: appserver/static/visualizations/maps-plus/visualization.js
The change introduces a simple one-time flag (_mfsInitDone) to ensure the fit and zoom logic executes only during the initial data load and is skipped on later refreshes.
Changes:
-
Run Auto Fit only on initial load Original:
this.isArgTrue(P)&&setTimeout(this.fitLayerBounds,O,{Changed to:this.isArgTrue(P)&&!this._mfsInitDone&&(this._mfsInitDone=!0)&&setTimeout(this.fitLayerBounds,O,{ -
Apply default zoom only on initial load Original:
,this.map.getZoom()!=N&&this.map.setZoom(N),Changed to:,!this._mfsInitDone&&this.map.getZoom()!=N&&this.map.setZoom(N),
Outcome:
- First load: the map fits/zooms to the data exactly as it does today.
- After that: data keeps refreshing, but the map stays at whatever zoom/position it is currently showing.
- Users can continue to use the Auto Fit & Zoom option from the right-click menu whenever they want to manually re-centre the map on all data points.
Fixed in v4.6.9.
Maps+ now includes an opt-in formatter option Preserve Viewport on Refresh (Map Settings). When enabled, Auto Fit & Zoom runs once on initial load; subsequent search refreshes (auto-refresh, filter changes, time range changes, panel refresh) update markers without resetting zoom or position. Use the context menu Auto Fit & Zoom to re-center manually.
Enable via format menu: Map Settings → Preserve Viewport on Refresh → Enabled
Or in dashboard XML:
<option name="leaflet_maps_app.maps-plus.preserveViewportOnRefresh">1</option>
Default is Disabled, so existing dashboards are unchanged until you opt in.
An acceptance-test dashboard is included: Examples → Preserve Viewport on Refresh (Test).
Release notes: https://github.com/sghaskell/maps-plus/blob/master/docs/release-notes-4.6.9.md
Closing as fixed in v4.6.9.