I'm trying to prevent a user in edit mode from creating overlapping shapes. With a CREATED event, I can easily remove the layer. But I want to revert an edited shape back to its original position instead of removing the layer.
My code is as follows:
map.on(L.Draw.Event.EDITED, function (e) {
var layers = e.layers;
layers.eachLayer(function (layer) {
var reversedCoordinates = [], latlngs = layer.getLatLngs();
for (var i = 0; i < latlngs.length; i++)
reversedCoordinates.push([latlngs[i].lng, latlngs[i].lat]);
reversedCoordinates.push([reversedCoordinates[0][0], reversedCoordinates[0][1]]);
if (checkRectangleOverlap(reversedCoordinates)) {
//drawnItems.removeLayer(layer);
//revert the layer to its original position here
};
});
});
Could anybody help me in this regard?