Using React-Leaflet V3.1.0 with an Express server.
My users have requested the ability to use a link in the following format:
https://www.mymap.com/id/:category/:id/:zoom
This sends a request to the server to get the lat/lon coordinates of the marker they're linking to and then sets the start location to those coordinates. I've managed to get this part working using React Router Dom. Now ideally, I would like to be able to have the popup for this particular marker opened upon map load. With the way I have the query component setup, it's not a problem to be able to pass a boolean value through props while generating the markers to indicate that this is the marker of interest, I'm just not sure how to activate the popup.
I'm not very familiar with useRef and how it can be used exactly to access the different Leaflet methods but I did some experiments yesterday and was able to get some behavior that seems to be a step in the right direction. The popups didn't load on initial startup but as I navigated around the map, other popups started opening automatically. That being said, my map renders thousands of markers and going beyond 1 render per marker isn't going to be worth the trade off of this relatively niche feature, unless a second render can be isolated to only the marker of interest.
The method that I think would get me to where I want but I couldn't get this specific one to fire: https://leafletjs.com/reference-1.6.0.html#popup-openon
I ended up using openPopup()
similar to this link:
https://stackblitz.com/edit/react-awtgn6?file=Map.js
But I was only able to get that to somewhat (results mentioned above) work with a useEffect + useRef.
I feel like I'm missing something obvious when it comes to storing the popup open status in state?
Basic code example:
<Marker
position={[item.lat, item.lon]}
icon={getIcon(item)}
>
<Popup position={[item.lat, item.lon]}>
<PopupContent
item={item}
userSettings={userSettings}
/>
</Popup>
</Marker>
Thank you!