ios - 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 。
解决方案
推荐阅读
- javascript - express 和 vue 项目如何协同工作?
- python - 如何更改动态本地主机端口?
- algorithm - 选择几何最接近原始点的子集
- c# - 当不再使用实例时,使用 Xamarin.Android 和 Xamarin.iOS 开发的应用程序是否需要分配空值?
- java - Gradle 任务的 doFirst() 不会先执行,而是在任务完成后执行
- angular - 预期 2 个参数,但在 Angular 2 中得到 1 个
- abap - 如何以新模式编写列表(abap)
- html - 无法定位 div 50% 高度 css
- python - 在定义另一个函数的 python 装饰器中会发生什么?
- sql - 返回值比 oracle apex 5.1 中“仅显示”页面项目的显示值