【问题标题】:How to customize markercluster icon when using angular-leaflet-directive使用angular-leaflet-directive时如何自定义markercluster图标
【发布时间】:2023-03-03 01:07:01
【问题描述】:
Leaflet 文档概述了一种使用 iconCreateFunction 指定 MarkerClusterGroup 的方法,您可以在其中自定义集群图标的外观。我想知道是否有通过 angular-leaflet-directive 暴露的东西也允许这样做,或者是否有办法在使用指令时降低到较低级别的 Leaflet API 来完成它。基本上,我只是想改变颜色改变的值而不是 10 和 100,我也想改变不同值的图标直径。类似于 Google MarkerClusterer 的东西。
谢谢
【问题讨论】:
标签:
javascript
angularjs
maps
leaflet
【解决方案1】:
在您指定标记集群的叠加层中,您可以添加选项。比如:
layerOptions: {
showCoverageOnHover: false,
disableClusteringAtZoom: 12,
iconCreateFunction: function (cluster) {
var childCount = cluster.getChildCount();
var c = ' marker-cluster-';
if (childCount < 10) {
c += 'small';
} else if (childCount < 100) {
c += 'medium';
} else {
c += 'large';
}
return new L.DivIcon({ html: '<div><span>' + "CUSTOM" + '</span></div>', className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) });
}
}