3

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?

2

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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