A previous developer created a map using Leaflet on the page. The Javascript is very complex and I cannot find where the Leaflet map is instantiated. However, I know which DOM element is associated with the map. Is there any way to get the Leaflet map object from the id of the element?
I.e., the element id is #city-map. L.map('city-map') returns
Error: Map container is already initialized.
Adding a Simple Marker Step 1 − Create a Map object by passing a <div> element (String or object) and map options (optional). Step 2 − Create a Layer object by passing the URL of the desired tile. Step 3 − Add the layer object to the map using the addLayer() method of the Map class.
No: Leaflet does not set a reference back to the map object from the DOM element, because that can easily cause memory leaks. And L.map
always creates a new map - it does not find a map like you might expect coming from jQuery. You'll need to decipher the code from your other developer and find the variable the map is assigned to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With