From 258cc439effe0494fe9f7a8ccbf524e7de11eac5 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 13 Dec 2016 20:23:45 -0800 Subject: [PATCH 1/2] [ios] Fix dequeue view variable scope --- platform/ios/src/MGLMapView.mm | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index c67105b9e77..a7138ec370e 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -4745,8 +4745,8 @@ - (void)updateAnnotationViews 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,17 @@ - (void)updateAnnotationViews 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]; - + + CGFloat largestHeight = _largestAnnotationViewSize.height; + CGFloat largestWidth = _largestAnnotationViewSize.width; + CGFloat viewHeight = CGRectGetHeight(self.frame); + CGFloat viewWidth = CGRectGetWidth(self.frame); + CLLocationCoordinate2D southwestCoordinate = [self convertPoint:{-largestWidth, viewHeight + largestHeight} + toCoordinateFromView:self]; + CLLocationCoordinate2D northeastCoordinate = [self convertPoint:{viewWidth + largestWidth, -largestHeight} + toCoordinateFromView:self]; + MGLCoordinateBounds coordinateBounds = {southwestCoordinate, northeastCoordinate}; + // Enqueue (and move if required) offscreen annotation views for (id annotation in offscreenAnnotations) { @@ -4795,17 +4798,16 @@ - (void)updateAnnotationViews // 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(adjustedFrame) * 10.0; + annotationView.frame = adjustedFrame; + [self enqueueAnnotationViewForAnnotationContext:annotationContext]; } } } From 8b9448a1e437b9f216a5bbead55da8897075e026 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 13 Dec 2016 22:52:31 -0800 Subject: [PATCH 2/2] Tidy up view wrangling --- platform/ios/src/MGLMapView.mm | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index a7138ec370e..d027b8b4431 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -4766,15 +4766,7 @@ - (void)updateAnnotationViews } } - CGFloat largestHeight = _largestAnnotationViewSize.height; - CGFloat largestWidth = _largestAnnotationViewSize.width; - CGFloat viewHeight = CGRectGetHeight(self.frame); - CGFloat viewWidth = CGRectGetWidth(self.frame); - CLLocationCoordinate2D southwestCoordinate = [self convertPoint:{-largestWidth, viewHeight + largestHeight} - toCoordinateFromView:self]; - CLLocationCoordinate2D northeastCoordinate = [self convertPoint:{viewWidth + largestWidth, -largestHeight} - toCoordinateFromView:self]; - MGLCoordinateBounds coordinateBounds = {southwestCoordinate, northeastCoordinate}; + MGLCoordinateBounds coordinateBounds = [self convertRect:viewPort toCoordinateBoundsFromView:self]; // Enqueue (and move if required) offscreen annotation views for (id annotation in offscreenAnnotations) @@ -4805,7 +4797,7 @@ - (void)updateAnnotationViews else { CGRect adjustedFrame = annotationView.frame; - adjustedFrame.origin.x = -CGRectGetWidth(adjustedFrame) * 10.0; + adjustedFrame.origin.x = CGRectGetWidth(annotationView.layer.presentationLayer.frame) * -2.0; annotationView.frame = adjustedFrame; [self enqueueAnnotationViewForAnnotationContext:annotationContext]; }