如何暂时禁用地图标记聚类? [英] How to temporarily disable map marker clustering?

查看:121
本文介绍了如何暂时禁用地图标记聚类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android版Google Maps V2和用于标记聚类的maps utils扩展库.应用程序的某些部分不需要获取群集标记.

I am using Google Maps V2 for Android together with maps utils extension library for marker clustering. Some parts of app does not need to get clustered markers.

有什么方法可以禁止clusterManager对标记进行聚类,并且在某些条件后让它再次对项目进行聚类?

Is there any way to forbid clusterManager to cluster markers and after certain conditions let it cluster items again?

推荐答案

我发现自己是另一个解决方案.我发现在DefaultClusterRenderer上,方法shouldRenderAsCluster负责标记是否将显示为簇.因此,我创建了一个扩展DefaultClusterRenderer的CustomRenderer类,并创建了一个带有布尔变量的方法来确定渲染器是否应该聚类.

I found myself another solution. I figured out that on DefaultClusterRenderer method shouldRenderAsCluster is responsible for whether the marker will be rendered as cluster or not. So I created a CustomRenderer class which extends DefaultClusterRenderer and created a method with a boolean variable to determine whether renderer should cluster or not.

public class CustomRenderer extends DefaultClusterRenderer<MarkerItem>
{
private boolean shouldCluster = true;
private static final int MIN_CLUSTER_SIZE = 1;

//Some code....

public void setMarkersToCluster(boolean toCluster)
{
    this.shouldCluster = toCluster;
}

我也重写了我之前提到的方法.

I also override the method here that i mentioned before.

@Override
protected boolean shouldRenderAsCluster(Cluster<MarkerItem> cluster)
{
    if (shouldCluster)
    {
        return cluster.getSize() > MIN_CLUSTER_SIZE;
    }

    else
    {
        return shouldCluster;
    }
}

现在,如果我想停止群集,我只需从我想要的活动中调用此方法即可.

And now if I want to stop clustering i just call this method from the activity i want.

ClusterManager clusterManager = new ClusterManager<MarkerItem>(this, googleMap);
CustomRenderer customRenderer = new CustomRenderer(this, googleMap, clusterManager);
clusterManager.setRenderer(customRenderer);
customRenderer.setMarkersToCluster(false);

这篇关于如何暂时禁用地图标记聚类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆