emilhe / dash-leaflet

MIT License
204 stars 33 forks source link

`click_lat_lng` not working in latest version #214

Closed IansGithubAcc closed 8 months ago

IansGithubAcc commented 8 months ago

It looks like the click_lat_lng property is simply not firing when clicking on the map. Also when debugging, I simply to not get into the callback.

This did use to work with an older version (I think an older version of Dash). But I did a clean pip install of dash-leaflet and dash and the problem remains.

I've made a really simple app to replicate the issue:

import dash_leaflet as dl
from dash import Dash, html, Input, Output

app = Dash(__name__)
app.layout = html.Div(
    [
        dl.Map(
            id="map",
            children=[
                dl.TileLayer(id="tile-layer"),
                dl.LayerGroup(id="layer-group"),
            ],
            style={"height": "90vh"},
            center=[50, 0],
            zoom=3,
        )
    ]
)

@app.callback(
    Output("layer-group", "children"),
    Input("map", "click_lat_lng"),
    prevent_initial_call=True,
)
def map_click(click_lat_lng):
    lat, lon = click_lat_lng
    marker = [
        dl.Marker(
            position=(lon, lat),
            children=dl.Tooltip("({:.3f}, {:.3f})".format(*click_lat_lng)),
        )
    ]
    return marker

Furthermore, I found this post on stackexchange that seems to suggest this is an issue with as well: https://gis.stackexchange.com/questions/465640/click-feature-doesnt-work-dash-leaflet

Lastly, I have found that with this latest version of that the map does not render unless I provide a center and a zoom. If I leave these values to default, then I do not see the map. This is however a different issue.

IansGithubAcc commented 8 months ago

I just found out that the function has been deprecated. An error would have been useful here.

Map: The click_lat_lng/dbl_click_lat_lng prop have been dropped in favor of clickData/dblclickData

https://www.dash-leaflet.com/docs/migration