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

dynamically changing pmIgnore isn't properly handled #1017

Closed EXio4 closed 2 years ago

EXio4 commented 2 years ago

If you dynamically change pmIgnore using the method provided by https://github.com/geoman-io/leaflet-geoman#getting-started - things like edit/drag mode/anything relying on findLayers aren't properly tracked, so you are left with a situation where the "state" of the map isn't exactly representative of what the functions meant (or intuitively represent)

A way to trigger the issue is to:

JSFiddle showing the issue: https://jsfiddle.net/exio4/7qba46ch/

Falke-Design commented 2 years ago

Yes but here is the problem, that we don't get a information from leaflet when the style is changed, so we can't implement anything that listen on that and automatically change the "map state".

A workaround is to call toggleGlobalEditMode() twice:

const switchPm = (poly) => {
    console.log(poly)
    poly.setStyle({ pmIgnore: !poly.options.pmIgnore })
    L.PM.reInitLayer(poly)
    map.pm.toggleGlobalEditMode() // disable mode
    map.pm.toggleGlobalEditMode() // renable mode
}