I have several sources and layers generated on my map through looping as can be seen on the source code.
var id, lat, lng, point;
function setPosition() {
$.post('m/getData.php', function(data) {
var split = data.split(",");
for (i = 0; i < split.length - 1; i++) {
var secSplit = split[i].split("|");
id = secSplit[0];
lat = secSplit[1];
lng = secSplit[2];
point = {
"type": "Point",
"coordinates": [lng, lat]
};
map.addSource(id, {
type: 'geojson',
data: point
});
map.addLayer({
"id": id,
"type": "symbol",
"source": id,
"layout": {
"icon-image": "ferry-15"
}
});
}
});
}
For my question, is it possible to dynamically bind popup to every sources and layers using Mapbox GL JS?
From what I have seen on Mapbox example, it shows only how to bind popup with feature collection from a single layer as you can see here