choefele/CCHMapClusterController

showAnnotations:animated: adds the default pin instead of custom Annotation Views

fdocr opened this issue · 1 comments

fdocr commented

First of all, amazing work on this Controller :)

I'm having some trouble zooming into a cluster following a tap on a cluster annotation. I implemented both mapView:viewForAnnotation: and mapClusterController:willReuseMapClusterAnnotation:. The problem is that the map adds the default annotation (red pin) to the MapView instead of using the custom map views.

Inside mapView:didSelectAnnotationView: i have something similar to this (Swift 2.3):

guard let clusterAnnotation = view.annotation as? CCHMapClusterAnnotation else { return }

if clusterAnnotation.annotations.count > 1 {
   let array: [MKAnnotation] = clusterAnnotation.annotations.map { $0 as! MKAnnotation }
   mapView.showAnnotations(array, animated: true)
}

Also recreated the issue using the example project on Obj-C in this fork. Is this a bug or am I missing something?

Cheers

fdocr commented

It just came to me that showAnnotations:animated: adds these annotations to the mapView (instead of adding them to the MapClusterController) and they just hang there on the map as default pins.

Still not sure if this is the desired behavior (OK to close the issue otherwise) but removing them right after showAnnotations:animated: them solved the extra pins issue:

guard let clusterAnnotation = view.annotation as? CCHMapClusterAnnotation else { return }

if clusterAnnotation.annotations.count > 1 {
   let array: [MKAnnotation] = clusterAnnotation.annotations.map { $0 as! MKAnnotation }
   mapView.showAnnotations(array, animated: true)
   mapView.removeAnnotations(array)
}