领域地图集群的自定义视图
Custom view for realm map clusters
据我阅读有关地图聚类的领域文档,有一个 class ABFClusterAnnotationView
几乎没有属性:count
、color
、countLabel
但我找不到任何地方 image
进行注释。这是通过添加 image
属性 来 override
的方法吗?我设法通过使用默认注释 iside mapView
委托方法添加 images
但从那里我无法管理集群的数量。我只想在地图上只有 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
}
}
据我阅读有关地图聚类的领域文档,有一个 class ABFClusterAnnotationView
几乎没有属性:count
、color
、countLabel
但我找不到任何地方 image
进行注释。这是通过添加 image
属性 来 override
的方法吗?我设法通过使用默认注释 iside mapView
委托方法添加 images
但从那里我无法管理集群的数量。我只想在地图上只有 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
}
}