I am using Mapbox-gl for showing the map in my code
When updating map lines and re-setting them I am getting this error:
mapboxgl: There is already a source with this ID
Before setting layer and source I am removing it
if (this.map.getLayer('mapLine')) {
this.map.removeSource('lines');
this.map.removeLayer('mapLine');
}
After that I am doing this operations:
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'] },
});
However, I am getting errors when trying to add a layer.