Open hyperknot opened 8 years ago
The following events are triggered when I call editTools.stopDrawing()
with a 2 vertex polygon:
endDrawing
only deletes the current drawn shape if invalid, but does not take care of removing the feature from the map.
Maybe this can be added in case the feature is without any shape after that, but I'm not even sure it's to be added as default behaviour. We may think at some use cases where someone would want to do something else in such case. I need to think a bit more on that.
One way to solve the issue for you is to listen for editable:drawing:cancel
event, and control here the state of the feature.
So far the best solution I found is to check for e.layer._defaultShape()
in editable:drawing:end
, as by this time this will be an empty array if the shape was invalid.
m.Lmap.editTools.on('editable:drawing:end', function(e) {
if (!e.layer._defaultShape().length) {
console.log('removing layer');
featuregroup.removeLayer(e.layer);
return;
}
// do rest of processing
});
I just found that Measurable has pretty much the exact same solution implemented: https://github.com/umap-project/Leaflet.Measurable/blob/52d56e758e34e2761be4c8c878abe042eed37c62/Leaflet.Measurable.js#L116
At the moment, if the user starts to draw a geometry, and stops while it's not complete, by triggering
stopDrawing()
, the incomplete feature is saved to the feature layer, no matter if it is valid or invalid. (By invalid I mean having MIN_VERTEX vertices.)I believe
endDrawing()
should be removing it, but somehow withstopDrawing()
,endDrawing()
isn't called.