I want to implement marker click event so when user click on marker it goes to url. Url is written inside an array (a[3]). However, this is my code which doesn't work, it always goes to the link of the last marker only. Can you help me? I need a function which will open a new window with url in an array of that specific marker.
for (var i = 0; i < markers.length; i++) {
var a = markers[i];
var title = a[2];
var link = a[3];
var image = a[4];
var list =
"<dl>"
+ "<dt>" + title + "</dt>"
+ image
+
"</dl>";
var marker = new L.Marker(new L.LatLng(a[0], a[1]), { riseOnHover: true }).bindLabel(list).addTo(map);
marker.on("click", function() {
window.open(link, "_blank");
}
);
}
Best Answer
I have written down a small piece of code might be helpful for you.
You can try working example on jsFiddle