vuelayers icon indicating copy to clipboard operation
vuelayers copied to clipboard

Access feature in drawFinsihCondition?

Open iboates opened this issue 3 years ago • 1 comments

How can I access the geometry of the feature just drawn in a :raw-finish-condition function?

I have a draw interaction:

      <vl-interaction-draw
        v-if="isDraw"
        :active="isDrawOrModify"
        :source="activeLayerIdent"
        :type="activeLayerType"
        :finish-condition="drawFinishCondition"
        @drawend="handleDrawFeature"
      />

And the method:

    drawFinishCondition(e) {

      if (["demander", "producer"].includes(this.activeLayerIdent)) {
        let clickPoint = point(e.coordinate);
        for (const feature of this.restrictedAreaCollection.features) {
          if (booleanContains(feature, clickPoint)) {
            return false
          }
        }
      } else if (this.activeLayerIdent === "restrictedArea") {
        console.log(e);
      }

      return true
    },

If this.activeLayerIdent === "restrictedArea", then I am unable to get the geometry of the just-drawn feature from e. I need to check it against some other data to see if it is valid before allowing it to be drawn. How can I do this?

iboates avatar Sep 21 '22 12:09 iboates

Hello @iboates , you can store a ref to the current drawing ol/Feature instance in drawstart event.

<vl-interaction-draw @drawstart="onDrawStart" />

onDrawStart (evt) {
  this.drawingFeature = evt.feature // instance of ol/Feature
}

Then in the finish condition callback you can access current drawing feature geometry via getGeometry() method. https://openlayers.org/en/v6.15.1/apidoc/module-ol_Feature-Feature.html#getGeometry Take a note that openlayers geometry objects will have coordinates in map view projection (EPSG:3857 by default)

ghettovoice avatar Sep 29 '22 13:09 ghettovoice

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Oct 30 '22 03:10 github-actions[bot]