You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to move a single marker on the map to where the user clicks on the map but I'm struggling. With every click (st_folium) the marker is moving to the previous click location instead of the current click location. What I am doing wrong here?
# State variablesif'center'notinst.session_state:
st.session_state.center= [45.503032, -73.566424]
if'zoom'notinst.session_state:
st.session_state.zoom=15if'location'notinst.session_state:
st.session_state.location=folium.Marker(st.session_state.center)
# Map creationm=folium.Map(location=st.session_state.center, zoom_start=st.session_state.zoom)
fg=folium.FeatureGroup(name="Markers")
fg.add_child(st.session_state.location)
# When the user interacts with the mapmap_state_change=st_folium(
m,
feature_group_to_add=fg,
height=400,
width='100%',
returned_objects=['last_clicked', 'zoom', 'bounds', 'center'],
)
# If the interaction includes a clickifmap_state_change['last_clicked']:
loc=map_state_change['last_clicked']
st.session_state.location=folium.Marker([loc['lat'], loc['lng']])
The text was updated successfully, but these errors were encountered:
What I ended up doing is not relying on a click at all. I added a crosshair as text in my Streamlit app and some hacky markdown to position the crosshair in the center of the map. You can see the app and code at https://isochrone.streamlit.app/.
I'm trying to move a single marker on the map to where the user clicks on the map but I'm struggling. With every click (st_folium) the marker is moving to the previous click location instead of the current click location. What I am doing wrong here?
The text was updated successfully, but these errors were encountered: