emilhe / dash-leaflet

MIT License
204 stars 33 forks source link

Add example with `LocateControl` in events #223

Open guidocioni opened 5 months ago

guidocioni commented 5 months ago

I just updated dash-leaflet to 1.x but I'm unsure how to migrate the "old" way of capturing the location provided by the geolocalization.

Before we were using location_lat_lon_acc. The migration guide says that this parameter is deprecated, yet there is no explanation on how to implement it in the new version.

I believe one has to define a custom eventHandlers as done here for MeasureControl, however it is not clear to me what are the properties one has to use in the case of LocationControl. In my case I just want to get the lat and lon determined by the geolocation into a callback.

pip-install-python commented 4 months ago

dl.LocateControl(locateOptions={"enableHighAccuracy": True}) # add to the children of dl.Map

or if you are trying to find lat and lon on map click: @dash.callback(Output("layer", "children"), [Input("map", "clickData")]) def map_click(click_lat_lng): print('checking map_click') print(click_lat_lng['latlng']) if click_lat_lng is not None: return [dl.Marker(position=[click_lat_lng['latlng']['lat'], click_lat_lng['latlng']['lng']], children=dl.Tooltip("Chosen 🗺 Location: ({:.5f}, {:.5f})".format(click_lat_lng['latlng']['lat'], click_lat_lng['latlng']['lng'])), icon={'iconUrl': 'https://cdn-icons-png.flaticon.com/512/1072/1072582.png', 'iconRetinaUrl': 'https://cdn-icons-png.flaticon.com/512/1072/1072582.png', 'iconSize': [40, 40], 'iconAnchor': [12, 12], 'popupAnchor': [0, -12], 'shadowUrl': None, 'shadowSize': None, 'shadowAnchor': None})]

Not exactly based on routing a LocationControl through a callback but I figured it might be helpful context.