emilhe / dash-leaflet

MIT License
204 stars 33 forks source link

dl.GeoJSON won't load data from string #206

Open KS-HTK opened 9 months ago

KS-HTK commented 9 months ago

According to the doc the data attribute may be string or dict but when trying to use a string it won't load. It will however load when using a geojson object.

Minimal example:

from dash import Dash
import dash_leaflet as dl
import geojson

gj = geojson.FeatureCollection([geojson.Feature(geometry=geojson.Point((42, 7)))])

app = Dash()
app.layout = dl.Map(
        dl.GeoJSON(
            data=geojson.dumps(gj),
        ),
    style={'height': '50vh'}, center=[7, 42], zoom=6)

if __name__ == '__main__':
    app.run_server()

There is no marker in the middle of the map. If removing geojson.dumps, however, it works. I would expect it to work from a string or the geojson object.

emilhe commented 8 months ago

I'd consider that a bug on the type definition. I'll correct it (to now allow strings) in the next release.