Skip to content

Commit

Permalink
included the fogotted view change logics
Browse files Browse the repository at this point in the history
  • Loading branch information
Navxihziq committed Jun 16, 2024
1 parent f683989 commit 3d8d537
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions streamlit_folium/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,45 @@ async function onRender(event: Event) {
window.__GLOBAL_DATA__.last_layer_control = layer_control

if (feature_group) {
// render feature group
console.log("Rendering feature group...")
eval(feature_group)
// eslint-disable-next-line
eval(feature_group + layer_control)
for (let key in window.map._layers) {
let layer = window.map._layers[key]
layer.off("click", onLayerClick)
layer.on("click", onLayerClick)
if (return_on_hover) {
layer.off("mouseover", onLayerClick)
layer.on("mouseover", onLayerClick)
}
}
} else {
// eslint-disable-next-line
eval(layer_control)
}
}

var view_changed = false
var new_zoom = window.map.getZoom()
if (zoom && zoom !== window.__GLOBAL_DATA__.last_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)
) {
new_center = center
window.__GLOBAL_DATA__.last_center = center
view_changed = true
}

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

if (!window.map) {
Expand Down

0 comments on commit 3d8d537

Please sign in to comment.