Skip to content

Commit

Permalink
Fix map center and zoom map update (#168)
Browse files Browse the repository at this point in the history
* fix: correctly update map center and zoom after user interacted with the map

* tmp: release to false

* tmp: release to true
  • Loading branch information
patrontheo authored Dec 22, 2023
1 parent dd7397b commit 51f3346
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions streamlit_folium/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,27 @@ function onRender(event: Event): void {
}
}

var view_changed = false
var new_zoom = window.map.getZoom()
if (zoom && zoom !== window.__GLOBAL_DATA__.last_zoom) {
window.map.setZoom(zoom)
new_zoom = zoom
window.__GLOBAL_DATA__.last_zoom = zoom
view_changed = true
}

var new_center = window.map.getCenter()
if (
center &&
JSON.stringify(center) !==
JSON.stringify(window.__GLOBAL_DATA__.last_center)
) {
window.map.panTo(center)
new_center = center
window.__GLOBAL_DATA__.last_center = center
view_changed = true
}

if (view_changed) {
window.map.setView(new_center, new_zoom)
}
}

Expand Down

0 comments on commit 51f3346

Please sign in to comment.