Skip to content

Empty geojson data fails when combined with a style_function #1212

@agussman

Description

@agussman

Please add a code sample or a nbviewer link, copy-pastable if possible

This works fine:

geo_json_data = """
{
  "type": "FeatureCollection",
  "features": []
}

m = folium.Map([43, -100], zoom_start=4)

folium.GeoJson(
    geo_json_data
).add_to(m)

m

But this does not:

geo_json_data = """
{
  "type": "FeatureCollection",
  "features": []
}

m = folium.Map([43, -100], zoom_start=4)

folium.GeoJson(
    geo_json_data,
    style_function=lambda feature: {
        'fillColor': '#ffff00',
        'color': 'black',
        'weight': 2,
        'dashArray': '5, 5'
    }
).add_to(m)

m
"""

Problem description

Sometimes a user ends up attempting to plot empty GeoJson (e.g., it came from an API response with no results).

Normally this works, but will fail if you use it in conjunction with a style_function .

Expected Output

I would expect to see an empty plot even when attempting to plot an empty GeoJson.

Output of folium.__version__

0.10.0+2.g60ae79c.dirty

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