From 3995d6ff68a51dd4543ad71f424adf261e1e8baf Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Tue, 21 Jun 2016 15:21:22 +0200 Subject: [PATCH] [ios] fixes #5406 view for annotation (#5413) --- platform/ios/src/MGLMapView.h | 9 +++++++++ platform/ios/src/MGLMapView.mm | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 1319228c1..d6bc25f96 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -951,6 +951,15 @@ IB_DESIGNABLE */ - (void)removeAnnotations:(NS_ARRAY_OF(id ) *)annotations; +/** + Returns an `MGLAnnotationView` if the given annotation is currently associated + with a view, otherwise nil. + + @param annotation The annotation associated with the view. + Annotation must conform to the `MGLAnnotation` protocol. + */ +- (nullable MGLAnnotationView *)viewForAnnotation:(id )annotation; + /** Returns a reusable annotation image object associated with its identifier. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index a1a412af0..7f09113f5 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2984,6 +2984,15 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) return annotationView; } +- (nullable MGLAnnotationView *)viewForAnnotation:(id)annotation +{ + MGLAnnotationTag annotationTag = [self annotationTagForAnnotation:annotation]; + if (annotationTag == MGLAnnotationTagNotFound) return nil; + + MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag); + return annotationContext.annotationView; +} + - (double)alphaForShapeAnnotation:(MGLShape *)annotation { if (_delegateHasAlphasForShapeAnnotations)