Reputation: 5917
I have a mapbox map at http://bei.dev.bclcmaps.com/ which has popups that open when clicking a marker.
My problem is that I need a way to set a default popup to be open on page load based on a value in the URL. This can be a latitude and longitude or some other value, whatever's easiest.
I have banged on this for a while and it seems like I either need to:
I've tried this:
map.gridLayer.fire('click', {latLng: L.latLng(28.04419, -81.947864)});
which closes any existing open popups but doesn't seem to open its own. I've also tried digging through the map and the leaflet objects to see if location/marker data is stored in there and I can't find anything besides the tiles.
Most of the examples I can find seem to be using GeoJSON which I'm not using so that makes things difficult.
Any advice?
Upvotes: 2
Views: 6577
Reputation: 2955
For mapbox gl you can currently use
map.fire('click', [-118.3214,34.0318])
but it may be deprecated in the future https://github.com/mapbox/mapbox-gl-js/blob/master/CHANGELOG.md#0450
Upvotes: 1
Reputation: 186
map.fireEvent('click', {latlng: L.latLng(28.04419, -81.947864)});
You were close - the 'click' event needs a latLng object named 'latlng' (lower case)
Upvotes: 3