Skip to content

clustering for Mapbox not working #68

@makinggainz

Description

@makinggainz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions