I am working on a project where I need to showcase a large amount (~1 million) of GPS coordinates using Mapbox gl js. To handle this data fetch from the server, I have set up multiple sequential Ajax requests. My goal is to update the map with a new layer after each Ajax request and have it immediately displayed.
However, I encountered an issue when trying to place the code inside the
map.on('style.load', function() {})
event. The map would not render until all the Ajax calls are completed. The current structure of my code looks something like this:
function loadData(finished) {
if (finished) {
return;
}
// Perform ajax request and wait for completion
// If it's the last request, set finished = true
// Call map.addSource()
// Call map.addLayer()
// Recursive call to loadData()
}
map.on("style.load", function() {
loadData();
});
Can anyone suggest a solution to overcome this issue?