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

Commit

Permalink
[ios][macos] Fix center coordinate incorrect after pinch gesture
Browse files Browse the repository at this point in the history
To changelog:
Fixed incorrect center coordinate after pinch regression caused by edge insets fix (#14664).

While working on #14664, missed to understand the logic used in

```
                CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
                mbgl::EdgeInsets padding { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x };
                self.mbglMap.jumpTo(mbgl::CameraOptions()
                                        .withCenter(MGLLatLngFromLocationCoordinate2D(centerCoordinate))
                                        .withPadding(padding));

```

Replacing this code by moveBy achieves the required translation.

Fixes: #14977, #15082
  • Loading branch information
astojilj authored and friedbunny committed Jul 12, 2019
1 parent a0e2064 commit e874264
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ @implementation MGLMapView

NSInteger _changeDelimiterSuppressionDepth;

/// Center coordinate of the pinch gesture on the previous iteration of the gesture.
CLLocationCoordinate2D _previousPinchCenterCoordinate;
/// Center of the pinch gesture on the previous iteration of the gesture.
CGPoint _previousPinchCenterPoint;
NSUInteger _previousPinchNumberOfTouches;

CLLocationDistance _distanceFromOldUserLocation;
Expand Down Expand Up @@ -1643,11 +1643,7 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch
// meaningless.
if (self.userTrackingMode == MGLUserTrackingModeNone && pinch.numberOfTouches == _previousPinchNumberOfTouches)
{
CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
mbgl::EdgeInsets padding { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x };
self.mbglMap.jumpTo(mbgl::CameraOptions()
.withCenter(MGLLatLngFromLocationCoordinate2D(centerCoordinate))
.withPadding(padding));
self.mbglMap.moveBy({centerPoint.x - _previousPinchCenterPoint.x, centerPoint.y - _previousPinchCenterPoint.y});
}
}
[self cameraIsChanging];
Expand Down Expand Up @@ -1705,7 +1701,7 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch
[self unrotateIfNeededForGesture];
}

_previousPinchCenterCoordinate = [self convertPoint:centerPoint toCoordinateFromView:self];
_previousPinchCenterPoint = centerPoint;
_previousPinchNumberOfTouches = pinch.numberOfTouches;
}

Expand Down

0 comments on commit e874264

Please sign in to comment.