draw用来画要素,可以选点、线、面;使用select将要素选中以后,使用modify修改要素。
ol/interaction/Draw
添加Draw工具
import { Vector as VectorSource } from 'ol/source'
import { Vector as VectorLayer } from 'ol/layer'
import Draw from 'ol/interaction/Draw'
this.source = new VectorSource()
this.vector = new VectorLayer({
source: this.source
})
this.map.addLayer(this.vector)
this.draw = new Draw({
source: this.source,
type: 'Point'
})
this.map.addInteraction(this.draw)
改变绘制的要素种类
需要先从map
中移除已经添加的draw
,再新建一个新的类型的draw
,添加到map
里。
this.map.removeInteraction(this.draw);
this.draw = new Draw({
source: this.source,
type: 'Polygon'
});
this.map.addInteraction(this.draw);
https://openlayers.org/en/latest/apidoc/module-ol_interaction_Draw-Draw.html
https://openlayers.org/en/latest/apidoc/module-ol_interaction_Modify-Modify.html