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
{{ message }}
Repository navigation
GeoJson style is not being applied correctly #1932
Expected behavior
We expect each geometry to have its own color defined by the style column.
Environment (please complete the following information):
Browser: all tested
Jupyter Notebook or html files? Both.
Python version: 3.11
folium version: 0.16.0
branca version: 0.7.1
Additional context
In a loop one can "hack" this problem by assigning a unique value using exec (note recommended though).
importfoliumm=folium.Map()
fork, glideringdf.iterrows():
exec(f"style_function = lambda x: {glider['style']}") # hack it to make it work# style_function = lambda x: glider['style'] # shows the bugfolium.GeoJson(
data=glider["geometry"],
style_function=style_function,
).add_to(m)
m
Possible solutions
I'll investigate more and see if I can come up with something.
I did try with latest branca and folium and this is not solved yet.
Update. The geopandas style column example has been broken for a while (since v0.9.0) and is unrelated to the late binding issue in the loop. It is likely due to #1058
Options:
document that we should do style_function = lambda x, style=style: style
Activity
ocefpaf commentedon Apr 19, 2024
OK. We are hitting https://docs.python-guide.org/writing/gotchas/#late-binding-closures :-/
I'll see what we can do. At least we should amend the docs.
Update. The geopandas style column example has been broken for a while (since v0.9.0) and is unrelated to the late binding issue in the loop. It is likely due to #1058
Options:
style_function = lambda x, style=style: styleConengmo commentedon May 6, 2024
Thanks for addressing this issue @ocefpaf!