I have a draw interaction in Openlayers 4.

I'm using it to draw polygons. I would like to continue drawing the polygon if its area is less than a default value.

I tried using the property finishCondition, but it takes an ol.MapBrowserEvent and feature is not accesible.

finishCondition(event) { /* return (true or false) based on feature */ }

It seems that the event is fired before feature is added to the source so I can't take the feature from the source.

Is there any way to do this?

1 Answer 1


Not sure if this is the best solution:

I created a variable whichs points to the feature being drawn:

new ol.interaction.Draw({
      stopClick: true,
      finishCondition: (event) => {
        const area = ol.Sphere.getArea(geomDrawn)
        const [minArea, maxArea] = [20*20, 1500*1500]
        return area > minArea && area < maxArea

And getting the geom from feature change event:

onDrawStart(event) {

  const { feature } = event

  this.listenerDraw = feature.getGeometry().on('change', event => {
    const geom = event.target        
    geomDrawn = geom

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.