删除固定feature的方法, 删除多个Feature可以循环遍历这个方法
import { Feature, Map, Overlay, View } from "ol";
import * as olProj from "ol/proj";
import VectorSource from "ol/source/Vector";
let vectorSource = new VectorSource({
wrapX: false,
});
let coordinates = [118, 103];
let newFeature = new Feature({
geometry: new Point(
olProj.fromLonLat(coordinates),
"XY"
),
data: [],
type: 'test',
});
newFeature.setStyle(new Style({...}));
newFeature.setId('newIcon');
vectorSource.addFeature(newFeature);
// 删除Feature
let f = vectorSource.getFeatureById('newIcon');
vectorSource.removeFeature(f); // 设置