I have already found Undoing last point when drawing linestring in OpenLayers 3? (with working Plunker) but it can't undo misclicks when drawing polygon. So what I want is remove last drawing.
Does anyone know how to do that?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI have already found Undoing last point when drawing linestring in OpenLayers 3? (with working Plunker) but it can't undo misclicks when drawing polygon. So what I want is remove last drawing.
Does anyone know how to do that?
You can use something like this -
var features = vectorSource.getFeatures();
var lastFeature = features[features.length - 1];
vectorSource.removeFeature(lastFeature);
Note that you need to vectorSource.getFeatures()
every time you want to remove the last feature or use it in a function.
vectorSource.addFeature(lastFeature)
should work. If you are removing multiple features and want to redo them, may be you should store the features somewhere before you remove them.
Sep 21, 2018 at 10:32