From 73ac3c784fe755650dc631e2e722a47890981248 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 28 Feb 2019 12:27:12 +0200 Subject: [core] Remove map bearing setters/getters --- include/mbgl/map/map.hpp | 6 ------ platform/android/src/native_map_view.cpp | 10 +++++----- platform/glfw/glfw_view.cpp | 10 ++++++---- platform/ios/src/MGLMapView.mm | 30 +++++++++++++++++++----------- platform/macos/src/MGLMapView.mm | 19 +++++++++++-------- platform/node/src/node_map.cpp | 2 +- platform/qt/src/qmapboxgl.cpp | 10 +++++++--- src/mbgl/map/map.cpp | 20 -------------------- test/api/annotations.test.cpp | 2 +- 9 files changed, 50 insertions(+), 59 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 5674902fe9..dfb1164cc0 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -100,12 +100,6 @@ public: // Rotation void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {}); - void setBearing(double degrees, const AnimationOptions& = {}); - void setBearing(double degrees, optional, const AnimationOptions& = {}); - void setBearing(double degrees, const EdgeInsets&, const AnimationOptions& = {}); - double getBearing() const; - void resetNorth(const AnimationOptions& = {{mbgl::Milliseconds(500)}}); - void resetNorth(const EdgeInsets&, const AnimationOptions& = {{mbgl::Milliseconds(500)}}); // North Orientation void setNorthOrientation(NorthOrientation); diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 94bcbe3cab..7cea8b00d7 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -439,20 +439,20 @@ void NativeMapView::rotateBy(jni::JNIEnv&, jni::jdouble sx, jni::jdouble sy, jni } void NativeMapView::setBearing(jni::JNIEnv&, jni::jdouble degrees, jni::jlong duration) { - map->setBearing(degrees, mbgl::AnimationOptions{mbgl::Milliseconds(duration)}); + map->easeTo(mbgl::CameraOptions().withAngle(degrees), mbgl::AnimationOptions{mbgl::Milliseconds(duration)}); } void NativeMapView::setBearingXY(jni::JNIEnv&, jni::jdouble degrees, jni::jdouble cx, jni::jdouble cy, jni::jlong duration) { - mbgl::ScreenCoordinate center(cx, cy); - map->setBearing(degrees, center, mbgl::AnimationOptions{mbgl::Milliseconds(duration)}); + mbgl::ScreenCoordinate anchor(cx, cy); + map->easeTo(mbgl::CameraOptions().withAngle(degrees).withAnchor(anchor), mbgl::AnimationOptions{mbgl::Milliseconds(duration)}); } jni::jdouble NativeMapView::getBearing(jni::JNIEnv&) { - return map->getBearing(); + return *map->getCameraOptions().angle; } void NativeMapView::resetNorth(jni::JNIEnv&) { - map->resetNorth(); + map->easeTo(mbgl::CameraOptions().withAngle(0.0), mbgl::AnimationOptions {{mbgl::Milliseconds(500)}}); } void NativeMapView::setVisibleCoordinateBounds(JNIEnv& env, const jni::Array>& coordinates, const jni::Object& padding, jdouble direction, jni::jlong duration) { diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index 78239bb97b..d222112aa2 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -209,7 +209,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, #endif // MBGL_USE_GLES2 case GLFW_KEY_N: if (!mods) - view->map->resetNorth(); + view->map->easeTo(mbgl::CameraOptions().withAngle(0.0), mbgl::AnimationOptions {{mbgl::Milliseconds(500)}}); break; case GLFW_KEY_Z: view->nextOrientation(); @@ -267,13 +267,15 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, routeProgress = 0.0; } + auto camera = routeMap->getCameraOptions(); + auto point = ruler.along(lineString, routeProgress * routeDistance); const mbgl::LatLng center { point.y, point.x }; - auto latLng = routeMap->getLatLng(); + auto latLng = *camera.center; double bearing = ruler.bearing({ latLng.longitude(), latLng.latitude() }, point); - double easing = bearing - routeMap->getBearing(); + double easing = bearing - *camera.angle; easing += easing > 180.0 ? -360.0 : easing < -180 ? 360.0 : 0; - bearing = routeMap->getBearing() + (easing / 20); + bearing = *camera.angle + (easing / 20); routeMap->jumpTo(mbgl::CameraOptions().withCenter(center).withZoom(18.0).withAngle(bearing).withPitch(60.0)); }; view->animateRouteCallback(view->map); diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index a7f201e8cf..353f87ad70 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1775,7 +1775,7 @@ public: { [self trackGestureEvent:MMEEventGestureRotateStart forRecognizer:rotate]; - self.angle = MGLRadiansFromDegrees(self.mbglMap.getBearing()) * -1; + self.angle = MGLRadiansFromDegrees(*self.mbglMap.getCameraOptions().angle) * -1; if (self.userTrackingMode != MGLUserTrackingModeNone) { @@ -1802,7 +1802,9 @@ public: if ([self _shouldChangeFromCamera:oldCamera toCamera:toCamera]) { - self.mbglMap.setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }); + self.mbglMap.jumpTo(mbgl::CameraOptions() + .withAngle(newDegrees) + .withAnchor(mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y})); } [self cameraIsChanging]; @@ -1837,8 +1839,11 @@ public: if ([self _shouldChangeFromCamera:oldCamera toCamera:toCamera]) { - self.mbglMap.setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationFromTimeInterval(decelerationRate)); - + self.mbglMap.easeTo(mbgl::CameraOptions() + .withAngle(newDegrees) + .withAnchor(mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }), + MGLDurationFromTimeInterval(decelerationRate)); + [self notifyGestureDidEndWithDrift:YES]; __weak MGLMapView *weakSelf = self; @@ -3486,7 +3491,7 @@ public: - (CLLocationDirection)direction { - return mbgl::util::wrap(self.mbglMap.getBearing(), 0., 360.); + return *self.mbglMap.getCameraOptions().angle; } - (void)setDirection:(CLLocationDirection)direction animated:(BOOL)animated @@ -3518,15 +3523,18 @@ public: if (self.userTrackingMode == MGLUserTrackingModeNone) { - self.mbglMap.setBearing(direction, - MGLEdgeInsetsFromNSEdgeInsets(self.contentInset), - MGLDurationFromTimeInterval(duration)); + self.mbglMap.easeTo(mbgl::CameraOptions() + .withAngle(direction) + .withPadding(MGLEdgeInsetsFromNSEdgeInsets(self.contentInset)), + MGLDurationFromTimeInterval(duration)); } else { - CGPoint centerPoint = self.userLocationAnnotationViewCenter; - self.mbglMap.setBearing(direction, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, - MGLDurationFromTimeInterval(duration)); + CGPoint anchor = self.userLocationAnnotationViewCenter; + self.mbglMap.easeTo(mbgl::CameraOptions() + .withAngle(direction) + .withAnchor(mbgl::ScreenCoordinate { anchor.x, anchor.y }), + MGLDurationFromTimeInterval(duration)); } } diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 21aa2c3bef..c27cfee775 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1124,7 +1124,7 @@ public: } - (CLLocationDirection)direction { - return mbgl::util::wrap(_mbglMap->getBearing(), 0., 360.); + return *_mbglMap->getCameraOptions().angle; } - (void)setDirection:(CLLocationDirection)direction { @@ -1135,14 +1135,15 @@ public: - (void)setDirection:(CLLocationDirection)direction animated:(BOOL)animated { MGLLogDebug(@"Setting direction: %f animated: %@", direction, MGLStringFromBOOL(animated)); [self willChangeValueForKey:@"direction"]; - _mbglMap->setBearing(direction, - MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets), - MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0)); + _mbglMap->easeTo(mbgl::CameraOptions() + .withAngle(direction) + .withPadding(MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets)), + MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0)); [self didChangeValueForKey:@"direction"]; } - (void)offsetDirectionBy:(CLLocationDegrees)delta animated:(BOOL)animated { - [self setDirection:_mbglMap->getBearing() + delta animated:animated]; + [self setDirection:*_mbglMap->getCameraOptions().angle + delta animated:animated]; } + (NSSet *)keyPathsForValuesAffectingCamera { @@ -1486,7 +1487,7 @@ public: if (self.rotateEnabled) { CLLocationDirection newDirection = _directionAtBeginningOfGesture - delta.x / 10; [self willChangeValueForKey:@"direction"]; - _mbglMap->setBearing(newDirection, center); + _mbglMap->jumpTo(mbgl::CameraOptions().withAngle(newDirection).withAnchor(center)); didChangeCamera = YES; [self didChangeValueForKey:@"direction"]; } @@ -1623,8 +1624,10 @@ public: MGLMapCamera *oldCamera = self.camera; NSPoint rotationPoint = [gestureRecognizer locationInView:self]; - mbgl::ScreenCoordinate center(rotationPoint.x, self.bounds.size.height - rotationPoint.y); - _mbglMap->setBearing(_directionAtBeginningOfGesture + gestureRecognizer.rotationInDegrees, center); + mbgl::ScreenCoordinate anchor(rotationPoint.x, self.bounds.size.height - rotationPoint.y); + _mbglMap->jumpTo(mbgl::CameraOptions() + .withAngle(_directionAtBeginningOfGesture + gestureRecognizer.rotationInDegrees) + .withAnchor(anchor)); if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] && ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:self.camera]) { diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index f1a29145cf..74201554dd 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -976,7 +976,7 @@ void NodeMap::SetBearing(const Nan::FunctionCallbackInfo& info) { } try { - nodeMap->map->setBearing(info[0]->NumberValue()); + nodeMap->map->jumpTo(mbgl::CameraOptions().withAngle(info[0]->NumberValue())); } catch (const std::exception &ex) { return Nan::ThrowError(ex.what()); } diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index cdeb4a962a..3f3b40b7a8 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -855,17 +855,21 @@ void QMapboxGL::jumpTo(const QMapboxGLCameraOptions& camera) */ double QMapboxGL::bearing() const { - return d_ptr->mapObj->getBearing(); + return *d_ptr->mapObj->getCameraOptions().angle; } void QMapboxGL::setBearing(double degrees) { - d_ptr->mapObj->setBearing(degrees, d_ptr->margins); + d_ptr->mapObj->jumpTo(mbgl::CameraOptions() + .withAngle(degrees) + .withPadding(d_ptr->margins)); } void QMapboxGL::setBearing(double degrees, const QPointF ¢er) { - d_ptr->mapObj->setBearing(degrees, mbgl::ScreenCoordinate { center.x(), center.y() }); + d_ptr->mapObj->jumpTo(mbgl::CameraOptions() + .withAngle(degrees) + .withAnchor(mbgl::ScreenCoordinate { center.x(), center.y() })); } /*! diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index c3e5edc688..d7a1020262 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -369,26 +369,6 @@ void Map::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second impl->onUpdate(); } -void Map::setBearing(double degrees, const AnimationOptions& animation) { - easeTo(CameraOptions().withAngle(degrees), animation); -} - -void Map::setBearing(double degrees, optional anchor, const AnimationOptions& animation) { - return easeTo(CameraOptions().withAngle(degrees).withAnchor(anchor), animation); -} - -void Map::setBearing(double degrees, const EdgeInsets& padding, const AnimationOptions& animation) { - easeTo(CameraOptions().withAngle(degrees).withPadding(padding), animation); -} - -double Map::getBearing() const { - return -impl->transform.getAngle() * util::RAD2DEG; -} - -void Map::resetNorth(const AnimationOptions& animation) { - easeTo(CameraOptions().withAngle(0.0), animation); -} - #pragma mark - North Orientation void Map::setNorthOrientation(NorthOrientation orientation) { diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp index c0c4f38cf9..a4534825a5 100644 --- a/test/api/annotations.test.cpp +++ b/test/api/annotations.test.cpp @@ -418,7 +418,7 @@ TEST(Annotations, VisibleFeatures) { } // Change bearing *after* adding annotations causes them to be reordered. - test.map.setBearing(45); + test.map.jumpTo(CameraOptions().withAngle(45.0)); test.frontend.render(test.map); auto features = test.frontend.getRenderer()->queryRenderedFeatures(box, {}); -- cgit v1.2.1