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?

1 Answer 1


You can use something like this -

var features = vectorSource.getFeatures();
var lastFeature = features[features.length - 1];

Note that you need to vectorSource.getFeatures() every time you want to remove the last feature or use it in a function.

  • Hey this works great for me. DO you any idea about redo that feature again. Commented Sep 20, 2018 at 11:41
  • 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. Commented Sep 21, 2018 at 10:32
  • this removeFeatures actually deletes feature, so on that index we get undefined value. Commented Sep 21, 2018 at 11:30
  • Oh. Clone the feature then? var cloneFeature = lastFeature.clone(); Commented Sep 21, 2018 at 11:44

Your Answer

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

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