7

When a draw:editvertex event fires, how can I get information about the polygon which triggered it?

this.map.on('draw:editvertex', function (e) { debugger;
    var layers = e.layers;
    // I want to get current polygon latLng here
}.bind(this));

2 Answers 2

3

This approach works for me (but doesn't feel like best practice) –

In my draw:editvertex handler I loop through the target._layers and look for the edited property:

map.on('draw:editvertex', function(e) {
    for (thisLayer in e.target._layers) {
        if (e.target._layers.hasOwnProperty(thisLayer)) {
            if (e.target._layers[thisLayer].hasOwnProperty("edited")) {
                console.log("we think we found the polygon?");
                console.log(e.target._layers[thisLayer]);

                // the updated Polygon array points are here:
                newPolyLatLngArray = e.target._layers[thisLayer].editing.latlngs[0];
            }
        }
    };
});

...like I said, this doesn't feel Awesome, but it is working for me so far.

1

There are not only layers in e, but also the target layer poly can be approached easily.

map.on('draw:editvertex', function (e) { 
  var poly = e.poly;
  var latlngs = poly.getLatLngs(); // here the polygon latlngs
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.