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?

  • 3
    finishCondition: function(event) { return confirm("Are you sure?"); } works for me. – Mike Feb 11 at 10:50
  • 1
    @Mike Put your comment into answer. – TomazicM Feb 11 at 17:05
  • @PeterCooper You should mark answer from Mike as accepted. – TomazicM Feb 12 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. – Peter Cooper Feb 13 at 6:12
2

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, privacy policy and cookie policy

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