Skip to content

Multiple GeoJsonPopup leads to Uncaught SyntaxError: Identifier 'name_getter' has already been declared #1346

Closed
@orangeluc

Description

@orangeluc

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).

image

as I got this error
image

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn issue describing unexpected or malicious behaviour

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions