0

How can I do this in Openlayers 5 / Typescript?

Is there a way (also) to identify the drawn rectangular? There may be other features on the vector layer.

SOLUTION:

import {Draw} from 'ol/interaction';
import {createBox} from 'ol/interaction/Draw';

startDrawingRectangular() {
    const geomFunction = createBox();
    this.draw = new Draw({
        source: this.vectorLayer.getSource(),
        type: 'Circle',
        geometryFunction: geomFunction
    });
    this.map.addInteraction(this.draw);
    const that = this;
    this.draw.on('drawend', (event) => {
        that.map.removeInteraction(this.draw);
        that.savedPolygon = event.feature.getGeometry();
        that.draw = null;
    });
}
tm1701
  • 7,307
  • 17
  • 79
  • 168

1 Answers1

1

One way to get the feature just drawn

this.draw.on('drawend',(event)=>{
  this.myLatestNewFeature = event.feature;
});
Mike
  • 16,042
  • 2
  • 14
  • 30