How to show an count for cluster
Closed this issue · 1 comments
cspnanda commented
For clustered annotations I want to show the number of elements inside a circle. So I implemented viewForClusterAnnotation inside my view controller.
-(MKAnnotationView *)mapView:(ADClusterMapView *)mapView viewForClusterAnnotation:(id <MKAnnotation>)annotation
{
ADClusterAnnotation *myc = (ADClusterAnnotation*) annotation;
MKAnnotationView * pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"ADMapCluster"];
if (!pinView) {
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"ADMapCluster"];
pinView.image = [self generateClusterIconWithCount:[[myc originalAnnotations] count]];
pinView.canShowCallout = YES;
}
else {
pinView.annotation = annotation;
}
return pinView;
}
But [myc originalAnnotations] count] is not showing the correct count. Which property I should be using ?
PatrickNLT commented
Are you sure that the originalAnnotations property is not returning the correct result?
Could you try with myc.cluster.numberOfChildren
?
Another possibility is that your image is not refreshed when the annotation view is dequeued: in your code, the `ìmage`` property is set only when allocating a new annotation view.