如何修改集群项总和值?

How to modify cluster item total sum value?

目前我正在使用 google 地图实用程序来实现地图中的标记及其聚类。

问题是我只希望其中一些标记计入簇密度的总和。

我一直在寻找基于标记标签的决策过程,但我似乎无法找到改变每个集群中总标记数的方法。

有什么办法吗?

谢谢

在您的 ClusterRenderer 中覆盖 onBeforeClusterRendered 如下:

@Override
protected void onBeforeClusterRendered(Cluster<MyClusterItem> cluster,
                                       MarkerOptions markerOptions) {

    // Calculate totalSum by checking the color of item
    int totalSum = 0;
    for (MyClusterItem item : cluster) {
        // Assume each MyClusterItem holds an attribute -- String color --.
        // Also, assume you can get this attribute by using the following method.
        if (item.getColorAsString().equals("red")) {
            totalSum++;
        }
    }

    // Write a method to customize your cluster drawable according to totalSum.
    Drawable customDrawable = customizeClusterDrawable(totalSum);
    mClusterImageView.setImageDrawable(customDrawable);
    Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}