I want to get the aggregated data of the point annotation when the point annotation is aggregated, and assign the aggregated data to the bound view annotation. MapBox SDK for iOS version: v10.13.0
I create a PointAnnotationManager
private var pointAnnotationManager: PointAnnotationManager!
let clusterLayerID: String = "clusterLayerID_mark"
private func createPointAnnotationManager() {
let circleColorExpression = Exp(.step) {
Exp(.get) {"point_count"}
UIColor.clear
}
// Create expression to get the total count of hydrants in a cluster
let sumExpression = Exp {
Exp(.sum) {
Exp(.accumulated)
Exp(.get) { "sum" }
}
1
}
// Create a cluster property to add to each cluster
let clusterProperties: [String: Expression] = [
"sum": sumExpression
]
// If a feature has the point_count property then prepend "Count:" and display the sum of hydrants in the cluster
// The sum property is added here for demonstration, you can use the built-in "point_count"
// property instead: Exp(.get) {"point_count"}
let textFieldExpression = Exp(.switchCase) {
Exp(.has) { "point_count" }
Exp(.concat) {
Exp(.string) { "Count:\n" }
Exp(.get) {"sum"}
}
Exp(.string) { "" }
}
let clusterOptions = ClusterOptions(circleRadius: .constant(30),
circleColor: .expression(circleColorExpression),
textColor: .constant(StyleColor(.black)),
textField: .expression(textFieldExpression),
clusterRadius: 80,
clusterProperties: clusterProperties)
pointAnnotationManager = mapView.annotations.makePointAnnotationManager(id: clusterLayerID, clusterOptions: clusterOptions)
pointAnnotationManager.delegate = self
}
And I attach view annotation to a point annotation:
public func addClusterAnnotations(annotationView: AnnotationViewType, viewId markerId: String, at coordinate: CLLocationCoordinate2D) {
// prepare point annotation
var pointAnnotation = PointAnnotation(coordinate: coordinate)
pointAnnotation.iconAnchor = .bottom
pointAnnotationManager.annotations.append(pointAnnotation)
// prepare view annotation and connect it by feature id
let options = ViewAnnotationOptions(
geometry: Point(coordinate),
associatedFeatureId: pointAnnotation.id,
anchor: .bottom,
offsetY: 0
)
try? mapView.viewAnnotations.add(annotationView, options: options)
}
How to know when the point annotation aggregates,and get the aggregated data?