From c6abc0ea89f2e44258f43aa4c3c6e00b1b8b04f7 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 27 Sep 2016 13:49:54 -0700 Subject: [ios] Always show annotation view even when view reuse is not used This fixes an issue where the map view would drop annotation views if the developer did not make full use of the reuse queue. The fixes are: - Guard against enqueuing a view for reuse if it does not have a `viewReuseIdentifier`. Previously, if the app developer created a new annotation view with no reuse id each time `[MGLMapViewDelegate mapView:viewForAnnotation:]` was called and then the view was scrolled offscreen, we attempted to add the view to the reuse queue (for no good reason) and did not update the views center ever again. This change avoids the reuse queue and just updates the center always. - Add any annotation view that should be displayed but is not in the annotation container view to the annotation container view. Previously, if the app developer created a new annotation view with a reuse id each time `[MGLMapViewDelegate mapView:viewForAnnotation:]` was called, and then if the annotation was scrolled off and then on screen again, we did not add the new view to the container view because it was not happening in the normal `addAnnotation` cycle. This adds add logic to catch that case and add annotation views created in this way to the view. --- platform/ios/src/MGLMapView.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 273f2715fa..f2a365f455 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -4572,6 +4572,10 @@ public: annotationView.mapView = self; annotationView.center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self]; annotationContext.annotationView = annotationView; + + if (!annotationView.superview) { + [self.annotationContainerView insertSubview:annotationView atIndex:0]; + } } else { @@ -4581,7 +4585,7 @@ public: } bool annotationViewIsVisible = CGRectContainsRect(viewPort, annotationView.frame); - if (!annotationViewIsVisible) + if (!annotationViewIsVisible && annotationContext.viewReuseIdentifier) { [self enqueueAnnotationViewForAnnotationContext:annotationContext]; } -- cgit v1.2.1