I'm pretty new to leaflet.js and I'm trying to figure out how to assign the same map with the same set of options and layers to a different HTML container instead of having to remove and add a new one every time?

I used to deal with OpenLayers 2 and I had map.render(div); option every time I wanted to set map to another div.

Is there solution to this?

  • Hi Dmitry, did you get any further with this? I'm into a similar problem and curious to compare notes. FWIW I am able to 1) get the html contents of the .leaflet-map-pane class, 2) open a new window, 3) instantiate a new Leaflet map in a fresh div in my new window, then 4) use JQuery to intrusively change the html value of the .leaflet-map-pane class in the new window/div. It works, but the map is essentially "soulless", unable to drag, etc. Curious if you ended up with something better. – elrobis Feb 16 '16 at 21:17
  • Hi, @elrobis. Sorry for the delay. To solve this - I ended up destroying map every time I had to create the new one. I was able to run multiple maps at once - not a big deal, but I once I reached 8-10 maps my ionic app started crashing. I now use Angular and its Leaflet directive Angular-leaflet-directive. It does initialization and management under the hood and all you need to do is to pass some initial parameters. – Dmitry Feb 20 '16 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.