diff options
author | tobrun <tobrun.van.nuland@gmail.com> | 2018-07-03 18:37:13 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-07-05 13:30:50 +0200 |
commit | ec78936e18946e3cad75d23beb03b90fcf0cb915 (patch) | |
tree | d8dcdbfd524b9eb420c0b54858e8e5d47ac14ebf /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk | |
parent | add9eecd9968c2747591aaabc74b76762ba140fe (diff) | |
download | qtlocation-mapboxgl-ec78936e18946e3cad75d23beb03b90fcf0cb915.tar.gz |
[android] - add bearing and pitch to get camera for geometry
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk')
2 files changed, 72 insertions, 6 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(); |