emilhe / dash-leaflet

MIT License
213 stars 39 forks source link

Error L.CRS is undefined #175

Closed Lawiss closed 1 year ago

Lawiss commented 1 year ago

Hello,

I am trying to plot markers on map using dash-leaflet v0.1.25rc1. The problem is that i get a Javascript error "L.CRS is undefined". The code that generate the map is :

res_div = html.Div(
        [
            dl.Map(
                [
                    dl.TileLayer(),
                    dl.GeoJSON(url="/assets/data/data_geojson.json", zoomToBounds=True),
                ],
            ),
        ]
    )

I verified the geojson file and it is fine, i've also tested (https://github.com/openlayers/openlayers/blob/main/examples/data/geojson/point-samples.geojson)[another geojson] without success. I am missing something ?

emilhe commented 1 year ago

No, I think the code looks OK. Do you get the same error if you use the data from the docs?

Otherwise, one guess might be due to the crs entry in the data,

"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" }

Lawiss commented 1 year ago

I tried with the snippet in the doc :

points = [
        dict(
            lat=55.5 + random.random(), lon=9.5 + random.random(), value=random.random()
        )
        for i in range(100)
    ]
    data = dlx.dicts_to_geojson(points)
    res_div = html.Div(
        [
            dl.Map(
                [
                    dl.TileLayer(),
                    dl.GeoJSON(data=data, zoomToBounds=True),
                ],
            ),
        ]
    )

But the error remains. Same if I delete the "crs" key of the geojson. Maybe it is a problem with my python env :

My python env ``` Package Version ------------------------ --------- aiofiles 0.8.0 aiosqlite 0.17.0 anyio 3.6.2 appnope 0.1.3 argon2-cffi 21.3.0 argon2-cffi-bindings 21.2.0 arrow 1.2.3 asttokens 2.2.1 async-lru 2.0.2 attrs 22.2.0 Babel 2.11.0 backcall 0.2.0 beautifulsoup4 4.11.2 black 23.1.0 bleach 6.0.0 Brotli 1.0.9 cachelib 0.9.0 certifi 2022.12.7 cffi 1.15.1 charset-normalizer 3.0.1 click 8.1.3 click-default-group 1.2.2 comm 0.1.2 connectorx 0.3.2a2 dash 2.8.1 dash-core-components 2.0.0 dash-extensions 0.1.14rc1 dash-html-components 2.0.0 dash-leaflet 0.1.25rc1 dash-table 5.0.0 debugpy 1.6.6 decorator 5.1.1 defusedxml 0.7.1 EditorConfig 0.12.3 entrypoints 0.4 executing 1.2.0 fastjsonschema 2.16.2 feffery-antd-components 0.1.16 Flask 2.2.3 Flask-Caching 2.0.2 Flask-Compress 1.12 fqdn 1.5.1 geobuf 1.1.1 gunicorn 20.1.0 idna 3.4 ipykernel 6.21.2 ipython 8.10.0 ipython-genutils 0.2.0 ipywidgets 8.0.4 isoduration 20.11.0 itsdangerous 2.1.2 jedi 0.18.2 Jinja2 3.1.2 jsbeautifier 1.14.7 json5 0.9.11 jsonpointer 2.3 jsonschema 4.17.3 jupyter 1.0.0 jupyter_client 8.0.3 jupyter-console 6.6.1 jupyter_core 5.2.0 jupyter-events 0.6.3 jupyter-lsp 1.5.1 jupyter_server 2.3.0 jupyter_server_terminals 0.4.4 jupyter-ydoc 0.1.10 jupyterlab 4.0.0a34 jupyterlab-pygments 0.2.2 jupyterlab_server 2.19.0 jupyterlab-widgets 3.0.5 kaleido 0.2.1 MarkupSafe 2.1.2 matplotlib-inline 0.1.6 memory-profiler 0.60.0 mistune 2.0.5 more-itertools 9.1.0 mypy-extensions 1.0.0 nbclient 0.7.2 nbconvert 7.2.9 nbformat 5.7.3 nest-asyncio 1.5.6 notebook 7.0.0a13 notebook_shim 0.2.2 numpy 1.24.2 packaging 23.0 pandas 2.0.0rc0 pandocfilters 1.5.0 parso 0.8.3 pathspec 0.11.0 pexpect 4.8.0 pickleshare 0.7.5 pip 22.1.2 platformdirs 3.0.0 plotly 5.13.1 polars 0.16.9 profiling 0.1.3 prometheus-client 0.16.0 prompt-toolkit 3.0.37 protobuf 3.19.0 psutil 5.9.4 psycopg2-binary 2.9.5 ptyprocess 0.7.0 pure-eval 0.2.2 pyarrow 11.0.0 pycparser 2.21 Pygments 2.14.0 pyparsing 3.0.9 pyrsistent 0.19.3 python-dateutil 2.8.2 python-dotenv 1.0.0 python-json-logger 2.0.7 pytz 2022.7.1 PyYAML 6.0 pyzmq 25.0.0 qtconsole 5.4.0 QtPy 2.3.0 requests 2.28.2 rfc3339-validator 0.1.4 rfc3986-validator 0.1.1 Send2Trash 1.8.1b0 setuptools 67.6.0 six 1.16.0 sniffio 1.3.0 soupsieve 2.4 SQLAlchemy 1.4.46 stack-data 0.6.2 tenacity 8.2.2 terminado 0.17.1 tinycss2 1.2.1 tomli 2.0.1 tornado 6.2 traitlets 5.9.0 typing_extensions 4.5.0 uri-template 1.2.0 urllib3 1.26.14 urwid 2.1.2 valuedispatch 0.0.1 wcwidth 0.2.6 webcolors 1.12 webencodings 0.5.1 websocket-client 1.5.1 Werkzeug 2.2.3 wheel 0.37.1 widgetsnbextension 4.0.5 y-py 0.5.2 ypy-websocket 0.1.13 ``` ```
emilhe commented 1 year ago

Could you try the 0.1.23 release? It sounds like a problem with the environment - or a problem with the dash-leaflet build

Lawiss commented 1 year ago

The error remains also with 0.1.23 release (I had to downgrade protobuf to 3.18.3 to make it work). I tried downgrading also dash to 2.6 without success. Maybe it is a problem of python version ? My env is currently using python 3.10.

Lawiss commented 1 year ago

After investigating, I found that the issue is from a js package I'm using which visibly interfere with dash-leaflet : https://github.com/GouvernementFR/dsfr (it's the design system of french government). I am not a JS/React expert so I have not yet found the root cause of this "interference" but when I delete the dsfr package, the leaflet map work properly.