efremidze / Cluster

Easy Map Annotation Clustering 📍
MIT License
1.27k stars 121 forks source link

How to enable canShowCallout and rightCalloutAccessoryView? #48

Closed donbytyqi closed 7 years ago

donbytyqi commented 7 years ago

annotation.canShowCallout = true annotation.rightCalloutAccessoryView = UIButton

Doesn't seem to work.

efremidze commented 7 years ago

on the cluster annotation or regular annotation?

donbytyqi commented 7 years ago

on the cluster annotation view, sorry should've been more clear.

annotationView = ClusterAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier, type: .image(UIImage(named: "pin.png"))) annotationView?.isUserInteractionEnabled = true annotationView?.canShowCallout = true annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)

efremidze commented 7 years ago

You need to add it twice since its reused

if let view = view as? ClusterAnnotationView {
    view.annotation = annotation
    view.configure(with: type)
    view.canShowCallout = true
    view.rightCalloutAccessoryView = SomeView()
} else {
    view = ClusterAnnotationView(annotation: annotation, reuseIdentifier: identifier, type: type)
    view.canShowCallout = true
    view.rightCalloutAccessoryView = SomeView()
}
donbytyqi commented 7 years ago

That doesn't seem to work as well, is this the right place to put it?

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

    guard !annotation.isKind(of: MKUserLocation.self) else {
        return nil
    }

    let annotationIdentifier = "AnnotationIdentifier"

    var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier)

    if annotationView == nil {
        annotationView = ClusterAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier, type: .image(UIImage(named: "pin.png")))
        annotationView?.canShowCallout = true
        annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
    } else {
        annotationView!.annotation = annotation
        annotationView?.canShowCallout = true
        annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
    }

    return annotationView

}
efremidze commented 7 years ago

I don't believe I'm breaking the callout anywhere. Can u check stackoverflow? Or try to debug it.

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

    guard !annotation.isKind(of: MKUserLocation.self) else {
        return nil
    }

    let annotationIdentifier = "AnnotationIdentifier"

    var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier)

    if annotationView == nil {
        annotationView = ClusterAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier, type: .image(UIImage(named: "pin.png")))
    } else {
        annotationView!.annotation = annotation
    }
    annotationView!.canShowCallout = true
    annotationView!.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)

    return annotationView

}
donbytyqi commented 7 years ago

Still not working, maybe the issue is Swift 4?

efremidze commented 7 years ago

swift 4 doesn't affect callouts

donbytyqi commented 7 years ago

hmm, okay, I'll just see what's causing this issue. Thanks for the help :)

sandman4sure commented 6 years ago

It breaks because of the layer.masksToBounds = true in ClusterAnnotationView

matejhocevar commented 6 years ago

I'm having the same issue. How can I display annotation callout? Can someone show me on example code from this repo? Thanks for help

efremidze commented 6 years ago

This library handles the clustering, you can add a callout by using the MKMapViewDelegate methods.

Example: https://www.raywenderlich.com/548-mapkit-tutorial-getting-started

ghadeermohameedelmahdy commented 2 years ago

anyone have the solution?