hulab / ClusterKit

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

clustering for Mapbox not working #68

Open makinggainz opened 5 years ago

makinggainz commented 5 years ago

So I have tried implementing the ClusterKit proj in order to have clustering of annotations/(possibly polylines)(given that Mapbox does not have that functionality) in my app but it does not seem to work. No errors or anything it just does nothing and I am unsure what I am doing wrong.

Here is the relevant code:

 viewDidLoad() {
        let algorithm = CKNonHierarchicalDistanceBasedAlgorithm()
        algorithm.cellSize = 200
        mapView1.clusterManager.algorithm = algorithm
        fetchData() //This is a call to firebase I add the annotations to an  array of them inside an annotations object. 
        setupCluster() //This gest called multiple times IDK why, not sure if its the issue but I have been unable to change this
  }
    func setupCluster() {

            mapView1.clusterManager.marginFactor = 1
            print(ObjAnnotationArray.annotations, " These are teh annotations")
            mapView1.clusterManager.annotations = ObjAnnotationArray.annotations
    }

These are the delagete methods whwere I added functionality as specified in the docs.

`    @nonobjc func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {
        print("Change ")
        mapView.clusterManager.updateClustersIfNeeded()
    }
`    func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {

        print(annotation," ",(annotation as? CKCluster)?.count, " also: ",annotation as? CKCluster)

        if let cluster = annotation as? CKCluster, cluster.count > 1 {
            print("inside if the k=cluser functionaluty")

            let edgePadding = UIEdgeInsets(top: 40, left: 20, bottom: 44, right: 20)
            let camera = mapView.cameraThatFitsCluster(cluster, edgePadding: edgePadding)
            mapView.setCamera(camera, animated: true)
        }
}

Any help/suggestions on how to solve this?

I have looked here at their example but cant find a solution there myself.

Also, here is the wiki on how to implement which I followed.

Shwetank97 commented 4 years ago

I've also tried making use of this third party to create clusters of the annotation views, but nothing happens. No errors or anything are shown either? Has this issue been resolved?