2

I am using the OpenLayers v4.6.5 Draw interaction.

drawInteraction = new ol.interaction.Draw({...});
map.addInteraction(drawInteraction);

I want users to be able to add properties to the features they draw so use the drawend event to display a form.

drawInteraction.on('drawend', function(e) {...}).

This all works fine.

However, an issue that arises is that, when drawing polygons, users sometimes complete polygons without intending to (for example by clicking within the snap distance of the start point or clicking too fast so triggering a double click event). On simple polygons they can easily cancel and start again, but many of our polygons are complex.

I wondered if there is a way, once the form is displayed, of undoing their last click and cancelling the completion of the geometry? I imagine them clicking an "Undo last click" button on the form and just carrying on with drawing their polygon. I have explored removeLastPoint (but this seems to have no effect once the drawing has finished) and finishCondition (but cannot see how to use it achieve what I want).

Users are able to modify their incorrect polygons to get them to be what they want, so it is not a huge issue. I understand I could make it harder for them to accidentally complete their polygons, by changing snap distances etc.

But an undo functionality would make it more intuitive for them. How can it be done?

4
  • 3
    finishCondition: function(event) { return confirm("Are you sure?"); } works for me.
    – Mike
    Commented Feb 11, 2019 at 10:50
  • 1
    @Mike Put your comment into answer.
    – TomazicM
    Commented Feb 11, 2019 at 17:05
  • @PeterCooper You should mark answer from Mike as accepted.
    – TomazicM
    Commented Feb 12, 2019 at 18:57
  • @TomazicM Have done. I did look for how to do that yesterday, but could not see it. Googling how showed me - obvious now I know. Commented Feb 13, 2019 at 6:12

1 Answer 1

4

finishCondition: function(event) { return confirm("Are you sure?"); } works for me.

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.