From c1ec9635335848900f89b2898b48f3faa9963ae3 Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Tue, 7 Jan 2020 16:10:53 +0200 Subject: Move API breaking changes to a new method name latLngBoundsForCameraUnwrapped. --- include/mbgl/map/map.hpp | 1 + platform/android/src/native_map_view.cpp | 2 +- src/mbgl/map/map.cpp | 11 +++++++++++ test/map/map.test.cpp | 32 +++++++++++++++++--------------- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index a3794962c6..62bb39e8c2 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -72,6 +72,7 @@ public: CameraOptions cameraForLatLngs(const std::vector&, const EdgeInsets&, optional bearing = {}, optional pitch = {}) const; CameraOptions cameraForGeometry(const Geometry&, const EdgeInsets&, optional bearing = {}, optional pitch = {}) const; LatLngBounds latLngBoundsForCamera(const CameraOptions&) const; + LatLngBounds latLngBoundsForCameraUnwrapped(const CameraOptions&) const; /// @name Bounds /// @{ diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 51124b76d0..d7351c7677 100644 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -530,7 +530,7 @@ void NativeMapView::setVisibleCoordinateBounds(JNIEnv& env, const jni::Array& output) { - auto latlngBounds = map->latLngBoundsForCamera(map->getCameraOptions(mbgl::nullopt)); + auto latlngBounds = map->latLngBoundsForCameraUnwrapped(map->getCameraOptions(mbgl::nullopt)); double latNorth = latlngBounds.north(); double lonEast = latlngBounds.east(); diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index d74f6e0651..a994af305f 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -249,6 +249,17 @@ LatLngBounds Map::latLngBoundsForCamera(const CameraOptions& camera) const { Transform shallow { impl->transform.getState() }; Size size = shallow.getState().getSize(); + shallow.jumpTo(camera); + return LatLngBounds::hull( + shallow.screenCoordinateToLatLng({}), + shallow.screenCoordinateToLatLng({ double(size.width), double(size.height) }) + ); +} + +LatLngBounds Map::latLngBoundsForCameraUnwrapped(const CameraOptions& camera) const { + Transform shallow{impl->transform.getState()}; + Size size = shallow.getState().getSize(); + shallow.jumpTo(camera); LatLng nw = shallow.screenCoordinateToLatLng({}); LatLng se = shallow.screenCoordinateToLatLng({double(size.width), double(size.height)}); diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index e75fdf06da..a0cd64bdd5 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -252,7 +252,7 @@ TEST(Map, CameraToLatLngBounds) { ASSERT_NEAR(camera.center->longitude(), virtualCamera.center->longitude(), 1e-7); } -TEST(Map, CameraToLatLngBoundsWithRotation) { +TEST(Map, CameraToLatLngBoundsUnwrappedWithRotation) { MapTest<> test; test.map.jumpTo(CameraOptions().withCenter(LatLng{45, 90}).withZoom(16.0).withBearing(45.0)); @@ -261,16 +261,18 @@ TEST(Map, CameraToLatLngBoundsWithRotation) { CameraOptions camera = test.map.getCameraOptions(); - ASSERT_TRUE(test.map.latLngBoundsForCamera(camera).contains(test.map.latLngForPixel({}))); - ASSERT_TRUE(test.map.latLngBoundsForCamera(camera).contains(test.map.latLngForPixel({0.0, double(size.height)}))); - ASSERT_TRUE(test.map.latLngBoundsForCamera(camera).contains(test.map.latLngForPixel({double(size.width), 0.0}))); - ASSERT_TRUE(test.map.latLngBoundsForCamera(camera).contains( + ASSERT_TRUE(test.map.latLngBoundsForCameraUnwrapped(camera).contains(test.map.latLngForPixel({}))); + ASSERT_TRUE( + test.map.latLngBoundsForCameraUnwrapped(camera).contains(test.map.latLngForPixel({0.0, double(size.height)}))); + ASSERT_TRUE( + test.map.latLngBoundsForCameraUnwrapped(camera).contains(test.map.latLngForPixel({double(size.width), 0.0}))); + ASSERT_TRUE(test.map.latLngBoundsForCameraUnwrapped(camera).contains( test.map.latLngForPixel({double(size.width), double(size.height)}))); - ASSERT_TRUE(test.map.latLngBoundsForCamera(camera).contains( + ASSERT_TRUE(test.map.latLngBoundsForCameraUnwrapped(camera).contains( test.map.latLngForPixel({double(size.width) / 2, double(size.height) / 2}))); } -TEST(Map, CameraToLatLngBoundsCrossDateLine) { +TEST(Map, CameraToLatLngBoundsUnwrappedCrossDateLine) { MapTest<> test; test.map.jumpTo(CameraOptions().withCenter(LatLng{0, 180}).withZoom(16.0)); @@ -279,17 +281,17 @@ TEST(Map, CameraToLatLngBoundsCrossDateLine) { CameraOptions camera = test.map.getCameraOptions(); - ASSERT_TRUE(test.map.latLngBoundsForCamera(camera).contains(test.map.latLngForPixel({}), LatLng::Wrapped)); - ASSERT_TRUE(test.map.latLngBoundsForCamera(camera).contains(test.map.latLngForPixel({0.0, double(size.height)}), - LatLng::Wrapped)); - ASSERT_TRUE(test.map.latLngBoundsForCamera(camera).contains(test.map.latLngForPixel({double(size.width), 0.0}), - LatLng::Wrapped)); - ASSERT_TRUE(test.map.latLngBoundsForCamera(camera).contains( + ASSERT_TRUE(test.map.latLngBoundsForCameraUnwrapped(camera).contains(test.map.latLngForPixel({}), LatLng::Wrapped)); + ASSERT_TRUE(test.map.latLngBoundsForCameraUnwrapped(camera).contains( + test.map.latLngForPixel({0.0, double(size.height)}), LatLng::Wrapped)); + ASSERT_TRUE(test.map.latLngBoundsForCameraUnwrapped(camera).contains( + test.map.latLngForPixel({double(size.width), 0.0}), LatLng::Wrapped)); + ASSERT_TRUE(test.map.latLngBoundsForCameraUnwrapped(camera).contains( test.map.latLngForPixel({double(size.width), double(size.height)}), LatLng::Wrapped)); - ASSERT_TRUE(test.map.latLngBoundsForCamera(camera).contains( + ASSERT_TRUE(test.map.latLngBoundsForCameraUnwrapped(camera).contains( test.map.latLngForPixel({double(size.width) / 2, double(size.height) / 2}))); - ASSERT_TRUE(test.map.latLngBoundsForCamera(camera).crossesAntimeridian()); + ASSERT_TRUE(test.map.latLngBoundsForCameraUnwrapped(camera).crossesAntimeridian()); } TEST(Map, Offline) { -- cgit v1.2.1