From 922bb3bc37696b736fe383f1347d007a423512f5 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 13 Sep 2016 22:24:37 -0700 Subject: [PATCH] [ios] Use content inset to calculate edge padding (#6313) This reverts a previous change that used only the contentInset when setting the center coordinate of the map view. Instead of contentInset, edgePaddingForFollowing is used. This fixes a regression that caused the user dot annotation to be misplaced when the map was configured to show the annotation in any place other than in the center of the map. In addition, edgePaddingForFollowing is updated to account for contentInset when it calculates its UIEdgeInsets. This fixes a bug where the user dot would move to the center of the content frame (when it was adjusted for content insets) but the map would not scroll along with it yielding the effect of the user dot being misplaced. --- platform/ios/src/MGLMapView.mm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index bf46634ee..273f2715f 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -4085,7 +4085,7 @@ public: - (void)didUpdateLocationIncrementallyAnimated:(BOOL)animated { [self _setCenterCoordinate:self.userLocation.location.coordinate - edgePadding:self.contentInset + edgePadding:self.edgePaddingForFollowing zoomLevel:self.zoomLevel direction:self.directionByFollowingWithCourse duration:animated ? MGLUserLocationAnimationDuration : 0 @@ -4112,7 +4112,7 @@ public: __weak MGLMapView *weakSelf = self; [self _flyToCamera:camera - edgePadding:self.contentInset + edgePadding:self.edgePaddingForFollowing withDuration:animated ? -1 : 0 peakAltitude:-1 completionHandler:^{ @@ -4173,8 +4173,10 @@ public: CGRect boundsAroundCorrectPoint = CGRectOffset(bounds, correctPoint.x - CGRectGetMidX(bounds), correctPoint.y - CGRectGetMidY(bounds)); - return UIEdgeInsetsMake(CGRectGetMinY(boundsAroundCorrectPoint) - CGRectGetMinY(bounds), 0, - CGRectGetMaxY(bounds) - CGRectGetMaxY(boundsAroundCorrectPoint), 0); + return UIEdgeInsetsMake(CGRectGetMinY(boundsAroundCorrectPoint) - CGRectGetMinY(bounds) + self.contentInset.top, + self.contentInset.left, + CGRectGetMaxY(bounds) - CGRectGetMaxY(boundsAroundCorrectPoint) + self.contentInset.bottom, + self.contentInset.right); } /// Returns the edge padding to apply during bifocal course tracking.