St_folium not taking style attribute into account

I am trying to display dynamically polygons on a map (e.g. I click on a button outside the map and it overlays a polygon on the map, and if I click on another button then another polygon appears).

As explained in, I use the feature_group_to_add parameter of st_folium to show the polygons, but any style parameter specified into a folium.GeoJson object are not taken into account when displayed on the map.

Here is example code:

style_parcels = {'fillColor': 'red', 'fillOpacity': 0.2} 
st.session_state['parcels'].append(folium.GeoJson(data=footprint.parcels, style_function = lambda x: style_parcels))

map = folium.Map(location=START_LOCATION, zoom_start=START_ZOOM, tiles='OpenStreetMap', max_zoom=21)
fg = folium.FeatureGroup(name="Parcels")
for parcel in st.session_state["parcels"]:

Above, the style_parcel dict will not be taken into account and the polygon will be displayed blue. If I specify some style into a GeoJsonTooltip, it will also not be taken into account when displayed on the map.

I think the style works if I add the folium.GeoJson polygon statically to the map (with .add_to(map)), as in, but won’t it break the dynamic aspect of the map ?

Is there any workaround possible to make it work ?

I am using python 3.11.6, streamlit 1.27.2, streamlit-folium 0.15, folium 0.14.

Hi @patrontheo, welcome to the forum! Thank you for also opening an issue on the repository issues – I’ll go ahead and link to that post, and respond your question there.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.