jupyter-widgets / ipyleaflet

A Jupyter - Leaflet.js bridge
https://ipyleaflet.readthedocs.io
MIT License
1.47k stars 359 forks source link

Unable to use GeoData style_callback #785

Open deeplook opened 3 years ago

deeplook commented 3 years ago

GeoJSON layers have a style_callback as documented in https://ipyleaflet.readthedocs.io/en/latest/api_reference/geo_json.html, but GeoData subclasses have no such thing documented in https://ipyleaflet.readthedocs.io/en/latest/api_reference/geodata.html. That would be easy to fix, but while using such a GeoData layer I find that the callback seems not to be called or I would know which argument it is called with. A GeoJSON layer callback gets a GeoJSON feature, but for GeoData I would rather expect a row of the respective dataframe. But in https://github.com/jupyter-widgets/ipyleaflet/blob/master/ipyleaflet/leaflet.py#L1248 I see no logic to access the dataframe.

Example (showing default blueish style):

import random
import geopandas
from ipyleaflet import Map, GeoData

m = Map(center=(52, 60), zoom=3)
m += GeoData(
    geo_dataframe=geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres")),
    style_callback=lambda whatever: {"color": random.choice(["red", "green", "black"])},
)
m
Screenshot 2021-02-03 at 10 28 31
deeplook commented 3 years ago

@martinRenou Any idea?