小编Chi*_*ker的帖子

如何解决错误:“mapboxgl:更新图层时已存在具有此 ID 的源”?

我正在使用 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)

但是,我在尝试添加图层时遇到错误。

mapbox-gl mapbox-gl-js angular

5
推荐指数
1
解决办法
8815
查看次数

标签 统计

angular ×1

mapbox-gl ×1

mapbox-gl-js ×1