swift - Realm map 集群的自定义 View

标签 swift mkmapview realm

据我阅读有关 map 聚类的 Realm 文档,有一个类 ABFClusterAnnotationView,它有几个属性:countcolorcountLabel 但我无法在任何地方找到 image 进行注释。是否可以通过添加 image 属性来覆盖?我设法通过使用默认注释 iside mapView 委托(delegate)方法添加 images 但从那里我无法管理集群的数量。我只想在 map 上只有 1 个值的图钉的地方更改图像。

所以没有什么棘手的,简单的为注释设置图像:

 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

        let annView = MKAnnotationView(annotation: annotation, reuseIdentifier: "test")
        annView.image = myImage

        return annView
    }

提前致谢!

最佳答案

恕我直言,图像属性未被覆盖。但无论如何你还有几个选择:

  1. 不要使用 ABFClusterAnnotationView。 (使用例如 MKAnnotationView)
  2. 使用FBAnnotationClusterView, 设置 FBAnnotationClusterViewConfiguration 并在模板中使用 FBAnnotationClusterDisplayMode.Image(imageName)
  3. 使用不同的库 - https://github.com/efremidze/Cluster

广告 1)

override func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        switch annotation {
        case _ as MyAnnotation:
            // use MKAnnotationView
            let reuseId = "Pin"
            return mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView ?? MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        case let fbAnnotation as FBAnnotationCluster:
            let reuseId = "Cluster"
            let clusterView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) ?? FBAnnotationClusterView(annotation: fbAnnotation, reuseIdentifier: reuseId, configuration: FBAnnotationClusterViewConfiguration.default())
            return clusterView
        default:
            return nil
        }
}

关于swift - Realm map 集群的自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43519560/

相关文章:

ios - Realm 线程困惑

ios - Realm 是否支持模型版本?

ios - Swift 中传递函数时可以绑定(bind)参数值吗?

string - Swift 生成器 : What is the counterpart to next()?

ios 谷歌 api 问题

ios - 如何在 MapKit 中获取可见的叠加层? (即来自 Mapkit View 的 MKOverlay/MKOverlayRenderer)

ios - Swift:如何查找 Realm 数据库包含自定义字符串

ios - PickerView - 如何根据分段控件选择返回 2 个不同的数组

swift - Swift3 函数声明中新的 "for"、 "at"、 "in"关键字是什么?

ios - 缓存图 block 的 MKTileOverlay 子类