Folium reload map after retrieving new objects based on draw


For a hobby project I would like to draw objects based on provided polygon by user. However, I’m facing issues with overwriting the existing geojson/map.

  1. Creating map with draw function works fine.
    m = folium.Map(location=center, zoom_start=zoom)
    map_data = st_folium(m, center=st.session_state[“center”], zoom=st.session_state[“zoom”],
    width=600, height=600)

  2. Retrieve drawing as WKT and return objects based on polygon works fine.
    if st.button(“Get results”):
    last_drawing = map_data[“last_active_drawing”]
    wkt = shape(last_drawing[‘geometry’]).wkt

    gdf = load_and_prepare_data(wkt)

    m = folium.Map(location=center, zoom_start=zoom)
    popup_fields = [col for col in gdf.columns if col != ‘geometry’]
    tooltip=folium.GeoJsonTooltip(fields=popup_fields, labels=True, sticky=False),

    map_data = st_folium(m, center=st.session_state[“center”],zoom=st.session_state[“zoom”],width=600, height=600)

Issue is with the last part. If I press the button a second map is showing up for a few miliseconds (with the correct objects plotted), however I want to overwrite the map that is initially used to draw a polygon (search area).

Struggling with this for hours so help would be really appreciated :slight_smile: