AlexB
AlexB

Reputation: 7416

Leaflet.draw - Fire an event when edition of a circle or polygon ends?

I'm using Leaflet.draw v1.0.3

Here is my basic scenario :

I load all shapes (only polygons or circles) created previously by the user from my DB.
These shapes are editable.

However, I can't find an Edited or EditedComplete event, fired when edit ends. My goal is to get the new coordinates (radius and center if it's a circle, or lat/lng of every polygon's vertex) and store them in my DB.
Obviously, I need only one update operation, when edit process is over.

I've only found :

The event L.Draw.Event.EDITED exists but it doesn't fire when expected.

I guess these events exist, but I can't find them. I've only found this issue, and it worries me...
Any help ?

Upvotes: 1

Views: 5503

Answers (1)

Zoubir
Zoubir

Reputation: 131

I met the same issue and I fixed it by doing the following :

after creating the layer (circle / polygone ) , I added an edit listener on the created layer :

map.on(L.Draw.Event.CREATED, function(e) {
    var type = e.layerType
    , layer = e.layer;
    drawnItems.addLayer(layer);       
    layer.on("edit", function(event) {
        console.log("layer edited !");
        ..........
    });
});

You can take a look at this example :

http://jsfiddle.net/Zoubir/oer03zu4/ In order to check : Create a polygone or circle and pass to edit mode , update a radius and see

I hope this can Help

Upvotes: 4

Related Questions