Skip to content

Unable to use GeoData style_callback #785

Open
@deeplook

Description

@deeplook

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions