Openlayers: 'singleclick' events fired during draw interaction

Created on 29 Nov 2017  路  2Comments  路  Source: openlayers/openlayers

Hello,

I'm listening for the singleclick event on the map in order to place a "pinned location" overlay on the map. However, I noticed that during a draw interaction, the singleclick event is still fired (or not swallowed), which results in some odd behavior for me: a pin gets dropped on the map at each singleclick event of the draw interaction.

You can check it out here: https://codepen.io/anon/pen/VrVwJj (be sure to open the console)

Admittedly, I can jump through hoops to look for any active draw interactions before proceeding, but this causes some of it's own issues when you consider that a completed draw interaction is no longer present by the time the last singleclick fires. I'm happy to go into more detail if needed.

My request, or question, is: is there a way to prevent the singleclick event from firing during a draw interaction?

It seems to me that one wouldn't need that event during a draw interaction, but I'm fully aware of my own ignorance, so perhaps an option could be passed into the interaction to swallow events:

stopPropagation: true

Thank you for your consideration

Most helpful comment

The draw interaction now takes a stopClick option (false by default). Setting this to true will stop click, singleclick, and doubleclick from firing while drawing. We can revisit the default in the next major release (note that this is different than normal behavior in browsers where you cannot stop a click with preventDefault or stopPropagation on mouseup or previous events).

All 2 comments

I think, as manually, you can set drawstart, drawend event on ol.interaction.Draw to remove and add singleclick event. https://codepen.io/anon/pen/wPQpNQ
or you can wait for #7526. maybe it's related?

The draw interaction now takes a stopClick option (false by default). Setting this to true will stop click, singleclick, and doubleclick from firing while drawing. We can revisit the default in the next major release (note that this is different than normal behavior in browsers where you cannot stop a click with preventDefault or stopPropagation on mouseup or previous events).

Was this page helpful?
0 / 5 - 0 ratings