diff --git a/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m b/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m index 0b32df55b4d..affea02f4d5 100644 --- a/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m +++ b/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m @@ -396,15 +396,17 @@ - (void)testSelectingAnnotationWithCenterOffset { for (CGFloat dx = -100.0; dx <= 100.0; dx += 100.0 ) { for (CGFloat dy = -100.0; dy <= 100.0; dy += 100.0 ) { CGVector offset = CGVectorMake(dx, dy); - [self internalTestSelectingAnnotationWithCenterOffsetWithOffset:offset]; + UIEdgeInsets edgeInsets = UIEdgeInsetsMake(fmax(-dy, 0.0), fmax(-dy, 0.0), fmax(dy, 0.0), fmax(dx, 0.0)); + [self internalTestSelectingAnnotationWithCenterOffsetWithOffset:offset edgeInsets:edgeInsets]; } } } -- (void)internalTestSelectingAnnotationWithCenterOffsetWithOffset:(CGVector)offset { +- (void)internalTestSelectingAnnotationWithCenterOffsetWithOffset:(CGVector)offset edgeInsets:(UIEdgeInsets)edgeInsets { NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReuseIdentifer"; + self.mapView.contentInset = edgeInsets; CGSize size = self.mapView.bounds.size; CGSize annotationSize = CGSizeMake(40.0, 40.0); @@ -444,8 +446,8 @@ - (void)internalTestSelectingAnnotationWithCenterOffsetWithOffset:(CGVector)offs // Check that the annotation is in the center of the view CGPoint annotationPoint = [self.mapView convertCoordinate:point.coordinate toPointToView:self.mapView]; - XCTAssertEqualWithAccuracy(annotationPoint.x, size.width/2.0, 0.25); - XCTAssertEqualWithAccuracy(annotationPoint.y, size.height/2.0, 0.25); + XCTAssertEqualWithAccuracy(annotationPoint.x, (size.width - edgeInsets.right + edgeInsets.left)/2.0, 0.25); + XCTAssertEqualWithAccuracy(annotationPoint.y, (size.height - edgeInsets.bottom + edgeInsets.top)/2.0, 0.25); // Now test taps around the annotation CGPoint tapPoint = CGPointMake(annotationPoint.x + offset.dx, annotationPoint.y + offset.dy); diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 85a2e3be927..72ea8fac3d3 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -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; @@ -1679,11 +1679,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]; @@ -1741,7 +1737,7 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch [self unrotateIfNeededForGesture]; } - _previousPinchCenterCoordinate = [self convertPoint:centerPoint toCoordinateFromView:self]; + _previousPinchCenterPoint = centerPoint; _previousPinchNumberOfTouches = pinch.numberOfTouches; } diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index f1d45c043c1..92c02d0bc76 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -226,10 +226,6 @@ double TransformState::getMaxZoom() const { return scaleZoom(max_scale); } -ScreenCoordinate TransformState::getCenterOffset() const { - return { 0.5 * (edgeInsets.left() - edgeInsets.right()), 0.5 * (edgeInsets.top() - edgeInsets.bottom()) }; -} - #pragma mark - Rotation float TransformState::getBearing() const { @@ -377,6 +373,10 @@ void TransformState::constrain(double& scale_, double& x_, double& y_) const { } } +ScreenCoordinate TransformState::getCenterOffset() const { + return { 0.5 * (edgeInsets.left() - edgeInsets.right()), 0.5 * (edgeInsets.top() - edgeInsets.bottom()) }; +} + void TransformState::moveLatLng(const LatLng& latLng, const ScreenCoordinate& anchor) { auto centerCoord = Projection::project(getLatLng(LatLng::Unwrapped), scale); auto latLngCoord = Projection::project(latLng, scale); diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index 187d266c8a5..cca42db20f6 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -65,10 +65,6 @@ class TransformState { void setMaxZoom(double); double getMaxZoom() const; - // Viewport center offset, from [size.width / 2, size.height / 2], defined - // by |edgeInsets| in screen coordinates, with top left origin. - ScreenCoordinate getCenterOffset() const; - // Rotation float getBearing() const; float getFieldOfView() const; @@ -100,6 +96,10 @@ class TransformState { bool rotatedNorth() const; void constrain(double& scale, double& x, double& y) const; + // Viewport center offset, from [size.width / 2, size.height / 2], defined + // by |edgeInsets| in screen coordinates, with top left origin. + ScreenCoordinate getCenterOffset() const; + LatLngBounds bounds; // Limit the amount of zooming possible on the map. diff --git a/src/mbgl/text/collision_index.cpp b/src/mbgl/text/collision_index.cpp index e3d832a854b..74923312d5b 100644 --- a/src/mbgl/text/collision_index.cpp +++ b/src/mbgl/text/collision_index.cpp @@ -348,12 +348,11 @@ std::pair CollisionIndex::projectAnchor(const mat4& posMatrix, cons std::pair,float> CollisionIndex::projectAndGetPerspectiveRatio(const mat4& posMatrix, const Point& point) const { vec4 p = {{ point.x, point.y, 0, 1 }}; matrix::transformMat4(p, p, posMatrix); - auto offset = transformState.getCenterOffset(); auto size = transformState.getSize(); return std::make_pair( Point( - (((p[0] / p[3] + 1) / 2) * size.width) + viewportPadding + offset.x, - (((-p[1] / p[3] + 1) / 2) * size.height) + viewportPadding + offset.y + (((p[0] / p[3] + 1) / 2) * size.width) + viewportPadding, + (((-p[1] / p[3] + 1) / 2) * size.height) + viewportPadding ), // See perspective ratio comment in symbol_sdf.vertex // We're doing collision detection in viewport space so we need @@ -365,11 +364,10 @@ std::pair,float> CollisionIndex::projectAndGetPerspectiveRatio(cons Point CollisionIndex::projectPoint(const mat4& posMatrix, const Point& point) const { vec4 p = {{ point.x, point.y, 0, 1 }}; matrix::transformMat4(p, p, posMatrix); - auto offset = transformState.getCenterOffset(); auto size = transformState.getSize(); return Point { - static_cast((((p[0] / p[3] + 1) / 2) * size.width) + viewportPadding + offset.x), - static_cast((((-p[1] / p[3] + 1) / 2) * size.height) + viewportPadding + offset.y) }; + static_cast((((p[0] / p[3] + 1) / 2) * size.width) + viewportPadding), + static_cast((((-p[1] / p[3] + 1) / 2) * size.height) + viewportPadding) }; } } // namespace mbgl