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

Commit

Permalink
[ios] Fix up center coordinate after lopsided pinch gesture
Browse files Browse the repository at this point in the history
The gesture recognizer only reports the gesture’s current center point, so use the previous center point to anchor the transition.

Fixes #4315.
  • Loading branch information
1ec5 committed Mar 22, 2016
1 parent bbe13b8 commit b57f0fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Known issues:
- Tiles and other resources are cached in the same file that holds offline resources. The combined cache file is located in a subdirectory of the user’s Application Support directory, which means iOS will not delete the file when disk space runs low. ([#4377](https://github.com/mapbox/mapbox-gl-native/pull/4377))
- The user dot no longer disappears after panning the map across the antimeridian at low zoom levels. ([#4275](https://github.com/mapbox/mapbox-gl-native/pull/4275))
- The map no longer recoils when panning quickly at low zoom levels. ([#4214](https://github.com/mapbox/mapbox-gl-native/pull/4214))
- Fixed an issue causing the map to pan the wrong way when the user pinches unevenly. ([#4427](https://github.com/mapbox/mapbox-gl-native/pull/4427))
- An icon laid out along a line no longer appears if it would extend past the end of the line. Some one-way arrows no longer point the wrong way. ([#3839](https://github.com/mapbox/mapbox-gl-native/pull/3839))
- Fixed warping of dashed lines near sharp corners. ([#3914](https://github.com/mapbox/mapbox-gl-native/pull/3914))
- Telemetry location gathering now occurs only when the device is in motion. ([#4115](https://github.com/mapbox/mapbox-gl-native/pull/4115))
Expand Down
18 changes: 18 additions & 0 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ @implementation MGLMapView

NSUInteger _changeDelimiterSuppressionDepth;

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

BOOL _delegateHasAlphasForShapeAnnotations;
BOOL _delegateHasStrokeColorsForShapeAnnotations;
BOOL _delegateHasFillColorsForShapeAnnotations;
Expand Down Expand Up @@ -1133,6 +1137,17 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch
if (log2(newScale) < _mbglMap->getMinZoom()) return;

_mbglMap->setScale(newScale, { centerPoint.x, centerPoint.y });

// The gesture recognizer only reports the gesture’s current center
// point, so use the previous center point to anchor the transition.
// If the number of touches has changed, the remembered center point is
// meaningless.
if (self.userTrackingMode == MGLUserTrackingModeNone && pinch.numberOfTouches == _previousPinchNumberOfTouches)
{
CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
_mbglMap->setLatLng(MGLLatLngFromLocationCoordinate2D(centerCoordinate),
{ centerPoint.x, centerPoint.y });
}

[self notifyMapChange:mbgl::MapChangeRegionIsChanging];
}
Expand Down Expand Up @@ -1176,6 +1191,9 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch

[self unrotateIfNeededForGesture];
}

_previousPinchCenterCoordinate = [self convertPoint:[pinch locationInView:pinch.view] toCoordinateFromView:self];
_previousPinchNumberOfTouches = pinch.numberOfTouches;
}

- (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
Expand Down

0 comments on commit b57f0fb

Please sign in to comment.