opengeos/leafmap

Styles are not working with streamlit

amjadraza opened this issue · 3 comments

Environment Information

  • leafmap version: lates
  • Python version: 3.11
  • Operating System: Linux

Description

The Color Styles are not working with streamlit UI. I have followed below two approaches

1- Using m.add_gdf(gdf, layer_name = "ABD", style_callback= lambda feature: style_function_custom(feature, "f1"))
2. Converting GDF to GeoJSON and Adding Explicit properties of color for each feature into feature collection

Looks like, m.to_streamlit is not handling the Polygone colors.

Can you provide a complete example that can reproduce the issue?

The parameter is style_function. See the example below.

import streamlit as st
import geopandas as gpd
import leafmap.foliumap as leafmap

m = leafmap.Map(location=[45.5236, -122.6750], zoom_start=13)
gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
# Define a style function that takes a feature and returns a style dictionary
def style_function(feature):
    return {
        'fillColor': '#228B22' if feature['properties']['pop_est'] < 10000000 else '#FF0000',
        'color': 'black',
        'weight': 2,
        'dashArray': '5, 5',
        'fillOpacity': 0.7,
    }
m.add_gdf(gdf, style_function=style_function)
m.to_streamlit()

@giswqs thanks, above example is working. Let me try my example, will report back if any issues.