[android] - add bearing and tilt to LatLngBounds, incorporate current tilt and bearing transformation in old api

This commit is contained in:
tobrun
2018-07-03 13:51:18 +02:00
committed by Tobrun
parent 9920b25af3
commit add9eecd99
5 changed files with 177 additions and 20 deletions

View File

@@ -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, 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) {
// 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,
@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);
}
/**

View File

@@ -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);