From 8afc68bbe4cdb81bbb758ea9d6f3e7880738fbbd Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Thu, 3 Nov 2016 18:19:55 -0700 Subject: [PATCH] [ios] Store annotation tags for MGLMultiPoint annotations in the map (#6888) * [ios] Store annotation tags for MGLMultiPoint annotations in the map This fixes an issue where, if a multipoint annotation was added, native annotation view update logic would crash. Adding the annotation tag for multipoints, too, avoids the out of range exception. This also adds a check for MGLMultiPoint for offscreen annotations for consistency with the onscreen case. --- platform/ios/src/MGLMapView.mm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 9206036a6..25a9b8518 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2915,6 +2915,7 @@ public: MGLAnnotationContext context; context.annotation = annotation; _annotationContextsByAnnotationTag[annotationTag] = context; + _annotationTagsByAnnotation[annotation] = annotationTag; [(NSObject *)annotation addObserver:self forKeyPath:@"coordinates" options:0 context:(void *)(NSUInteger)annotationTag]; } @@ -4704,13 +4705,19 @@ public: // Enqueue (and move if required) offscreen annotation views for (id annotation in offscreenAnnotations) { - CLLocationCoordinate2D coordinate = annotation.coordinate; + // Defer to the shape/polygon styling delegate methods + if ([annotation isKindOfClass:[MGLMultiPoint class]]) + { + continue; + } + MGLAnnotationTag annotationTag = _annotationTagsByAnnotation.at(annotation); MGLAnnotationContext &annotationContext = _annotationContextsByAnnotationTag.at(annotationTag); UIView *annotationView = annotationContext.annotationView; if (annotationView) { + CLLocationCoordinate2D coordinate = annotation.coordinate; // Every so often (1 out of 1000 frames?) the mbgl query mechanism fails. This logic spot checks the // offscreenAnnotations values -- if they are actually still on screen then the view center is // moved and the enqueue operation is avoided. This allows us to keep the performance benefit of