osmbonuspack
osmbonuspack copied to clipboard
Problem on the number of items in a cluster when we customize it
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?
refers to #204