diff options
-rw-r--r-- | include/mbgl/map/map.hpp | 4 | ||||
-rwxr-xr-x | platform/android/src/native_map_view.cpp | 7 | ||||
-rw-r--r-- | platform/default/src/mbgl/map/map_snapshotter.cpp | 2 | ||||
-rw-r--r-- | platform/glfw/glfw_view.cpp | 2 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 10 | ||||
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 11 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 2 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 14 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 20 | ||||
-rw-r--r-- | test/map/map.test.cpp | 6 |
10 files changed, 31 insertions, 47 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index dfb1164cc0..3d7223308b 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -75,10 +75,6 @@ public: // Position void moveBy(const ScreenCoordinate&, const AnimationOptions& = {}); - void setLatLng(const LatLng&, const EdgeInsets&, const AnimationOptions& = {}); - void setLatLng(const LatLng&, const AnimationOptions& = {}); - LatLng getLatLng(const EdgeInsets& = {}) const; - void resetPosition(const EdgeInsets& = {}); // Zoom void scaleBy(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation = {}); diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 050a5eaaaa..d8eba09e9a 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -366,11 +366,12 @@ void NativeMapView::flyTo(jni::JNIEnv&, jni::jdouble bearing, jni::jdouble latit } jni::Local<jni::Object<LatLng>> NativeMapView::getLatLng(JNIEnv& env) { - return LatLng::New(env, map->getLatLng(insets)); + return LatLng::New(env, *map->getCameraOptions(insets).center); } void NativeMapView::setLatLng(jni::JNIEnv&, jni::jdouble latitude, jni::jdouble longitude, jni::jlong duration) { - map->setLatLng(mbgl::LatLng(latitude, longitude), insets, mbgl::AnimationOptions{mbgl::Milliseconds(duration)}); + map->easeTo(mbgl::CameraOptions().withCenter(mbgl::LatLng(latitude, longitude)).withPadding(insets), + mbgl::AnimationOptions{mbgl::Milliseconds(duration)}); } jni::Local<jni::Object<CameraPosition>> NativeMapView::getCameraForLatLngBounds(jni::JNIEnv& env, const jni::Object<LatLngBounds>& jBounds, double top, double left, double bottom, double right, double bearing, double tilt) { @@ -391,7 +392,7 @@ void NativeMapView::setReachability(jni::JNIEnv&, jni::jboolean reachable) { } void NativeMapView::resetPosition(jni::JNIEnv&) { - map->resetPosition(); + map->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng {}).withZoom(0.0).withBearing(0.0).withPitch(0.0)); } jni::jdouble NativeMapView::getPitch(jni::JNIEnv&) { diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp index ae14b20721..926c51b60f 100644 --- a/platform/default/src/mbgl/map/map_snapshotter.cpp +++ b/platform/default/src/mbgl/map/map_snapshotter.cpp @@ -82,7 +82,7 @@ void MapSnapshotter::Impl::snapshot(ActorRef<MapSnapshotter::Callback> callback) // and can be used to translate for geographic to screen // coordinates assert (frontend.getTransformState()); - PointForFn pointForFn { [=, center=map.getLatLng(), transformState = *frontend.getTransformState()] (const LatLng& latLng) { + PointForFn pointForFn { [=, center = *map.getCameraOptions().center, transformState = *frontend.getTransformState()] (const LatLng& latLng) { LatLng unwrappedLatLng = latLng.wrapped(); unwrappedLatLng.unwrapForShortestPath(center); Transform transform { transformState }; diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index 64c9eb495e..dc5e6b1ecd 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -184,7 +184,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, break; case GLFW_KEY_X: if (!mods) - view->map->resetPosition(); + view->map->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng {}).withZoom(0.0).withBearing(0.0).withPitch(0.0)); break; case GLFW_KEY_O: view->onlineStatusCallback(); diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 3de6e06e4d..3eeffb9cbd 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1697,8 +1697,10 @@ public: if (self.userTrackingMode == MGLUserTrackingModeNone && pinch.numberOfTouches == _previousPinchNumberOfTouches) { CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate; - self.mbglMap.setLatLng(MGLLatLngFromLocationCoordinate2D(centerCoordinate), - mbgl::EdgeInsets { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x }); + 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 cameraIsChanging]; @@ -3177,7 +3179,7 @@ public: - (CLLocationCoordinate2D)centerCoordinate { mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); - return MGLLocationCoordinate2DFromLatLng(self.mbglMap.getLatLng(padding)); + return MGLLocationCoordinate2DFromLatLng(*self.mbglMap.getCameraOptions(padding).center); } - (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel animated:(BOOL)animated @@ -3795,7 +3797,7 @@ public: } mbgl::CameraOptions mapCamera = self.mbglMap.getCameraOptions(); - CLLocationCoordinate2D centerCoordinate = MGLLocationCoordinate2DFromLatLng(cameraOptions.center ? *cameraOptions.center : self.mbglMap.getLatLng()); + CLLocationCoordinate2D centerCoordinate = MGLLocationCoordinate2DFromLatLng(cameraOptions.center ? *cameraOptions.center : *mapCamera.center); double zoomLevel = cameraOptions.zoom ? *cameraOptions.zoom : self.zoomLevel; CLLocationDirection direction = cameraOptions.bearing ? mbgl::util::wrap(*cameraOptions.bearing, 0., 360.) : self.direction; CGFloat pitch = cameraOptions.pitch ? *cameraOptions.pitch : *mapCamera.pitch; diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 5f613922d8..8ebf6356cb 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -996,7 +996,7 @@ public: - (CLLocationCoordinate2D)centerCoordinate { mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); - return MGLLocationCoordinate2DFromLatLng(_mbglMap->getLatLng(padding)); + return MGLLocationCoordinate2DFromLatLng(*_mbglMap->getCameraOptions(padding).center); } - (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate { @@ -1007,9 +1007,10 @@ public: - (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate animated:(BOOL)animated { MGLLogDebug(@"Setting centerCoordinate: %@ animated: %@", MGLStringFromCLLocationCoordinate2D(centerCoordinate), MGLStringFromBOOL(animated)); [self willChangeValueForKey:@"centerCoordinate"]; - _mbglMap->setLatLng(MGLLatLngFromLocationCoordinate2D(centerCoordinate), - MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets), - MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0)); + _mbglMap->easeTo(mbgl::CameraOptions() + .withCenter(MGLLatLngFromLocationCoordinate2D(centerCoordinate)) + .withPadding(MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets)), + MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0)); [self didChangeValueForKey:@"centerCoordinate"]; } @@ -1359,7 +1360,7 @@ public: - (MGLMapCamera *)cameraForCameraOptions:(const mbgl::CameraOptions &)cameraOptions { mbgl::CameraOptions mapCamera = _mbglMap->getCameraOptions(); - CLLocationCoordinate2D centerCoordinate = MGLLocationCoordinate2DFromLatLng(cameraOptions.center ? *cameraOptions.center : _mbglMap->getLatLng()); + CLLocationCoordinate2D centerCoordinate = MGLLocationCoordinate2DFromLatLng(cameraOptions.center ? *cameraOptions.center : *mapCamera.center); double zoomLevel = cameraOptions.zoom ? *cameraOptions.zoom : self.zoomLevel; CLLocationDirection direction = cameraOptions.bearing ? mbgl::util::wrap(*cameraOptions.bearing, 0., 360.) : self.direction; CGFloat pitch = cameraOptions.pitch ? *cameraOptions.pitch : *mapCamera.pitch; diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index a685c2a12e..068fc57a5c 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -942,7 +942,7 @@ void NodeMap::SetCenter(const Nan::FunctionCallbackInfo<v8::Value>& info) { if (center->Length() > 1) { latitude = Nan::Get(center, 1).ToLocalChecked()->NumberValue(); } try { - nodeMap->map->setLatLng(mbgl::LatLng { latitude, longitude }); + nodeMap->map->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng { latitude, longitude })); } 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 02c38e209d..7ed8f04007 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -685,12 +685,12 @@ void QMapboxGL::setStyleUrl(const QString &url) */ double QMapboxGL::latitude() const { - return d_ptr->mapObj->getLatLng(d_ptr->margins).latitude(); + return d_ptr->mapObj->getCameraOptions(d_ptr->margins).center->latitude(); } void QMapboxGL::setLatitude(double latitude_) { - d_ptr->mapObj->setLatLng(mbgl::LatLng { latitude_, longitude() }, d_ptr->margins); + d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng { latitude_, longitude() }).withPadding(d_ptr->margins)); } /*! @@ -703,12 +703,12 @@ void QMapboxGL::setLatitude(double latitude_) */ double QMapboxGL::longitude() const { - return d_ptr->mapObj->getLatLng(d_ptr->margins).longitude(); + return d_ptr->mapObj->getCameraOptions(d_ptr->margins).center->longitude(); } void QMapboxGL::setLongitude(double longitude_) { - d_ptr->mapObj->setLatLng(mbgl::LatLng { latitude(), longitude_ }, d_ptr->margins); + d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng { latitude(), longitude_ }).withPadding(d_ptr->margins)); } /*! @@ -784,13 +784,15 @@ double QMapboxGL::maximumZoom() const */ Coordinate QMapboxGL::coordinate() const { - const mbgl::LatLng& latLng = d_ptr->mapObj->getLatLng(d_ptr->margins); + const mbgl::LatLng& latLng = *d_ptr->mapObj->getCameraOptions(d_ptr->margins).center; return Coordinate(latLng.latitude(), latLng.longitude()); } void QMapboxGL::setCoordinate(const QMapbox::Coordinate &coordinate_) { - d_ptr->mapObj->setLatLng(mbgl::LatLng { coordinate_.first, coordinate_.second }, d_ptr->margins); + d_ptr->mapObj->jumpTo(mbgl::CameraOptions() + .withCenter(mbgl::LatLng { coordinate_.first, coordinate_.second }) + .withPadding(d_ptr->margins)); } /*! diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 3bc4c9f8d9..e2b56b8d55 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -167,24 +167,6 @@ void Map::moveBy(const ScreenCoordinate& point, const AnimationOptions& animatio impl->onUpdate(); } -void Map::setLatLng(const LatLng& latLng, const AnimationOptions& animation) { - easeTo(CameraOptions().withCenter(latLng), animation); -} - -void Map::setLatLng(const LatLng& latLng, const EdgeInsets& padding, const AnimationOptions& animation) { - easeTo(CameraOptions().withCenter(latLng).withPadding(padding), animation); -} - -LatLng Map::getLatLng(const EdgeInsets& padding) const { - return impl->transform.getLatLng(padding); -} - -void Map::resetPosition(const EdgeInsets& padding) { - impl->cameraMutated = true; - impl->transform.jumpTo(CameraOptions().withCenter(LatLng()).withPadding(padding).withZoom(0.0).withBearing(0.0).withPitch(0.0)); - impl->onUpdate(); -} - #pragma mark - Zoom void Map::scaleBy(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) { @@ -438,7 +420,7 @@ ScreenCoordinate Map::pixelForLatLng(const LatLng& latLng) const { // antimeridian, we unwrap the point longitude so it would be seen if // e.g. the next antimeridian side is visible. LatLng unwrappedLatLng = latLng.wrapped(); - unwrappedLatLng.unwrapForShortestPath(getLatLng()); + unwrappedLatLng.unwrapForShortestPath(impl->transform.getLatLng()); return impl->transform.latLngToScreenCoordinate(unwrappedLatLng); } diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 1b64e48614..6d1650b82c 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -127,10 +127,10 @@ TEST(Map, LatLngBehavior) { MapTest<> test; test.map.jumpTo(CameraOptions().withCenter(LatLng { 1.0, 1.0 }).withZoom(0.0)); - auto latLng1 = test.map.getLatLng(); + auto latLng1 = *test.map.getCameraOptions().center; - test.map.setLatLng({ 1, 1 }); - auto latLng2 = test.map.getLatLng(); + test.map.jumpTo(CameraOptions().withCenter(LatLng { 1.0, 1.0 })); + auto latLng2 = *test.map.getCameraOptions().center; ASSERT_DOUBLE_EQ(latLng1.latitude(), latLng2.latitude()); ASSERT_DOUBLE_EQ(latLng1.longitude(), latLng2.longitude()); |