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 }