File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ exclude: examples/data/|.*\.css|.*\.json|.*\.geojson|.*\.html
22
33repos :
44- repo : https://github.com/pre-commit/pre-commit-hooks
5- rev : v4.5 .0
5+ rev : v4.6 .0
66 hooks :
77 - id : trailing-whitespace
88 - id : check-ast
@@ -15,12 +15,12 @@ repos:
1515 files : requirements-dev.txt
1616
1717- repo : https://github.com/astral-sh/ruff-pre-commit
18- rev : v0.3.4
18+ rev : v0.4.1
1919 hooks :
2020 - id : ruff
2121
2222- repo : https://github.com/psf/black
23- rev : 24.3 .0
23+ rev : 24.4 .0
2424 hooks :
2525 - id : black
2626 language_version : python3
Original file line number Diff line number Diff line change @@ -237,6 +237,23 @@ colormap.add_to(m)
237237m
238238```
239239
240+ >
241+ > ** Caveat**
242+ >
243+ > When using ` style_function ` in a loop you may encounter Python's 'Late Binding Closure' gotcha!
244+ > See https://docs.python-guide.org/writing/gotchas/#late-binding-closures for more info.
245+ > There are a few ways around it from using a GeoPandas object instead,
246+ > to "hacking" your ` style_function ` to force early closure, like:
247+ > ``` python
248+ > for geom, my_style in zip (geoms, my_styles):
249+ > style = my_style
250+ > style_function = lambda x , style = style: style
251+ > folium.GeoJson(
252+ > data = geom,
253+ > style_function = style_function,
254+ > ).add_to(m)
255+ > ```
256+
240257# ## Highlight function
241258
242259The `GeoJson` class provides a `highlight_function` argument, which works similarly
Original file line number Diff line number Diff line change @@ -643,6 +643,10 @@ class GeoJson(Layer):
643643 .done({{ this.get_name() }}_add);
644644 {%- endif %}
645645
646+ {%- if not this.style %}
647+ {{this.get_name()}}.setStyle(function(feature) {return feature.properties.style;});
648+ {%- endif %}
649+
646650 {% endmacro %}
647651 """
648652 ) # noqa
You can’t perform that action at this time.
0 commit comments