lundi 28 octobre 2019

use if statement in json

I have a problem using the if statement json in leaflet, does anyone know a solution?

var Icon2 = L.icon({
                        iconUrl : src = "marker/dam.png",
                        iconSize:     [15, 25],
                        iconAnchor:   [25, 25],
                        popupAnchor:  [-20, -30] 
                    });
                    var Icon1 = L.icon({
                        iconUrl : src = "marker/pinicon.png",
                        iconSize:     [15, 25],
                        iconAnchor:   [25, 25],
                        popupAnchor:  [-20, -30] 
                    });

and this the if statement of my icon in leaflet

function getMarker() {
$.getJSON("getData.php", function (data) {
for (var i = 0; i < data.length; i++) {
var location = new L.LatLng(data[i].latitude, data[i].longitude);
var name = data[i].name1;
var id = data[i].id_icon;
var longitude = data[i].longitude;
var latitude = data[i].latitude;
var marker = L.marker([data[i].latitude, data[i].longitude],{
if (id[i] == 1){
icon:Icon2;
}else{
icon:Icon1;
}
}).addTo(map);
}
})
};

Aucun commentaire:

Enregistrer un commentaire