import VectorLayer from 'ol/layer/Vector'
import VectorSource from 'ol/source/Vector'
import Draw from 'ol/interaction/Draw';
const drawSource = new VectorSource();
const drawLayer = new VectorLayer({
????source: drawSource
});
map.addLayer(drawLayer);
var draw;
// 開始繪制多邊形
drawPolygon (type) {
? ? draw = new Draw({
? ? ? ? source: drawSource,
? ? ? ? type: type
? ? })
? ? map.addInteraction(draw);
? ? draw.on('drawend', ()? => {
? ? ? ? console.log('繪制完成');
? ? });
}
// 結(jié)束繪制
endDraw () {
? ? map.removeInteraction(draw);
}
// Point? LineString? Polygon? Circle
drawPolygon('Polygon');