Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] Use map view frame to calculate annotation view reuse adjustmen…
Browse files Browse the repository at this point in the history
…ts (#8926)

* [ios] Use map view frame to calculate annotation view reuse adjustments

The value for determining the visible viewport buffer and also the distance to move offscreen an annotation view outside of that buffer was based on the annotation view width and height. This changes that to use the map viewport width and height as constants and avoids a class of bugs where the annotation view would become detached from the tracking system when it did not have a size or was animating from a small to large size.
  • Loading branch information
boundsj committed May 9, 2017
1 parent c69fae9 commit b7b6706
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5012,8 +5012,10 @@ - (void)updateAnnotationViews

// If the map is pitched consider the viewport to be exactly the same as the bounds.
// Otherwise, add a small buffer.
CGFloat widthAdjustment = self.camera.pitch > 0.0 ? 0.0 : -_largestAnnotationViewSize.width * 2.0;
CGFloat heightAdjustment = self.camera.pitch > 0.0 ? 0.0 : -_largestAnnotationViewSize.height * 2.0;
CGFloat largestWidth = MAX(_largestAnnotationViewSize.width, CGRectGetWidth(self.frame));
CGFloat largestHeight = MAX(_largestAnnotationViewSize.height, CGRectGetHeight(self.frame));
CGFloat widthAdjustment = self.camera.pitch > 0.0 ? 0.0 : -largestWidth * 2.0;
CGFloat heightAdjustment = self.camera.pitch > 0.0 ? 0.0 : -largestHeight * 2.0;
CGRect viewPort = CGRectInset(self.bounds, widthAdjustment, heightAdjustment);

NSArray *visibleAnnotations = [self visibleAnnotationsInRect:viewPort];
Expand Down Expand Up @@ -5092,13 +5094,9 @@ - (void)updateAnnotationViews
if (annotationView.layer.animationKeys.count > 0) {
continue;
}
// Move the annotation view far out of view to the left
CGRect adjustedFrame = annotationView.frame;
if (annotationView.layer.presentationLayer) {
adjustedFrame.origin.x = -CGRectGetWidth(annotationView.layer.presentationLayer.frame) * 10.0;
} else {
// views that are added off screen do not have a presentationLayer
adjustedFrame.origin.x = -CGRectGetWidth(adjustedFrame) * 10.0;
}
adjustedFrame.origin.x = -CGRectGetWidth(self.frame) * 10.0;
annotationView.frame = adjustedFrame;
[self enqueueAnnotationViewForAnnotationContext:annotationContext];
}
Expand Down

0 comments on commit b7b6706

Please sign in to comment.