How do I get the data according to the marker I clicked on?
for(i in data) {
var title = data[i].title,
id = data[i].id,
position = data[i].position,
kriteria = data[i].data.kriteria,
iconUrl = data[i].icon.url,
pa_judul = data[i].data.pa_judul,
marker = new L.Marker(new L.latLng(position),
{
icon: L.icon({
iconUrl: iconUrl,
})
},
{title: title},
).addTo(map);
marker.bindPopup('ID: '+ id ).on('click', function(e) {
console.log(data);
$('#ModalDetail').modal('show').on('shown.bs.modal', function(e) {
});
});
markersLayer.addLayer(marker);
}
console.log(data)
returns the whole array:
When I change to console.log(data[i]);
I get undefined message:
If I change to console.log(data[0])
or data[1]
and data[2]
the results is not error and I can get the data:
Only for marker.bindpopup
this working fine, but for on click it's not working.