因此,我正在尝试更改leaflet地图中标记聚类图标的颜色。我只想改变颜色并继承其他默认属性(例如形状、文本属性等)。
在这个示例中,有类似于我想要的东西,但他们定义了一个全新的CSS类,而没有使用默认图标样式。我需要的是像这样但带有自定义颜色:
我知道我必须自定义iconCreateFunction
。我正在尝试以下方法:
CSS
.foo { background-color: red;}
.bar { background-color: blue;}
JavaScript
var markers = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
// here there is a piece code that determines the value of the variable 'class_name' is either foo or bar
return L.divIcon({ className: "marker-cluster-medium "+class_name});
}
});
很不幸,那个解决方案无效并导致图标渲染不美观。
我该如何仅更改默认markercluster图标的颜色?