Closed
Description
Hi,
Have been trying to use make an interactive map with multiple data layers using folium. And for each layer, I would like to have tooltip and popups. Therefore I created functions to generate popups and tooltips.
However, there are issues to create multiple popups for multiple layers.
I think the issue could be link to the "name_getter" in the folium class GeoJsonPopup(GeoJsonDetail).
For GeoJsonTooltip, it works pretty fine.
from folium.features import GeoJson, GeoJsonTooltip, GeoJsonPopup
def create_popup(field):
popup = GeoJsonPopup(
fields=[field],
aliases=[field],
localize=True,
labels=True,
style="background-color: yellow;",
),
parse_html=True
return popup
def create_tooltip(field):
tooltip = GeoJsonTooltip(fields=[field],
aliases=[field],
localize=True,
sticky=False,
labels=True,
style="""
background-color: #F0EFEF;
border: 2px solid black;
border-radius: 3px;
box-shadow: 3px;
""",
max_width=800,
parse_html=True
)
return tooltip
inwoner = GeoJson(
geo_data,
style_function=lambda x: {
"fillColor": colormap_inwoner(x["properties"]["INWONER"])
if x["properties"]["INWONER"] is not None
else "transparent",
"color": "black",
"fillOpacity": 0.4,
},
name = "Resident",
tooltip=create_tooltip("INWONER"),
popup=create_popup("INWONER")
).add_to(nl_map)
household = GeoJson(
geo_data,
style_function=lambda x: {
"fillColor": colormap_hh(x["properties"]["AANTAL_HH"])
if x["properties"]["AANTAL_HH"] is not None
else "transparent",
"color": "black",
"fillOpacity": 0.4,
},
name = "Household",
tooltip=create_tooltip("AANTAL_HH"),
popup=create_popup("AANTAL_HH")
).add_to(nl_map)