Firstly I'm a beginner in Mapbox and I have an issue with changing style of map. When change the style, I am uploading sources but can't add a new layer to map.
I am creating my sources like that.
function addRoadsSource(){
map.addSource('roads3',{
'type':'geojson',
'data': datas.roadsInfo // datas --> roadsInfo includes roads geoFile Data
});
}
And adding them as a layer to map with uploadRoads()
function uploadRoads() {
map.on('load',function() {
addRoadsSource();
showRoads();
});
}
And also here is showRoads() function
function showRoads() {
map.addLayer({
'id': 'roadsLayer',
'type': 'line',
'source': 'roads3',
'filter': ['==', '$type', 'LineString'],
'paint' : {
'line-color' : '#33cc33',
'line-width' : 5
}
});
}
But when I change style of map from streets-v11 to dark-v10 all sources are gone. According to my research it's happening because of structure of mapbox(Mapbox-GL setStyle removes layers). And everyone says that I need to upload resources again. But I'm already uploading my resources with addRoadsSource() function. Then when I add a new layer to new style with uploadRoads() roads do not appear on the map. When I look to sources of new style with map.style.sources() I can see that sources loaded correctly but layers don't appear. I hope I could explain my problem. I looked at many sources, including Github issues, but none of them worked for me. If you need anything from my code or geojson files, I can add it.