Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem on the number of items in a cluster when we customize it #238

Open
2ndGAB opened this issue Jul 26, 2016 · 1 comment
Open

Problem on the number of items in a cluster when we customize it #238

2ndGAB opened this issue Jul 26, 2016 · 1 comment

Comments

@2ndGAB
Copy link

2ndGAB commented Jul 26, 2016

Hi Mickael,

I have a problem with the number displayed on the cluster icon.
I've customized RadiusMarkerClusterer that way to only cluster :

public class MyRadiusMarkerClusterer extends RadiusMarkerClusterer {

    public int getMinNumOfMarkersInCluster() {
        return minNumOfMarkersInCluster;
    }

    public void setMinNumOfMarkersInCluster(int minNumOfMarkersInCluster) {
        this.minNumOfMarkersInCluster = minNumOfMarkersInCluster;
    }

    int minNumOfMarkersInCluster = 1;   // Initialized to 1 to keep the same behavior as today

    public MyRadiusMarkerClusterer(Context ctx) {
        super(ctx);
    }

    @Override public ArrayList<StaticCluster> clusterer(MapView mapView) {

        ArrayList<StaticCluster> clusters = super.clusterer(mapView);

        ArrayList<StaticCluster> myClusters = new ArrayList<>();

        Iterator<StaticCluster> itClusters = clusters.iterator();

        while(itClusters.hasNext()) {
            StaticCluster cluster = itClusters.next();

            if (cluster.getSize() < minNumOfMarkersInCluster) {
                for (int i = 0; i < cluster.getSize(); i++) {
                    StaticCluster newCluster = new StaticCluster(cluster.getItem(i).getPosition());
                    newCluster.add(cluster.getItem(i));
                    myClusters.add(newCluster);
                }
            } else {
                myClusters.add(cluster);
            }
        }

        clusters.clear(); // Not sure it's useful
        return myClusters;
    }

    @Override public boolean onSingleTapConfirmed(final MotionEvent event, final MapView mapView){

        for (int i = mClusters.size() - 1; i >= 0 ; i--){
            StaticCluster cluster = mClusters.get(i);
            if (cluster.getMarker().onSingleTapConfirmed(event, mapView))
                return true;
        }
        return false;
    }
}

So that way, the number of items supposed to be contained in a cluster is higher than expected.
I think that some items are counted twice maybe.

What's your opinion?

@2ndGAB
Copy link
Author

2ndGAB commented Jan 24, 2017

refers to #204

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant