summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2018-07-03 18:37:13 +0200
committerTobrun <tobrun@mapbox.com>2018-07-05 13:30:50 +0200
commitec78936e18946e3cad75d23beb03b90fcf0cb915 (patch)
treed8dcdbfd524b9eb420c0b54858e8e5d47ac14ebf /platform
parentadd9eecd9968c2747591aaabc74b76762ba140fe (diff)
downloadqtlocation-mapboxgl-ec78936e18946e3cad75d23beb03b90fcf0cb915.tar.gz
[android] - add bearing and pitch to get camera for geometry
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java67
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java11
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java102
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraForTest.java268
-rwxr-xr-xplatform/android/src/native_map_view.cpp4
-rwxr-xr-xplatform/android/src/native_map_view.hpp2
6 files changed, 343 insertions, 111 deletions
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
@@ -1636,14 +1636,77 @@ public final class MapboxMap {
* 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<List<Point>> 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<List<Point>> getPolygonDefinition() {
+ return new ArrayList<List<Point>>() {
+ {
+ add(new ArrayList<Point>() {
+ {
+ 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<List<Point>> 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<List<Point>> 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<List<Point>> 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<List<Point>> 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<List<Point>> 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<CameraPosition> NativeMapView::getCameraForLatLngBounds(jni::JNIEnv&
return CameraPosition::New(env, map->cameraForLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds), padding, bearing, tilt));
}
-jni::Object<CameraPosition> NativeMapView::getCameraForGeometry(jni::JNIEnv& env, jni::Object<geojson::Geometry> jGeometry, double bearing, double top, double left, double bottom, double right) {
+jni::Object<CameraPosition> NativeMapView::getCameraForGeometry(jni::JNIEnv& env, jni::Object<geojson::Geometry> 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<CameraPosition> getCameraForLatLngBounds(jni::JNIEnv&, jni::Object<mbgl::android::LatLngBounds>, double top, double left, double bottom, double right, double bearing, double tilt);
- jni::Object<CameraPosition> getCameraForGeometry(jni::JNIEnv&, jni::Object<geojson::Geometry>, double bearing, double top, double left, double bottom, double right);
+ jni::Object<CameraPosition> getCameraForGeometry(jni::JNIEnv&, jni::Object<geojson::Geometry>, double top, double left, double bottom, double right, double bearing, double tilt);
void setReachability(jni::JNIEnv&, jni::jboolean);