17

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.
jdelman
  • 683
  • 1
  • 6
  • 20

1 Answers1

25

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.

tmcw
  • 11,536
  • 3
  • 36
  • 45