首页 > 解决方案 > Mapbox 的 ClusterKit 无法正常工作?

问题描述

因此,我尝试实现 ClusterKit项目,以便在我的应用程序中对注释/(可能是折线)(假设 Mapbox 没有该功能)进行聚类,似乎不起作用。没有错误或任何事情,它什么都不做,我不确定我做错了什么。

以下是相关代码:

 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
    }

这些是我添加了文档中指定的功能的 delagete 方法。

`    @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)
        }
}

关于如何解决这个问题的任何帮助/建议?

我在这里查看了他们的示例,但我自己无法找到解决方案。

此外,这是我遵循的关于如何实现的 wiki 。

标签: iosswiftmapbox

解决方案


推荐阅读