I'm currently adding some popups to my leaflet map of tourist destinations within a country. The popups will have a title, image and wiki link. I want to check that the images are available and preload them. I've succeeded in all of this, but now I don't know how to insert the preloaded images into the popup.
Here is my code:
var tourists = result.tourists.geonames;
var images_urls = [];
for (let i in tourists) {
$.get(tourists[i].thumbnailImg)
.done(function () {
images_urls.push(tourists[i].thumbnailImg);
}).fail(function () {
images_urls.push("libs/css/image/wiki.png");
})
}
var images = [];
function preload(arguments) {
for (var i = 0; i < arguments.length; i++) {
images = new Image();
images.src = arguments[i];
}
}
preload(images_urls);
for (let i in tourists) {
markers.addLayer(
L.marker([tourists[i].lat, tourists[i].lng], { icon: touristIcon })
.bindPopup(`<b>${tourists[i].title}</b> <br> INSERT PRELOADED IMAGES <br> <a href="https://${tourists[i].wikipediaUrl}" target="_blank" >Wikipedia Article<a> <br>`)
)
}