New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
style_callback param for add_geojson() not working? #119
Comments
Thanks for reporting. This bug has been fixed. It was caused by the default import leafmap
m = leafmap.Map(center=[0, 0], zoom=2, height="400px")
in_geojson = 'https://raw.githubusercontent.com/telegeography/www.submarinecablemap.com/master/web/public/api/v3/cable/cable-geo.json'
callback = lambda feat: {"color": feat["properties"]["color"]}
m.add_geojson(in_geojson, layer_name="Cable lines", style_callback=callback)
m |
Thank you!! BTW, I see the same issue with geemap 0.9.2, where it seems to work for |
Yes, please. Thanks. |
I've tested this in 0.6.0 with import random
import leafmap
import geopandas as gpd
m = leafmap.Map(center=[20, 0], zoom=1)
gdf = gpd.read_file('https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/cable-geo.geojson')
m.add_gdf(gdf,
style_callback=lambda feat: {"color": random.choice(["red", "green", "black"])}
)
m |
The function has a import random
import leafmap
import geopandas as gpd
m = leafmap.Map(center=[20, 0], zoom=1)
gdf = gpd.read_file('https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/countries.geojson')
m.add_gdf(gdf,
fill_colors = ["red", "green", "black"])
m |
Thanks! I'm using the random colors only to keep the snippet short, but I'm more interested in a general callback that has access to the individual geo dataframe rows like the GeoJSON variant can access single features. |
@deeplook This bug has been fixed. Please update the package and have a try. |
Awesome, thanks! In the meantime I've found an easy workaround, at least in cases like this: import random
import leafmap
import geopandas as gpd
m = leafmap.Map(center=[20, 0], zoom=1)
gdf = gpd.read_file('https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/cable-geo.geojson')
m.add_geojson(gdf.geometry.__geo_interface__, # convert to GeoJSON!
style_callback=lambda feat: {"color": random.choice(["red", "green", "black"])}
)
m |
Environment Information
Description
I want to use the
style_callback
parameter formap.add_geojson()
, but the chosen style which sets only the color seems not to be respected. I think the style dicts are the same for ipyleaflet and leafmap, at least I could not find any contradictory information. See below.The text was updated successfully, but these errors were encountered: