I am trying to load 300 markers at a time from an API and since I'm trying to load the data also for pop-up which contains image, it takes too much time to load the markers as well. I want to know if I can load the markers as soon the map opens and then load the image for each marker pop-up when clicked on that particular marker.
This is my piece of code:
fetch('http://www.example.com/data.php?qty=250')
.then((response) => response.json())
.then((response) => {
let datapoint = response.datapoint;
for (let i=0; i<datapoint.length; i++) {
let lat = parseFloat(datapoint[i]["lat"]);
let lon = parseFloat(datapoint[i]["long"]);
let popup = L.popup().setContent("<img src=\""+datapoint[i].img+"\" width='32%' height='135px'/>" + '<h3>');
let markerLocation = new L.LatLng(lat, lon);
let marker = new L.marker(markerLocation,{icon: greenIcon});
marker.addTo(map).bindPopup(popup,customOptions);
marker.setOpacity(1.0);
}
document.getElementById('loader').style.display='none';
})
I tried to add this code but not sure what to do:
marker.bindPopup(function() {
var el = $('<div/>');
$.get("DYNAMIC_CONTENT_URL").done(function(data) {
el.setContent(data);
popup.update();
});
return el;
});
Here is my sample data:
{"datapoint":[{"img":"abc.jpeg","latitud":"18.52","longitud":"82.4767"},{"img":"bbc.jpeg","latitud":"17.7375","longitud":"82.8347"}]}
Any help is appreciated! Thanks.