hulab / ClusterKit

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

ClusterKit incompatible with with MGLAnnotations? #66

Closed makinggainz closed 5 years ago

makinggainz commented 5 years ago

So I am trying to implement the mapbox pods in order to cluster a bunch of customPointAnnotations which are in an array. The only problem is that on the line below:

mapView1.clusterManager.annotations = annotations I get the following error:

Cannot assign value of type '[MGLAnnotation]' to type '[MKAnnotation]'

Does clusterkit not work with MGLAnnotations?

maxep commented 5 years ago

ClusterKit works with MKAnnotation but this is easily fixed by adding the compliance. MGLAnnotation and MKAnnotation are very close:

class YourAnnotation: NSObject, MGLAnnotation, MKAnnotation {
    ...
}
makinggainz commented 5 years ago

@maxep I currently do not have my own custom class for my annotations. I must then create one? What content should it have inside? Could you point me to any examples of how this would be implemented?

maxep commented 5 years ago

MGLAnnotation like MKAnnotation are protocols, so you need to create a concrete type that complies to MKAnnotation to be used as an annotation in ClusterKit. In the examples of this project, I use the MKPointAnnotation.

makinggainz commented 5 years ago

@maxep So I did this and also implemented the other pieces of functionality and it has not been working. I find that in the

func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) { method I get nil when doing: if let cluster = annotation as? CKCluster, cluster.count > 1 { How do I fix this? I also asked a SO question if you would like to check it out.

I also did extension MapVC: MGLMapViewDelegate, MKMapViewDelegate { But that does not seem to help. Not sure if I need to do this or not.

makinggainz commented 5 years ago

I believe my problem above has to do with the clustering not working at all so I opened a new issue for it. https://github.com/hulab/ClusterKit/issues/68