Hello!
I am using streamlit to produce some maps using mapbox_scatter. Is there a way to retain the zoom level when the code reruns (e.g. when a user changes one of the filters)? Currently, if I zoom in on the map, then change the ‘layers’ (they’re not layers really), then it defaults back to the initial zoom - see screen snips below
I have used the code below to try and hold the mapbox center and zoom variables in the session state, but I do not think these are overwritten when the maps are zoomed (they seem to just stay as the default -3,55 values)
if "mapfig" in st.session_state:
cent = st.session_state.mapfig.layout.mapbox.center
zoom = st.session_state.mapfig.layout.mapbox.zoom
else:
cent = {'lon':-3, 'lat':55}
zoom = 4.5
st.session_state.mapfig = go.Figure()
# process data to plot
st.session_state.mapfig.add_trace(go.Scattermapbox(lat=lats, lon=lons, mode=lines)
st.session_state.mapfig.update_layout(mapbox={'style':"open-street-map",'center':cent,'zoom':zoom})
st.plotly_chart(st.session_state.mapfig,height=500)
Is there a way to obtain these values directly from Streamlit? Or a way to force the map to maintain it’s zoom limits when it calls back to python?
Many thanks, please ask if more info or details would be helpful!