ipyleaflet icon indicating copy to clipboard operation
ipyleaflet copied to clipboard

Unable to use GeoData style_callback

Open deeplook opened this issue 4 years ago • 1 comments

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 avatar Feb 03 '21 08:02 deeplook

@martinRenou Any idea?

deeplook avatar Feb 15 '21 10:02 deeplook