/ / Come creare diversi indicatori di colore in cluster: javascript, leaflet, mapbox

Come creare indicatori di colore diversi in cluster: javascript, leaflet, mapbox

Sto seguendo l'esempio del cluster di marker nel volantino che è di seguito: marcatore-cluster Come mostrato, tutti i marker sono raggruppati e ora voglio modificare il colore del marker per alcuni. Quindi avrò un'altra colonna nel file come di seguito:

var addressPoints = [
[-37.8210922667, 175.2209316333, "2",0],
[-37.8210819833, 175.2213903167, "3",1],
[-37.8210881833, 175.2215004833, "3A",1],
[-37.8211946833, 175.2213655333, "1",0],
[-37.8209458667, 175.2214051333, "5",0],
[-37.8208292333, 175.2214374833, "7",1],
]

dove 0 sono marcatori blu e rosso 1 sono marcatori rossi. Quindi, come posso cambiare il colore del marcatore a seconda della terza colonna nel cluster di marker? Aggiornare

Ho aggiunto il seguente codice

var map = L.map("map", {center: latlng, zoom: 13, layers: [tiles]});
var greenIcon = new L.Icon({
iconUrl: "/img/marker-icon-2x-green.png",
shadowUrl: "/img/marker-shadow.png",
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});



var markers = L.markerClusterGroup();

for (var i = 0; i < addressPoints.length; i++) {
var a = addressPoints[i];
var title = a[2];
if(a[3]==0){

var marker = L.marker(new L.LatLng(a[0], a[1]), { title: title },{icon: greenIcon});
}
else{

var marker = L.marker(new L.LatLng(a[0], a[1]), { title: title });

}

marker.bindPopup(title);
markers.addLayer(marker);
}
map.addLayer(markers);

Ma il colore dell'indicatore è ancora blu e non cambia in verde. Qualsiasi aiuto è apprezzato

risposte:

2 per risposta № 1

In realtà questo ha fatto il trucco:

var map = L.mapbox.map("map", "mapbox.streets")
.setView([-37.82, 175.215], 14);

var markers = new L.MarkerClusterGroup();

for (var i = 0; i < addressPoints.length; i++) {
var a = addressPoints[i];
var title = a[2];

if(a[3]==1){
var marker = L.marker(new L.LatLng(a[0], a[1]), {
icon: L.mapbox.marker.icon({"marker-symbol": "car", "marker-color": "#00FFFF"}),
title: title
});
}
else{
var marker = L.marker(new L.LatLng(a[0], a[1]), {
icon: L.mapbox.marker.icon({"marker-symbol": "car", "marker-color": "#ff0000"}),
title: title
});
}

marker.bindPopup(title);
markers.addLayer(marker);
}



map.addLayer(markers);

Spero che aiuti chiunque