据我阅读有关 map 聚类的 Realm 文档,有一个类 ABFClusterAnnotationView
,它有几个属性:count
、color
、countLabel
但我无法在任何地方找到 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
}
提前致谢!
最佳答案
恕我直言,图像属性未被覆盖。但无论如何你还有几个选择:
- 不要使用
ABFClusterAnnotationView
。 (使用例如MKAnnotationView
) - 使用
FBAnnotationClusterView
, 设置FBAnnotationClusterViewConfiguration
并在模板中使用FBAnnotationClusterDisplayMode.Image(imageName)
- 使用不同的库 - 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/