首页 > 解决方案 > 如何在 MarkerClusterGroup 中设置每个集群的选项

问题描述

我使用以下方式创建自己的 MarkerClusterGroup:

this.cluster = leaflet.markerClusterGroup({
    zoomToBoundsOnClick: false,
    showCoverageOnHover: false,
    spiderfyDistanceMultiplier: 3,
    spiderLegPolylineOptions: {
        weight: 1.5,
        color: "#1BA5D0",
        lineCap: "butt",
        dashArray: "10 10",
        opacity: 0.5
    }
});

如何为该组内的每个集群应用一些选项(就它实际上是leaflet.Marker而言)?特别是,我想设置riseOnHover: true

我发现有一些方法可以使用自定义窗格控制整个 MarkerClusterGroup 定位,但这不是我的情况

标签: javascriptleafletleaflet.markercluster

解决方案


最后,我想通了。选项可以在里面设置iconCreateFunction

this.cluster = leaflet.markerClusterGroup({
    iconCreateFunction: cluster => {
        cluster.options.riseOnHover = true;
    }
});

推荐阅读