choefele / CCHMapClusterController

High-performance map clustering with MapKit for iOS and OS X. Integrate with 4 lines of code.
MIT License
1.37k stars 155 forks source link

Cannot refer to custom subclass of MKAnnotation in viewForAnnotation #138

Closed happiehappie closed 7 years ago

happiehappie commented 7 years ago

I have a custom subclass of MKAnnotation with extra property: Image etc However, in my viewForAnnotation delegation method, if annotation is DiscoverMapAnnotation { print("I want youuu") } else if let annotation = annotation as? CCHMapClusterAnnotation { print("NOOO") }

always prints NOOO. this is how I addAnnotation self.mapClusterController.addAnnotations([DiscoverMapAnnotation(id: location.id, location: location.location, thumbnailUrl: location.thumbnailUrl, coordinate: CLLocationCoordinate2D(latitude: Double(location.location.latitude)!, longitude: Double(location.location.longitude)!))], withCompletionHandler: nil)

Am I doing anything wrong?

happiehappie commented 7 years ago

From what I observe, as long as I add annotation to CCHMapClusterController instead of my mapkit directly, I can't reference my DiscoverMapAnnotation

choefele commented 7 years ago

Hi – once you created a custom MKAnnotation with your property just add it to the map cluster controller with addAnnotations as you described in your comment.

At which point do you need access to the annotation you have added? mapView:viewForAnnotation: will give you the annotation directly whereas the delegate calls for CCHMapClusterController will pass you a CCHMapClusterAnnotation with your annotation in the annotations array.

This code of the example might help

happiehappie commented 7 years ago

@choefele Thank you so much for you comment really... I didn't have my concept right about my custom annotation is INSIDE CCHMapClusterAnnotation. Feel free to close this now. And again, thank you for the swift reply and the input really.