Reputation: 2750
I am following the marker cluster example in leaflet which is below: marker-cluster As shown all the markers are clustered and now I want to modify the color of the marker for some. So i will be having another column in the file like below:
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],
]
where 0 are blue markers and red 1 are red markers. So how can I change the color of the marker depending on the third column in the marker cluster? Update
I added the following code
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);
But still the marker color is blue and did not change to green.Any help is appreciated
Upvotes: 0
Views: 687
Reputation: 2750
Actually this made the trick:
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);
Hope it helps anyone
Upvotes: 2