我正在使用 Mapbox-gl 在我的代码中显示地图
更新地图线并重新设置它们时,我收到此错误:
mapboxgl:已经有一个具有此 ID 的源
在设置图层和源之前,我将其删除
if (this.map.getLayer('mapLine')) {
this.map.removeSource('lines');
this.map.removeLayer('mapLine');
}
Run Code Online (Sandbox Code Playgroud)
之后我正在做这个操作:
this.map.addSource('lines', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features,
},
});
this.map.addLayer({
id: 'mapLine',
type: 'line',
source: {
type: 'geojson',
data: {
type: 'FeatureCollection',
features,
},
},
paint: { 'line-width': 4, 'line-color': ['get', 'color'] },
});
Run Code Online (Sandbox Code Playgroud)
但是,我在尝试添加图层时遇到错误。