jupyter-widgets / ipyleaflet

A Jupyter - Leaflet.js bridge
https://ipyleaflet.readthedocs.io
MIT License
1.47k stars 359 forks source link

Close Markers in MarkerClusters: the "coordinates" of an on_click event may not the ones of the marker initially created #1207

Open jmp75 opened 4 weeks ago

jmp75 commented 4 weeks ago

Context

I have a component built upon ipyleaflet to streamline the interactive exploration of geo-located data in xarray.

This worked on the assumption that an on_click event on a Marker would contain the exact geo-coordinates at which the Marker was created. However if some markers are geographically very close, and perhaps because MarkerCluster is used, this fails to work.

Example

I have ~1500 points with streamflow monitoring sites:

image

zoming in on to most area, markers "ungroup" as expected, and clicking on each marker triggers a successful action based on the click lat/lon information.

Zooming in on to a location (the Marne river in South Australia, not the one in Europe :smile: ...), a cluster persists even at maximum zoom:

image

clicking on the cluster "opens" it

image

but then clicking on one of the icon triggers a KeyError: (-34.67698205588844, 139.24381256103518) as coordinates are not exactly the same as expected: [((-34.6743, 139.2319), 'A4260529'), ((-34.6741, 139.2317), 'A4260605')]

Related links

More details in https://github.com/jmp75/ipyleaflet-dashboard-tools/issues/2

One workaround may be to not use MarkerCluster as in ipyleaflet issue #498 . But I'd like to keep MarkerCluster and find another way to circumvent this issue.