diff options
author | tobrun <tobrun.van.nuland@gmail.com> | 2018-07-03 13:51:18 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-07-05 13:30:50 +0200 |
commit | add9eecd9968c2747591aaabc74b76762ba140fe (patch) | |
tree | e01cee6fe4cd5a6a86bf527f1495720ffee8b89a /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk | |
parent | 9920b25af3c2f70bb22ed65885db2dd10dc10fe0 (diff) | |
download | qtlocation-mapboxgl-add9eecd9968c2747591aaabc74b76762ba140fe.tar.gz |
[android] - add bearing and tilt to LatLngBounds, incorporate current tilt and bearing transformation in old api
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk')
2 files changed, 68 insertions, 13 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 45357b8064..27311dce1f 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 @@ -9,12 +9,12 @@ import android.support.annotation.FloatRange; import android.support.annotation.IntRange; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.Size; import android.support.annotation.UiThread; import android.support.v4.util.Pools; import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; - import com.mapbox.android.gestures.AndroidGesturesManager; import com.mapbox.android.gestures.MoveGestureDetector; import com.mapbox.android.gestures.RotateGestureDetector; @@ -44,12 +44,11 @@ import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.Layer; import com.mapbox.mapboxsdk.style.light.Light; import com.mapbox.mapboxsdk.style.sources.Source; +import timber.log.Timber; import java.util.HashMap; import java.util.List; -import timber.log.Timber; - /** * The general class to interact with in the Android Mapbox SDK. It exposes the entry point for all * methods related to the MapView. You cannot instantiate {@link MapboxMap} object directly, rather, @@ -457,7 +456,7 @@ public final class MapboxMap { * * @param name the name of the image * @param image the pre-multiplied Bitmap - * @param sdf the flag indicating image is an SDF or template image + * @param sdf the flag indicating image is an SDF or template image */ public void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf) { nativeMapView.addImage(name, image, sdf); @@ -1567,17 +1566,70 @@ public final class MapboxMap { nativeMapView.setLatLngBounds(latLngBounds); } + /** - * Get a camera position that fits a provided bounds and padding. + * Get a camera position that fits a provided bounds and the current camera tilt. * - * @param latLngBounds the bounds to constrain the map with + * @param latLngBounds the bounds to set the map with + * @return the camera position that fits the bounds + */ + @NonNull + public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds) { + // we use current camera tilt value to provide expected transformations as #11993 + return getCameraForLatLngBounds(latLngBounds, new int[] {0, 0, 0, 0}); + } + + + /** + * Get a camera position that fits a provided bounds and padding and the current camera tilt. + * + * @param latLngBounds the bounds to set 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 getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds, + @NonNull @Size(value = 4) int[] padding) { + // we use current camera tilt/bearing value to provide expected transformations as #11993 + return getCameraForLatLngBounds(latLngBounds, padding, transform.getBearing(), transform.getTilt()); + } + + + /** + * Get a camera position that fits a provided bounds, padding and tilt. + * + * @param latLngBounds the bounds to set the map with + * @param bearing the bearing to transform the camera position with + * @param tilt to transform the camera position with + * @return the camera position that fits the bounds and padding + */ + @NonNull + public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds, + @FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, + to = MapboxConstants.MAXIMUM_DIRECTION) double bearing, + @FloatRange(from = MapboxConstants.MINIMUM_TILT, + to = MapboxConstants.MAXIMUM_TILT) double tilt) { + return getCameraForLatLngBounds(latLngBounds, new int[] {0, 0, 0, 0}, bearing, tilt); + } + + + /** + * Get a camera position that fits a provided bounds, padding and tilt. + * + * @param latLngBounds the bounds to set the map with * @param padding the padding to apply to the bounds + * @param bearing the bearing to transform the camera position with + * @param tilt to transform the camera position with * @return the camera position that fits the bounds and padding */ @NonNull - public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds, int[] padding) { - // get padded camera position from LatLngBounds - return nativeMapView.getCameraForLatLngBounds(latLngBounds, padding); + public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds, + @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.getCameraForLatLngBounds(latLngBounds, padding, bearing, tilt); } /** 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 8bf3524ff5..885028a04f 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 @@ -249,16 +249,19 @@ final class NativeMapView { return nativeGetLatLng().wrap(); } - public CameraPosition getCameraForLatLngBounds(LatLngBounds latLngBounds, int[] padding) { + public CameraPosition getCameraForLatLngBounds(LatLngBounds bounds, int[] padding, double bearing, double tilt) { if (checkState("getCameraForLatLngBounds")) { return null; } return nativeGetCameraForLatLngBounds( - latLngBounds, + bounds, padding[1] / pixelRatio, padding[0] / pixelRatio, padding[3] / pixelRatio, - padding[2] / pixelRatio); + padding[2] / pixelRatio, + bearing, + tilt + ); } public CameraPosition getCameraForGeometry(Geometry geometry, double bearing, int[] padding) { @@ -943,7 +946,7 @@ final class NativeMapView { private native LatLng nativeGetLatLng(); private native CameraPosition nativeGetCameraForLatLngBounds( - LatLngBounds latLngBounds, double top, double left, double bottom, double right); + 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); |