From afd14cbfe5dea97c66e53da7ac2adaa16d969356 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Wed, 14 Dec 2016 10:24:06 -0800 Subject: [ios] Fix dequeue view variable scope (#7423) Fix a bug where an annotation view variable was incorrectly re-declared which caused annotation views to not appear in some cases. This also refactors the guard that spot checks that annotation view are or are not visible. --- platform/ios/src/MGLMapView.mm | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'platform') diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 14f17dab8c..b01ab09fb4 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -4745,8 +4745,8 @@ public: if (!annotationView) { // This will dequeue views if the delegate implements the dequeue call - MGLAnnotationView *annotationView = [self annotationViewForAnnotation:annotationContext.annotation]; - + annotationView = [self annotationViewForAnnotation:annotationContext.annotation]; + if (annotationView) { annotationView.mapView = self; @@ -4765,14 +4765,9 @@ public: annotationView.center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self]; } } - - CGPoint upperLeft = {_largestAnnotationViewSize.width,_largestAnnotationViewSize.height}; - CGPoint lowerRight = {CGRectGetWidth(self.bounds) + _largestAnnotationViewSize.width, - CGRectGetHeight(self.bounds) + _largestAnnotationViewSize.height}; - - CLLocationCoordinate2D upperLeftCoordinate = [self convertPoint:upperLeft toCoordinateFromView:self]; - CLLocationCoordinate2D lowerRightCoordinate = [self convertPoint:lowerRight toCoordinateFromView:self]; - + + MGLCoordinateBounds coordinateBounds = [self convertRect:viewPort toCoordinateBoundsFromView:self]; + // Enqueue (and move if required) offscreen annotation views for (id annotation in offscreenAnnotations) { @@ -4795,17 +4790,16 @@ public: // moved and the enqueue operation is avoided. This allows us to keep the performance benefit of // using the mbgl query result. It also forces views that have just gone offscreen to be cleared // fully from view. - if ((coordinate.latitude > upperLeftCoordinate.latitude || coordinate.latitude < lowerRightCoordinate.latitude) || - (coordinate.longitude < upperLeftCoordinate.longitude || coordinate.longitude > lowerRightCoordinate.longitude)) + if (MGLCoordinateInCoordinateBounds(coordinate, coordinateBounds)) { - CGRect adjustedFrame = annotationView.frame; - adjustedFrame.origin.x = -CGRectGetWidth(adjustedFrame) * 2.0; - annotationView.frame = adjustedFrame; - [self enqueueAnnotationViewForAnnotationContext:annotationContext]; + annotationView.center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self]; } else { - annotationView.center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self]; + CGRect adjustedFrame = annotationView.frame; + adjustedFrame.origin.x = CGRectGetWidth(annotationView.layer.presentationLayer.frame) * -2.0; + annotationView.frame = adjustedFrame; + [self enqueueAnnotationViewForAnnotationContext:annotationContext]; } } } -- cgit v1.2.1