Skip to content

Error when using fill pattern to style GeoJson #274

@cvogel17

Description

@cvogel17

I have a map where I want to display a GeoJson, which works correctly. I want to style the GeoJson such that there is a fill pattern, e.g. a stripe pattern. If I do so, the map is shown, but the GeoJson is not rendered any longer.

A minimal example is the following:

import requests
import folium

from streamlit_folium import st_folium

m = folium.Map([40.0, -105.0], zoom_start=6)

stripes = folium.plugins.pattern.StripePattern(angle=-45).add_to(m)

circles = folium.plugins.pattern.CirclePattern(
    width=20, height=20, radius=5, fill_opacity=0.5, opacity=1
).add_to(m)


def style_function(feature):
    default_style = {
        "opacity": 1.0,
        "fillColor": "#ffff00",
        "color": "black",
        "weight": 2,
    }

    if feature["properties"]["name"] == "Colorado":
        default_style["fillPattern"] = stripes
        default_style["fillOpacity"] = 1.0

    if feature["properties"]["name"] == "Utah":
        default_style["fillPattern"] = circles
        default_style["fillOpacity"] = 1.0

    return default_style

us_states = requests.get(
    "https://raw.githubusercontent.com/python-visualization/folium-example-data/main/us_states.json"
).json()

folium.GeoJson(
    us_states,
    smooth_factor=0.5,
    style_function=style_function,
).add_to(m)

st_folium(m, width=725)

If I look at the console in the browser, I can see the following error:

Image

The package versions I used are:

  • streamlit, version 1.47.1
  • streamlit-folium, version 0.25.3
  • folium, version 0.20.0

Is this a bug or am I doing something wrong? Thank you for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions