Search code examples
leafletleaflet-geoman

Leaflet geoman setLatLngs not restoring object to the getLatLngs position


I have an issue that when leaflet geoman removes a vertex on for example polygon, I cannot restore the latLngs of the object.

What im doing: On object click -> object.getLatLngs(). Works fine.

If I start editing the object and then object.setLatLngs(ObjectClickLatLngs) it works fine.

But the issue is: Click object -> start editing -> Right click vertex(to delete vertex) -> object.setLatLngs(ObjectclickLatLngs). Now the vertex is deleted and did not restore to the latLngs it had previously.

Try to click the polygon, change a vertex then click "restore object to initial position" (works as expected) Then click the polygon, but right click a vertex(to delete) without moving it then click "restore object to initial position" (now the object is not in the state it should be, expected it to restore to same position as initial)

https://jsfiddle.net/6tzxg2ds/2/


Solution

  • The Problem is that JavaScript refrence the variable to the source, so when the latlng of the layer is changed, then the restoreLatLngs is also updated.

    You can "destroy" the refrence with this:

    restoreLatLngs = JSON.parse(JSON.stringify(x.target.getLatLngs()));