简体   繁体   中英

Click event handling for draw features in Openlayers 3`

I have implemented the following example from the Openlayers 3 library where you can measure lines and areas.

http://openlayers.org/en/latest/examples/measure.html

Specifically for areas, to complete the shape you can either double click at the last vertex you want to draw, or single click back at the start of the shape when the cursor snaps to the original point.

I have an issue whereby many users are taking their cursor back to the original point and it is snapping, but they are double clicking thinking therefore completing the original shape and inadvertently starting a new one.

How am I able to code this example so that if a double click occurs at the original point, then the shape is completed but a new shape not started?

Thanks

You can set property snapTolerance into 1, it should help:

new ol.interaction.Draw( { snapTolerance: 1, ...

You still can finish shape with single click, but you have to click exactly in the first point.

I set snapTolerance for myself some time before and people are happy now :).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM