From ec78936e18946e3cad75d23beb03b90fcf0cb915 Mon Sep 17 00:00:00 2001 From: tobrun Date: Tue, 3 Jul 2018 18:37:13 +0200 Subject: [android] - add bearing and pitch to get camera for geometry --- .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 67 +++++- .../com/mapbox/mapboxsdk/maps/NativeMapView.java | 11 +- .../com/mapbox/mapboxsdk/maps/MapboxMapTest.java | 102 -------- .../mapboxsdk/testapp/camera/CameraForTest.java | 268 +++++++++++++++++++++ platform/android/src/native_map_view.cpp | 4 +- platform/android/src/native_map_view.hpp | 2 +- 6 files changed, 343 insertions(+), 111 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraForTest.java diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index 27311dce1f..1a8fc1eac7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -1632,18 +1632,81 @@ public final class MapboxMap { return nativeMapView.getCameraForLatLngBounds(latLngBounds, padding, bearing, tilt); } + /** + * Get a camera position that fits a provided shape with a given bearing and padding. + * + * @param geometry the geometry to constrain the map with + * @return the camera position that fits the bounds and padding + */ + @NonNull + public CameraPosition getCameraForGeometry(@NonNull Geometry geometry) { + // we use current camera tilt value to provide expected transformations as #11993 + return getCameraForGeometry(geometry, new int[] {0, 0, 0, 0}); + } + + /** + * Get a camera position that fits a provided shape with a given bearing and padding. + * + * @param geometry the geometry to constrain the map with + * @param padding the padding to apply to the bounds + * @return the camera position that fits the bounds and padding + */ + @NonNull + public CameraPosition getCameraForGeometry(@NonNull Geometry geometry, + @NonNull @Size(value = 4) int[] padding) { + // we use current camera tilt/bearing value to provide expected transformations as #11993 + return getCameraForGeometry(geometry, padding, transform.getBearing(), transform.getTilt()); + } + /** * Get a camera position that fits a provided shape with a given bearing and padding. * * @param geometry the geometry to constrain the map with * @param bearing the bearing at which to compute the geometry's bounds + * @param tilt the tilt at which to compute the geometry's bounds + * @return the camera position that fits the bounds and padding + */ + @NonNull + public CameraPosition getCameraForGeometry(@NonNull Geometry geometry, + @FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, + to = MapboxConstants.MAXIMUM_DIRECTION) double bearing, + @FloatRange(from = MapboxConstants.MINIMUM_TILT, + to = MapboxConstants.MAXIMUM_TILT) double tilt) { + return getCameraForGeometry(geometry, new int[] {0, 0, 0, 0}, bearing, tilt); + } + + /** + * Get a camera position that fits a provided shape with a given bearing and padding. + * + * @param geometry the geometry to constrain the map with * @param padding the padding to apply to the bounds + * @param bearing the bearing at which to compute the geometry's bounds + * @param tilt the tilt at which to compute the geometry's bounds * @return the camera position that fits the bounds and padding */ @NonNull + public CameraPosition getCameraForGeometry(@NonNull Geometry geometry, + @NonNull @Size(value = 4) int[] padding, + @FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, + to = MapboxConstants.MAXIMUM_DIRECTION) double bearing, + @FloatRange(from = MapboxConstants.MINIMUM_TILT, + to = MapboxConstants.MAXIMUM_TILT) double tilt) { + return nativeMapView.getCameraForGeometry(geometry, padding, bearing, tilt); + } + + /** + * Get a camera position that fits a provided shape with a given bearing and padding. + * + * @param geometry the geometry to constrain the map with + * @param bearing the bearing at which to compute the geometry's bounds + * @param padding the padding to apply to the bounds + * @return the camera position that fits the bounds and padding + * @deprecated use Mapbox{@link #getCameraForGeometry(Geometry, int[], double, double)} instead + */ + @NonNull + @Deprecated public CameraPosition getCameraForGeometry(Geometry geometry, double bearing, int[] padding) { - // get padded camera position from Geometry - return nativeMapView.getCameraForGeometry(geometry, bearing, padding); + return getCameraForGeometry(geometry, padding, bearing, transform.getTilt()); } // diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 885028a04f..e427efc780 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -264,16 +264,19 @@ final class NativeMapView { ); } - public CameraPosition getCameraForGeometry(Geometry geometry, double bearing, int[] padding) { + public CameraPosition getCameraForGeometry(Geometry geometry, int[] padding, double bearing, double tilt) { if (checkState("getCameraForGeometry")) { return null; } return nativeGetCameraForGeometry( - geometry, bearing, + geometry, padding[1] / pixelRatio, padding[0] / pixelRatio, padding[3] / pixelRatio, - padding[2] / pixelRatio); + padding[2] / pixelRatio, + bearing, + tilt + ); } public void resetPosition() { @@ -949,7 +952,7 @@ final class NativeMapView { LatLngBounds latLngBounds, double top, double left, double bottom, double right, double bearing, double tilt); private native CameraPosition nativeGetCameraForGeometry( - Geometry geometry, double bearing, double top, double left, double bottom, double right); + Geometry geometry, double top, double left, double bottom, double right, double bearing, double tilt); private native void nativeResetPosition(); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java index 19402f0a0d..26960ddb61 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java @@ -11,7 +11,6 @@ import com.mapbox.mapboxsdk.annotations.Polygon; import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.annotations.Polyline; import com.mapbox.mapboxsdk.annotations.PolylineOptions; -import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException; @@ -124,107 +123,6 @@ public class MapboxMapTest extends BaseActivityTest { })); } - @Test - public void testGetCameraForLatLngBounds() { - validateTestSetup(); - onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { - CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( - LatLngBounds.from(10, 10, -10, -10)); - CameraPosition expectedPosition = new CameraPosition.Builder() - .target(new LatLng()).zoom(3.66).tilt(0).bearing(0).build(); - assertEquals("Latitude should match", - expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); - assertEquals("Longitude should match", - expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); - assertEquals("Bearing should match", - expectedPosition.zoom, actualPosition.zoom, 0.01f); - assertEquals("Tilt should match", expectedPosition.tilt, actualPosition.tilt, 0.01f); - })); - } - - @Test - public void testGetCameraForLatLngBoundsPadding() { - validateTestSetup(); - onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { - CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( - LatLngBounds.from(10, 10, -10, -10), new int[] {5, 5, 5, 5}); - CameraPosition expectedPosition = new CameraPosition.Builder() - .target(new LatLng()).zoom(3.64).tilt(0).bearing(0).build(); - assertEquals("Latitude should match", - expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); - assertEquals("Longitude should match", - expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); - assertEquals("Zoom should match", - expectedPosition.zoom, actualPosition.zoom, 0.01f); - assertEquals("Tilt should match", - expectedPosition.tilt, actualPosition.tilt, 0.01f); - assertEquals("Bearing should match", - expectedPosition.bearing, actualPosition.bearing, 0.01f); - })); - } - - @Test - public void testGetCameraForLatLngBoundsBearing() { - validateTestSetup(); - onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { - CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( - LatLngBounds.from(10, 10, -10, -10),45, 0); - CameraPosition expectedPosition = new CameraPosition.Builder() - .target(new LatLng()).zoom(3.15).tilt(0).bearing(45).build(); - assertEquals("Latitude should match", - expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); - assertEquals("Longitude should match", - expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); - assertEquals("Zoom should match", - expectedPosition.zoom, actualPosition.zoom, 0.01f); - assertEquals("Tilt should match", - expectedPosition.tilt, actualPosition.tilt, 0.01f); - assertEquals("Bearing should match", - expectedPosition.bearing, actualPosition.bearing, 0.01f); - })); - } - - @Test - public void testGetCameraForLatLngBoundsTilt() { - validateTestSetup(); - onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { - CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( - LatLngBounds.from(10, 10, -10, -10), 0, 45); - CameraPosition expectedPosition = new CameraPosition.Builder() - .target(new LatLng(-0.2423318,0)).zoom(3.62).tilt(45).bearing(0).build(); - assertEquals("Latitude should match", - expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); - assertEquals("Longitude should match", - expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); - assertEquals("Zoom should match", - expectedPosition.zoom, actualPosition.zoom, 0.01f); - assertEquals("Tilt should match", - expectedPosition.tilt, actualPosition.tilt, 0.01f); - assertEquals("Bearing should match", - expectedPosition.bearing, actualPosition.bearing, 0.01f); - })); - } - - @Test - public void testGetCameraForLatLngBoundsAll() { - validateTestSetup(); - onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { - CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( - LatLngBounds.from(10, 10, -10, -10), new int[]{5,5,5,5}, 45, 45); - CameraPosition expectedPosition = new CameraPosition.Builder() - .target(new LatLng(-0.3418347,-0.3400988)).zoom(3.13).tilt(45).bearing(45).build(); - assertEquals("Latitude should match", - expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); - assertEquals("Longitude should match", - expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); - assertEquals("Zoom should match", - expectedPosition.zoom, actualPosition.zoom, 0.01f); - assertEquals("Tilt should match", - expectedPosition.tilt, actualPosition.tilt, 0.01f); - assertEquals("Bearing should match", - expectedPosition.bearing, actualPosition.bearing, 0.01f); - })); - } // // MinZoomLevel diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraForTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraForTest.java new file mode 100644 index 0000000000..b835d7daea --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraForTest.java @@ -0,0 +1,268 @@ +package com.mapbox.mapboxsdk.testapp.camera; + +import android.support.annotation.NonNull; +import com.mapbox.geojson.Point; +import com.mapbox.geojson.Polygon; +import com.mapbox.mapboxsdk.camera.CameraPosition; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class CameraForTest extends BaseActivityTest { + + @Test + public void testGetCameraForLatLngBounds() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( + LatLngBounds.from(10, 10, -10, -10)); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(3.66).tilt(0).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Bearing should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", expectedPosition.tilt, actualPosition.tilt, 0.01f); + })); + } + + @Test + public void testGetCameraForLatLngBoundsPadding() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( + LatLngBounds.from(10, 10, -10, -10), new int[] {5, 5, 5, 5}); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(3.64).tilt(0).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForLatLngBoundsBearing() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( + LatLngBounds.from(10, 10, -10, -10), 45, 0); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(3.15).tilt(0).bearing(45).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForLatLngBoundsTilt() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( + LatLngBounds.from(10, 10, -10, -10), 0, 45); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng(-0.2423318, 0)).zoom(3.62).tilt(45).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForLatLngBoundsAll() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( + LatLngBounds.from(10, 10, -10, -10), new int[] {5, 5, 5, 5}, 45, 45); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng(-0.3418347, -0.3400988)).zoom(3.13).tilt(45).bearing(45).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForGeometry() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition)); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(3.66).tilt(0).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Bearing should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", expectedPosition.tilt, actualPosition.tilt, 0.01f); + })); + } + + @NonNull + private List> getPolygonDefinition() { + return new ArrayList>() { + { + add(new ArrayList() { + { + add(Point.fromLngLat(10, 10)); + add(Point.fromLngLat(-10, 10)); + add(Point.fromLngLat(-10, -10)); + add(Point.fromLngLat(10, -10)); + } + }); + } + }; + } + + @Test + public void testGetCameraForGeometryPadding() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition), + new int[] {5, 5, 5, 5}); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(3.64).tilt(0).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForGeometryBearing() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition), 45, 0); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(3.15).tilt(0).bearing(45).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForGeometryTilt() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition), 0, 45); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng(-0.2423318, 0)).zoom(3.62).tilt(45).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForGeometryAll() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition), + new int[] {5, 5, 5, 5}, 45, 45); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng(-0.3418347, -0.3400988)).zoom(3.13).tilt(45).bearing(45).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForGeometryDeprecatedApi() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition), 45, + new int[] {5, 5, 5, 5}); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(3.13).tilt(0).bearing(45).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } +} diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 35a67ed9b7..c648a22893 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -293,10 +293,10 @@ jni::Object NativeMapView::getCameraForLatLngBounds(jni::JNIEnv& return CameraPosition::New(env, map->cameraForLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds), padding, bearing, tilt)); } -jni::Object NativeMapView::getCameraForGeometry(jni::JNIEnv& env, jni::Object jGeometry, double bearing, double top, double left, double bottom, double right) { +jni::Object NativeMapView::getCameraForGeometry(jni::JNIEnv& env, jni::Object jGeometry, double top, double left, double bottom, double right, double bearing, double tilt) { auto geometry = geojson::Geometry::convert(env, jGeometry); mbgl::EdgeInsets padding = {top, left, bottom, right}; - return CameraPosition::New(env, map->cameraForGeometry(geometry, padding, bearing)); + return CameraPosition::New(env, map->cameraForGeometry(geometry, padding, bearing, tilt)); } void NativeMapView::setReachability(jni::JNIEnv&, jni::jboolean reachable) { diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index d189ebcbec..321d43c5e9 100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -106,7 +106,7 @@ public: jni::Object getCameraForLatLngBounds(jni::JNIEnv&, jni::Object, double top, double left, double bottom, double right, double bearing, double tilt); - jni::Object getCameraForGeometry(jni::JNIEnv&, jni::Object, double bearing, double top, double left, double bottom, double right); + jni::Object getCameraForGeometry(jni::JNIEnv&, jni::Object, double top, double left, double bottom, double right, double bearing, double tilt); void setReachability(jni::JNIEnv&, jni::jboolean); -- cgit v1.2.1