Path: blob/main/docs/user_guide/geojson/geojson_advanced_on_each_feature.md
1720 views
Advanced GeoJSON Customization with on_each_feature
The on_each_feature
parameter in folium.GeoJson
provides powerful customization capabilities by allowing you to execute JavaScript code for each feature in your GeoJSON data. This is particularly useful for:
Custom tooltip and popup handling for complex geometries like MultiPoint
Adding custom event listeners
Implementing advanced styling logic
Working with geometry types that need special handling
Understanding on_each_feature
The on_each_feature
parameter accepts a folium.utilities.JsCode
object containing JavaScript code that will be executed for each feature. The JavaScript function receives two parameters:
feature
: The GeoJSON feature objectlayer
: The Leaflet layer object representing the feature
Basic Example
The on_each_feature
parameter provides the flexibility needed to handle complex GeoJSON scenarios that the standard tooltip and popup classes cannot address, particularly for MultiPoint geometries and advanced interactive features.
References
Leaflet GeoJSON Tutorial - Comprehensive guide to using GeoJSON with Leaflet, including the
onEachFeature
option that inspired folium'son_each_feature
parameter.