hulab / ClusterKit

An iOS map clustering framework targeting MapKit, Google Maps and Mapbox.
MIT License
512 stars 86 forks source link

count on cluster item #11

Closed MaeseppTarvo closed 7 years ago

MaeseppTarvo commented 7 years ago

Hey! How should you add the count to cluster item?

maxep commented 7 years ago

You can manage the cluster UI in the mapview's data source method.

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    if let cluster = annotation as? CKCluster {
         // Return an annotation view that show the cluster count.
    }
}
MaeseppTarvo commented 7 years ago

@maxep I created simple UILabel and assigned it to the iconView but the count is totally wrong for some reason. Is thecluster.count right?

maxep commented 7 years ago

@MaeseppTarvo yes you can use the count property, I'm not seeing a wrong value on my side.

NSMyself commented 7 years ago

@MaeseppTarvo I tried adding a label as a subview to the annotationView of the example project and I was experiencing the same issue: the label was off by a lot (and it persisted even when the annotation wasn't a cluster).

If you disable the annotation reuse it works though.

maxep commented 7 years ago

Did you properly clean the count label of the reused view? whether in the prepareForReuse of the annotation view subclass, or in the data source method mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation)