我正在关注下面的传单中的标记群集示例: marker-cluster 如图所示,所有标记都是聚类的,现在我想修改某些标记的颜色。所以我将在文件中有另一列,如下所示:
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],
]
其中0是蓝色标记,红色1是红色标记。那么如何根据标记簇中的第三列更改标记的颜色? 的更新
我添加了以下代码
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);
但是标记颜色仍然是蓝色,并且没有变为绿色。感谢任何帮助