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));
meetar
  • 7,443
  • 8
  • 42
  • 73
Kalashir
  • 1,099
  • 4
  • 15
  • 38

2 Answers2

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.

meetar
  • 7,443
  • 8
  • 42
  • 73
AKA
  • 318
  • 3
  • 15
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
});