[android] - add bearing and tilt to LatLngBounds, incorporate current tilt and bearing transformation in old api
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.graphics.Color;
|
||||
import android.support.test.espresso.UiController;
|
||||
import android.support.test.espresso.ViewAction;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
@@ -12,6 +11,7 @@ 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;
|
||||
@@ -22,16 +22,14 @@ import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ViewUtils;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
@@ -126,6 +124,108 @@ 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
|
||||
//
|
||||
@@ -634,6 +734,8 @@ public class MapboxMapTest extends BaseActivityTest {
|
||||
}));
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
public class MapboxMapAction implements ViewAction {
|
||||
|
||||
private InvokeViewAction invokeViewAction;
|
||||
|
||||
@@ -288,9 +288,9 @@ void NativeMapView::setLatLng(jni::JNIEnv&, jni::jdouble latitude, jni::jdouble
|
||||
map->setLatLng(mbgl::LatLng(latitude, longitude), insets, mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
|
||||
}
|
||||
|
||||
jni::Object<CameraPosition> NativeMapView::getCameraForLatLngBounds(jni::JNIEnv& env, jni::Object<LatLngBounds> jBounds, double top, double left, double bottom, double right) {
|
||||
jni::Object<CameraPosition> NativeMapView::getCameraForLatLngBounds(jni::JNIEnv& env, jni::Object<LatLngBounds> jBounds, double top, double left, double bottom, double right, double bearing, double tilt) {
|
||||
mbgl::EdgeInsets padding = {top, left, bottom, right};
|
||||
return CameraPosition::New(env, map->cameraForLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds), padding));
|
||||
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) {
|
||||
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
|
||||
void setLatLng(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jlong);
|
||||
|
||||
jni::Object<CameraPosition> getCameraForLatLngBounds(jni::JNIEnv&, jni::Object<mbgl::android::LatLngBounds>, double top, double left, double bottom, double right);
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user