From 3eed43ceaf7892a4021a34f87da2e6561e50318c Mon Sep 17 00:00:00 2001 From: Paul Kraft Date: Mon, 27 Feb 2023 23:17:14 +0100 Subject: [PATCH] Correctly register cluster annotation views --- Sources/Map/Map+Coordinator.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/Map/Map+Coordinator.swift b/Sources/Map/Map+Coordinator.swift index 205c5a1..ec2c6c0 100644 --- a/Sources/Map/Map+Coordinator.swift +++ b/Sources/Map/Map+Coordinator.swift @@ -303,16 +303,18 @@ extension Map { if let content = annotationContentByObject[ObjectIdentifier(annotation)] { return content.view(for: mapView) } else if let clusterAnnotation = annotation as? MKClusterAnnotation { - let content = clusterAnnotation.memberAnnotations.compactMap { annotation -> AnnotationItems.Element? in + let members = clusterAnnotation.memberAnnotations.compactMap { annotation -> AnnotationItems.Element? in guard let item = annotationItemByObject[ObjectIdentifier(annotation)] else { assertionFailure("Somehow a cluster contains an unknown annotation item.") return nil } return item } - return view? - .clusterAnnotation(clusterAnnotation, content)? - .view(for: mapView) + guard let content = view?.clusterAnnotation(clusterAnnotation, members) else { + return nil + } + registerAnnotationViewIfNeeded(on: mapView, for: content) + return content.view(for: mapView) } else { return nil }