I have a vector layer in OL3 which I want to auto clear when drawing a Point feature (which means there is always max 1 feature in the layer).
Problem is that when I listen to drawstart (ol.interaction.draw) or to featureadd (ol.layer.vector) they are fired after feature is added and thus I can't clear the layer without them be deleted.
how can I workaround this ?
* Edit *
I've noticed the drawstart event work when the draw type isn't Point , but I want to add points and thus my problem.
Best Answer
Points are a bit tricky because the
drawstart
anddrawend
events are driven from the same mouse click. To support all geometry types, have a look at the sample code below.If you only ever need to support the
ol.geom.Point
type, then just use thedrawend
event and don't worry about the rest.Sample Code
jsFiddle
See a complete example here that handles all geometry types: https://jsfiddle.net/abb54n79/1/