React-leaflet popup - Open specific popup by clicking on an option outside the map

881 views
Skip to first unread message

Ada Naza

unread,
Aug 31, 2022, 2:46:31 AM8/31/22
to Leaflet
I have a problem and I think there is a way to do this but I just haven't figured it out. I have a map with lots of markers, and I want to be able to open a specific marker by clicking an option outside the map. right now,  doing this -markerRef.current.openPopup(lat, lng), opens a random marker that isn't the one at the lng and lat i specified and I don't know why

Pat Keller

unread,
Aug 31, 2022, 10:56:45 PM8/31/22
to Leaflet
The first thing I notice is that it doesn't look like you're calling openPopup correctly. You need to pass a LatLng object and not two separate values openPopup(<LatLnglatlng?).

As for opening a specific marker, you need to store all of the marker objects or markerRefs somewhere, then find the correct item, and finally call openPopup.

Reply all
Reply to author
Forward
0 new messages