I am trying to get multiple (5) popups to open based on clicking a polyline. It seems that I am only able to open one of the popups/photo with the clickevent. Is it possible to open 5 popups via one click on a polyline in Leaflet?
function getPhotos(res) {
const photo_link = `https://www.strava.com/api/v3/activities/number/photos?photo_sources=true&access_token=hidden&size=1000`;
fetch(photo_link)
.then((res) => res.json())
.then(function (data) {
for (var x = 0; x < data.length; x++) {
var images = data[x].urls["1000"];
console.log(images);
var lat = data[x].location[0];
var lng = data[x].location[1];
var latlng = { lat, lng };
console.log(latlng);
L.polyline(coordinates, {
color: "red",
weight: 3,
})
.on("click", function (e) {
L.popup({ autoPan: false })
.setContent("<img src='" + images + "' width='160'/>")
.setLatLng(latlng)
.openOn(map);
})
.addTo(map);
}
});
}
getPhotos();
var layer= new L.popup({ autoPan: false, autoClose: false })
.setContent("<img src='" + images + "' width='160'/>")
.setLatLng(latlng)
map.addLayer(layer)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.