I am using folium to visualise zones in an city.
My GeoJSON is a FeatureCollection with multiple polygons as features. I want to be able to add different popups for
To build on @David Olmo Pérez's answer, this seemed more intuitive to me.
# Create feature group to add to folium.Map object
layer = folium.FeatureGroup(name='your layer name', show=False)
# load GEOJSON, but don't add it to anything
temp_geojson = folium.GeoJson('path/to/your/file.geojson')
# iterate over GEOJSON, style individual features, and add them to FeatureGroup
for feature in temp_geojson.data['features']:
# GEOJSON layer consisting of a single feature
temp_layer = folium.GeoJson(feature,
style_function={
'color': '#000000',
'opacity': 0.7,
})
# lambda to add HTML
foo = lambda name, source: f"""
"""
# create Popup and add it to our lone feature
# this example embeds a .png
folium.Popup(
html=foo('name of your IFrame',
f'path/to/embed/file_{feature["properties"]["some_attribute"]}.png')
).add_to(temp_layer)
# consolidate individual features back into the main layer
temp_layer.add_to(layer)
# add main layer to folium.Map object
layer.add_to(m)