geoman-io / leaflet-geoman

🍂🗺️ The most powerful leaflet plugin for drawing and editing geometry layers
https://geoman.io
MIT License
2.21k stars 433 forks source link

Instantiate L.PM after L.Map creation #636

Closed fpuga closed 3 years ago

fpuga commented 4 years ago

In my application the edition is something that happens from time to time, so there is no need to have the css and js of geoman loaded from the beginning.

I try to dynamically import the css and js after an user event (button click), but in the form that L.PM is initialized and adds the hooks to Leaflet objects this is not possible.

Doing something like:

loadGeoman().then(function() {
    L.PM.initialize({optIn: true});
    map.pm = new L.PM.Map(map);
});

does not work either as a lot of errors appears in the console when using the tools, like:

leaflet-geoman.min.js:1 Uncaught TypeError: Cannot read property 'enable' of undefined
    at NewClass._createMarker (leaflet-geoman.min.js:1)
    at NewClass.fire (Events.js:190)
    at NewClass._fireDOMEvent (Map.js:1439)
    at NewClass._handleDOMEvent (Map.js:1396)
    at HTMLDivElement.handler (DomEvent.js:79)

Probably this is also related with the solutions proposed to #516

Falke-Design commented 4 years ago

Yes this is a known problem. There is already a PR #596 but this code changes needs a precise review.