我的代码目前允许用户一次创建多个多边形。我希望每次用户决定创建一个新的矢量时,它都能擦除以前的矢量。
let drawSource = new VectorSource({wrapX: false});
let drawLayer = new VectorLayer({source : drawSource,})
this.map.addLayer(drawLayer);
let draw = new Draw({
source : drawSource,
type : GeometryType.POLYGON,
style : new Style({
stroke: new Stroke({
color: "#f00",
width: 1,
}),
fill: new Fill({
color: "#300",
})
})
});
this.map.addInteraction(draw)
启动新图形时清除源
draw.on('drawstart', function() {
drawSource.clear();
});