leaflet/JSONobject. Marker onclick show only last record
- by user2780898
that my code
<div id='map'></div>
<div id="info"></div>
[...]
var markers1 = new L.MarkerClusterGroup( { showCoverageOnHover: true } );
$.ajax({
type: "GET",
url: "db.php",
success: function (result) {
var JSONobject = JSON.parse(result);
var jnCount = JSONobject.length;
for (var i = 0; i < jnCount; i++) {
var marker = new L.Marker(new L.LatLng(JSONobject[i]["lat"],JSONobject[i]["lng"]),{ icon: myIcon1 });
var id = JSONobject[i]["id"];
var list = "<dl>"
+ "<dt><b>CITTA':</b> " + JSONobject[i]["citta_"] + "</dt>";
marker.on('click', function()
{ {document.getElementById('info').innerHTML = list;} });
markers1.addLayer(marker);
}
map.addLayer(markers1);
}
});
Marker onclick shows only the last record! I think problem is in loop but I don't understand how fix it. Any idea?
Thanks
Nicola