[android] expose camera padding option
This removes the cached insets on the Android side, making the core TransformState the source of truth. This still leaves an option to lazily set the padding which is going to be applied only when the next camera animation is started.
This commit is contained in:
committed by
Łukasz Paczos
parent
e5c219d035
commit
becc705f05
@@ -5,20 +5,23 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.annotation.Keep;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.Size;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.MathUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Resembles the position, angle, zoom and tilt of the user's viewpoint.
|
||||
*/
|
||||
public final class CameraPosition implements Parcelable {
|
||||
|
||||
public static final CameraPosition DEFAULT = new CameraPosition(new LatLng(), 0, 0, 0);
|
||||
public static final CameraPosition DEFAULT = new CameraPosition(new LatLng(), 0, 0, 0, new double[] {0, 0, 0, 0});
|
||||
|
||||
public static final Parcelable.Creator<CameraPosition> CREATOR =
|
||||
new Parcelable.Creator<CameraPosition>() {
|
||||
@@ -27,7 +30,9 @@ public final class CameraPosition implements Parcelable {
|
||||
LatLng target = in.readParcelable(LatLng.class.getClassLoader());
|
||||
double tilt = in.readDouble();
|
||||
double zoom = in.readDouble();
|
||||
return new CameraPosition(target, zoom, tilt, bearing);
|
||||
double[] padding = new double[4];
|
||||
in.readDoubleArray(padding);
|
||||
return new CameraPosition(target, zoom, tilt, bearing, padding);
|
||||
}
|
||||
|
||||
public CameraPosition[] newArray(int size) {
|
||||
@@ -49,18 +54,25 @@ public final class CameraPosition implements Parcelable {
|
||||
|
||||
/**
|
||||
* The angle, in degrees, of the camera angle from the nadir (directly facing the Earth).
|
||||
* See tilt(float) for details of restrictions on the range of values.
|
||||
* See {@link Builder#tilt(double)} for details of restrictions on the range of values.
|
||||
*/
|
||||
@Keep
|
||||
public final double tilt;
|
||||
|
||||
/**
|
||||
* Zoom level near the center of the screen. See zoom(float) for the definition of the camera's
|
||||
* Zoom level near the center of the screen. See {@link Builder#zoom(double)} for the definition of the camera's
|
||||
* zoom level.
|
||||
*/
|
||||
@Keep
|
||||
public final double zoom;
|
||||
|
||||
/**
|
||||
* Padding in pixels. Specified in left, top, right, bottom order.
|
||||
* See {@link Builder#padding(double[])} for the definition of the camera's padding.
|
||||
*/
|
||||
@Keep
|
||||
public final double[] padding;
|
||||
|
||||
/**
|
||||
* Constructs a CameraPosition.
|
||||
*
|
||||
@@ -73,13 +85,34 @@ public final class CameraPosition implements Parcelable {
|
||||
* exclusive.
|
||||
* @throws NullPointerException if target is null
|
||||
* @throws IllegalArgumentException if tilt is outside the range of 0 to 90 degrees inclusive.
|
||||
* @deprecated use {@link CameraPosition#CameraPosition(LatLng, double, double, double, double[])} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
CameraPosition(LatLng target, double zoom, double tilt, double bearing) {
|
||||
this(target, zoom, tilt, bearing, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a CameraPosition.
|
||||
*
|
||||
* @param target The target location to align with the center of the screen.
|
||||
* @param zoom Zoom level at target. See zoom(float) for details of restrictions.
|
||||
* @param tilt The camera angle, in degrees, from the nadir (directly down). See tilt(float)
|
||||
* for details of restrictions.
|
||||
* @param bearing Direction that the camera is pointing in, in degrees clockwise from north.
|
||||
* This value will be normalized to be within 0 degrees inclusive and 360 degrees
|
||||
* exclusive.
|
||||
* @param padding Padding in pixels. Specified in left, top, right, bottom order.
|
||||
* @throws NullPointerException if target is null
|
||||
* @throws IllegalArgumentException if tilt is outside the range of 0 to 90 degrees inclusive.
|
||||
*/
|
||||
@Keep
|
||||
CameraPosition(LatLng target, double zoom, double tilt, double bearing) {
|
||||
CameraPosition(LatLng target, double zoom, double tilt, double bearing, double[] padding) {
|
||||
this.target = target;
|
||||
this.bearing = bearing;
|
||||
this.tilt = tilt;
|
||||
this.zoom = zoom;
|
||||
this.padding = padding;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,6 +139,7 @@ public final class CameraPosition implements Parcelable {
|
||||
out.writeParcelable(target, flags);
|
||||
out.writeDouble(tilt);
|
||||
out.writeDouble(zoom);
|
||||
out.writeDoubleArray(padding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +149,8 @@ public final class CameraPosition implements Parcelable {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Target: " + target + ", Zoom:" + zoom + ", Bearing:" + bearing + ", Tilt:" + tilt;
|
||||
return "Target: " + target + ", Zoom:" + zoom + ", Bearing:" + bearing + ", Tilt:" + tilt
|
||||
+ ", Padding:" + Arrays.toString(padding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,6 +180,8 @@ public final class CameraPosition implements Parcelable {
|
||||
return false;
|
||||
} else if (bearing != cameraPosition.bearing) {
|
||||
return false;
|
||||
} else if (!Arrays.equals(padding, cameraPosition.padding)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -159,8 +196,16 @@ public final class CameraPosition implements Parcelable {
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
int result;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(bearing);
|
||||
result = (int) (temp ^ (temp >>> 32));
|
||||
result = 31 * result + (target != null ? target.hashCode() : 0);
|
||||
temp = Double.doubleToLongBits(tilt);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(zoom);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
result = 31 * result + Arrays.hashCode(padding);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -174,6 +219,7 @@ public final class CameraPosition implements Parcelable {
|
||||
private LatLng target = null;
|
||||
private double tilt = -1;
|
||||
private double zoom = -1;
|
||||
private double[] padding = null;
|
||||
|
||||
/**
|
||||
* Create an empty builder.
|
||||
@@ -194,6 +240,7 @@ public final class CameraPosition implements Parcelable {
|
||||
this.target = previous.target;
|
||||
this.tilt = previous.tilt;
|
||||
this.zoom = previous.zoom;
|
||||
this.padding = previous.padding;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +273,7 @@ public final class CameraPosition implements Parcelable {
|
||||
target = update.getTarget();
|
||||
tilt = update.getTilt();
|
||||
zoom = update.getZoom();
|
||||
padding = update.getPadding();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,13 +354,44 @@ public final class CameraPosition implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Padding in pixels that shifts the viewport by the specified amount.
|
||||
* Applied padding is going to persist and impact following camera transformations.
|
||||
* <p>
|
||||
* Specified in left, top, right, bottom order.
|
||||
* </p>
|
||||
*
|
||||
* @param padding Camera padding
|
||||
* @return this
|
||||
*/
|
||||
@NonNull
|
||||
public Builder padding(@Size(4) double[] padding) {
|
||||
this.padding = padding;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Padding in pixels that shifts the viewport by the specified amount.
|
||||
* Applied padding is going to persist and impact following camera transformations.
|
||||
* <p>
|
||||
* Specified in left, top, right, bottom order.
|
||||
* </p>
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
@NonNull
|
||||
public Builder padding(double left, double top, double right, double bottom) {
|
||||
this.padding = new double[] {left, top, right, bottom};
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the CameraPosition.
|
||||
*
|
||||
* @return CameraPosition
|
||||
*/
|
||||
public CameraPosition build() {
|
||||
return new CameraPosition(target, zoom, tilt, bearing);
|
||||
return new CameraPosition(target, zoom, tilt, bearing, padding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.graphics.PointF;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
@@ -28,7 +29,7 @@ public final class CameraUpdateFactory {
|
||||
*/
|
||||
public static CameraUpdate newCameraPosition(@NonNull CameraPosition cameraPosition) {
|
||||
return new CameraPositionUpdate(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt,
|
||||
cameraPosition.zoom);
|
||||
cameraPosition.zoom, cameraPosition.padding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +40,7 @@ public final class CameraUpdateFactory {
|
||||
* @return CameraUpdate Final Camera Position
|
||||
*/
|
||||
public static CameraUpdate newLatLng(@NonNull LatLng latLng) {
|
||||
return new CameraPositionUpdate(-1, latLng, -1, -1);
|
||||
return new CameraPositionUpdate(-1, latLng, -1, -1, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,6 +49,7 @@ public final class CameraUpdateFactory {
|
||||
* current camera position bearing and tilt values.
|
||||
* <p>
|
||||
* You can specify padding, in order to inset the bounding box from the map view's edges.
|
||||
* The padding will not persist and impact following camera transformations.
|
||||
* </p>
|
||||
*
|
||||
* @param bounds Bounds to match Camera position with
|
||||
@@ -64,6 +66,7 @@ public final class CameraUpdateFactory {
|
||||
* provided bearing and tilt values.
|
||||
* <p>
|
||||
* You can specify padding, in order to inset the bounding box from the map view's edges.
|
||||
* The padding will not persist and impact following camera transformations.
|
||||
* </p>
|
||||
*
|
||||
* @param bounds Bounds to match Camera position with
|
||||
@@ -82,6 +85,7 @@ public final class CameraUpdateFactory {
|
||||
* current camera position bearing and tilt values.
|
||||
* <p>
|
||||
* You can specify padding, in order to inset the bounding box from the map view's edges.
|
||||
* The padding will not persist and impact following camera transformations.
|
||||
* </p>
|
||||
*
|
||||
* @param bounds Bounds to base the Camera position out of
|
||||
@@ -102,6 +106,7 @@ public final class CameraUpdateFactory {
|
||||
* provided bearing and tilt values.
|
||||
* <p>
|
||||
* You can specify padding, in order to inset the bounding box from the map view's edges.
|
||||
* The padding will not persist and impact following camera transformations.
|
||||
* </p>
|
||||
*
|
||||
* @param bounds Bounds to base the Camera position out of
|
||||
@@ -120,14 +125,31 @@ public final class CameraUpdateFactory {
|
||||
|
||||
/**
|
||||
* Returns a CameraUpdate that moves the center of the screen to a latitude and longitude
|
||||
* specified by a LatLng object, and moves to the given zoom level.
|
||||
* specified by a LatLng object taking the specified padding into account.
|
||||
*
|
||||
* @param latLng Target location to change to
|
||||
* @param zoom Zoom level to change to
|
||||
* @return CameraUpdate Final Camera Position
|
||||
*/
|
||||
public static CameraUpdate newLatLngZoom(@NonNull LatLng latLng, double zoom) {
|
||||
return new CameraPositionUpdate(-1, latLng, -1, zoom);
|
||||
return new CameraPositionUpdate(-1, latLng, -1, zoom, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a CameraUpdate that moves the center of the screen to a latitude and longitude
|
||||
* specified by a LatLng object, and moves to the given zoom level.
|
||||
* Applied padding is going to persist and impact following camera transformations.
|
||||
*
|
||||
* @param latLng Target location to change to
|
||||
* @param left Left padding
|
||||
* @param top Top padding
|
||||
* @param right Right padding
|
||||
* @param bottom Bottom padding
|
||||
* @return CameraUpdate Final Camera Position
|
||||
*/
|
||||
public static CameraUpdate newLatLngPadding(@NonNull LatLng latLng,
|
||||
double left, double top, double right, double bottom) {
|
||||
return new CameraPositionUpdate(-1, latLng, -1, -1, new double[] {left, top, right, bottom});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,7 +210,7 @@ public final class CameraUpdateFactory {
|
||||
* @return CameraUpdate Final Camera Position
|
||||
*/
|
||||
public static CameraUpdate bearingTo(double bearing) {
|
||||
return new CameraPositionUpdate(bearing, null, -1, -1);
|
||||
return new CameraPositionUpdate(bearing, null, -1, -1, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,7 +220,34 @@ public final class CameraUpdateFactory {
|
||||
* @return CameraUpdate Final Camera Position
|
||||
*/
|
||||
public static CameraUpdate tiltTo(double tilt) {
|
||||
return new CameraPositionUpdate(-1, null, tilt, -1);
|
||||
return new CameraPositionUpdate(-1, null, tilt, -1, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a CameraUpdate that when animated changes the camera padding.
|
||||
* Applied padding is going to persist and impact following camera transformations.
|
||||
* <p>
|
||||
* Specified in left, top, right, bottom order.
|
||||
* </p>
|
||||
*
|
||||
* @param padding Padding to change to
|
||||
* @return CameraUpdate Final Camera Position
|
||||
*/
|
||||
public static CameraUpdate paddingTo(double[] padding) {
|
||||
return new CameraPositionUpdate(-1, null, -1, -1, padding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a CameraUpdate that when animated changes the camera padding.
|
||||
* Applied padding is going to persist and impact following camera transformations.
|
||||
* <p>
|
||||
* Specified in left, top, right, bottom order.
|
||||
* </p>
|
||||
*
|
||||
* @return CameraUpdate Final Camera Position
|
||||
*/
|
||||
public static CameraUpdate paddingTo(double left, double top, double right, double bottom) {
|
||||
return paddingTo(new double[] {left, top, right, bottom});
|
||||
}
|
||||
|
||||
//
|
||||
@@ -211,12 +260,14 @@ public final class CameraUpdateFactory {
|
||||
private final LatLng target;
|
||||
private final double tilt;
|
||||
private final double zoom;
|
||||
private final double[] padding;
|
||||
|
||||
CameraPositionUpdate(double bearing, LatLng target, double tilt, double zoom) {
|
||||
CameraPositionUpdate(double bearing, LatLng target, double tilt, double zoom, double[] padding) {
|
||||
this.bearing = bearing;
|
||||
this.target = target;
|
||||
this.tilt = tilt;
|
||||
this.zoom = zoom;
|
||||
this.padding = padding;
|
||||
}
|
||||
|
||||
public LatLng getTarget() {
|
||||
@@ -235,10 +286,14 @@ public final class CameraUpdateFactory {
|
||||
return zoom;
|
||||
}
|
||||
|
||||
public double[] getPadding() {
|
||||
return padding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap) {
|
||||
CameraPosition previousPosition = mapboxMap.getCameraPosition();
|
||||
if (target == null) {
|
||||
CameraPosition previousPosition = mapboxMap.getCameraPosition();
|
||||
return new CameraPosition.Builder(this)
|
||||
.target(previousPosition.target)
|
||||
.build();
|
||||
@@ -247,7 +302,7 @@ public final class CameraUpdateFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object o) {
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
@@ -266,7 +321,10 @@ public final class CameraUpdateFactory {
|
||||
if (Double.compare(that.zoom, zoom) != 0) {
|
||||
return false;
|
||||
}
|
||||
return target != null ? target.equals(that.target) : that.target == null;
|
||||
if (target != null ? !target.equals(that.target) : that.target != null) {
|
||||
return false;
|
||||
}
|
||||
return Arrays.equals(padding, that.padding);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -280,6 +338,7 @@ public final class CameraUpdateFactory {
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(zoom);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
result = 31 * result + Arrays.hashCode(padding);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -290,6 +349,7 @@ public final class CameraUpdateFactory {
|
||||
+ ", target=" + target
|
||||
+ ", tilt=" + tilt
|
||||
+ ", zoom=" + zoom
|
||||
+ ", padding=" + Arrays.toString(padding)
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1530,8 +1530,11 @@ public class LocationComponentOptions implements Parcelable {
|
||||
* </p>
|
||||
*
|
||||
* @param padding The margins for the map in pixels (left, top, right, bottom).
|
||||
* @deprecated Use {@link CameraPosition.Builder#padding(double, double, double, double)}
|
||||
* or {@link CameraUpdateFactory#paddingTo(double, double, double, double)} instead.
|
||||
*/
|
||||
@NonNull
|
||||
@Deprecated
|
||||
public LocationComponentOptions.Builder padding(@Nullable int[] padding) {
|
||||
if (padding == null) {
|
||||
throw new NullPointerException("Null padding");
|
||||
|
||||
@@ -1540,24 +1540,38 @@ public final class MapboxMap {
|
||||
* frame from the viewport. For instance, if the only the top edge is inset, the
|
||||
* map center is effectively shifted downward.
|
||||
* </p>
|
||||
* <p>
|
||||
* This method sets the padding "lazily".
|
||||
* This means that the <b>padding is going to be applied with the next camera transformation.</b>
|
||||
* To apply the padding immediately use {@link CameraPosition.Builder#padding(double, double, double, double)}
|
||||
* or {@link CameraUpdateFactory#paddingTo(double, double, double, double)}.
|
||||
* </p>
|
||||
*
|
||||
* @param left The left margin in pixels.
|
||||
* @param top The top margin in pixels.
|
||||
* @param right The right margin in pixels.
|
||||
* @param bottom The bottom margin in pixels.
|
||||
* @deprecated Use {@link CameraPosition.Builder#padding(double, double, double, double)}
|
||||
* or {@link CameraUpdateFactory#paddingTo(double, double, double, double)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setPadding(int left, int top, int right, int bottom) {
|
||||
// TODO padding should be passed as doubles
|
||||
projection.setContentPadding(new int[] {left, top, right, bottom});
|
||||
uiSettings.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current configured content padding on map view.
|
||||
* Returns the current configured content padding on map view. This might return the currently visible padding
|
||||
* or the padding cached but not yet applied by {@link #setPadding(int, int, int, int)}.
|
||||
*
|
||||
* @return An array with length 4 in the LTRB order.
|
||||
* @deprecated Use {@link CameraPosition#padding} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@NonNull
|
||||
public int[] getPadding() {
|
||||
// TODO this should return double[] (semver major change)
|
||||
return projection.getContentPadding();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,12 +41,12 @@ interface NativeMap {
|
||||
// Camera API
|
||||
//
|
||||
|
||||
void jumpTo(@NonNull LatLng center, double zoom, double pitch, double bearing);
|
||||
void jumpTo(@NonNull LatLng center, double zoom, double pitch, double bearing, double[] padding);
|
||||
|
||||
void easeTo(@NonNull LatLng center, double zoom, double bearing, double pitch, long duration,
|
||||
void easeTo(@NonNull LatLng center, double zoom, double bearing, double pitch, double[] padding, long duration,
|
||||
boolean easingInterpolator);
|
||||
|
||||
void flyTo(@NonNull LatLng center, double zoom, double bearing, double pitch, long duration);
|
||||
void flyTo(@NonNull LatLng center, double zoom, double bearing, double pitch, double[] padding, long duration);
|
||||
|
||||
void moveBy(double deltaX, double deltaY, long duration);
|
||||
|
||||
@@ -161,9 +161,9 @@ interface NativeMap {
|
||||
// Content padding API
|
||||
//
|
||||
|
||||
void setContentPadding(float[] padding);
|
||||
void setContentPadding(double[] padding);
|
||||
|
||||
float[] getContentPadding();
|
||||
double[] getContentPadding();
|
||||
|
||||
//
|
||||
// Query API
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.support.annotation.Keep;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.Geometry;
|
||||
import com.mapbox.mapboxsdk.LibraryLoader;
|
||||
@@ -68,6 +69,10 @@ final class NativeMapView implements NativeMap {
|
||||
// Flag to indicate destroy was called
|
||||
private boolean destroyed = false;
|
||||
|
||||
// Cached to enable lazily set padding.
|
||||
// Whenever an animation is schedule, this value is cleared and the source of truth becomes the core transform state.
|
||||
private double[] edgeInsets;
|
||||
|
||||
// Holds the pointer to JNI NativeMapView
|
||||
@Keep
|
||||
private long nativePtr = 0;
|
||||
@@ -241,7 +246,8 @@ final class NativeMapView implements NativeMap {
|
||||
if (checkState("setLatLng")) {
|
||||
return;
|
||||
}
|
||||
nativeSetLatLng(latLng.getLatitude(), latLng.getLongitude(), duration);
|
||||
nativeSetLatLng(latLng.getLatitude(), latLng.getLongitude(),
|
||||
getAnimationPaddingAndClearCachedInsets(null), duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -374,30 +380,20 @@ final class NativeMapView implements NativeMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentPadding(float[] padding) {
|
||||
public void setContentPadding(double[] padding) {
|
||||
if (checkState("setContentPadding")) {
|
||||
return;
|
||||
}
|
||||
// TopLeftBottomRight
|
||||
nativeSetContentPadding(
|
||||
padding[1] / pixelRatio,
|
||||
padding[0] / pixelRatio,
|
||||
padding[3] / pixelRatio,
|
||||
padding[2] / pixelRatio);
|
||||
this.edgeInsets = padding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getContentPadding() {
|
||||
public double[] getContentPadding() {
|
||||
if (checkState("getContentPadding")) {
|
||||
return new float[] {0, 0, 0, 0};
|
||||
return new double[] {0, 0, 0, 0};
|
||||
}
|
||||
float[] topLeftBottomRight = nativeGetContentPadding();
|
||||
return new float[] {
|
||||
topLeftBottomRight[1] * pixelRatio,
|
||||
topLeftBottomRight[0] * pixelRatio,
|
||||
topLeftBottomRight[3] * pixelRatio,
|
||||
topLeftBottomRight[2] * pixelRatio
|
||||
};
|
||||
// if cached insets are not applied yet, return them, otherwise, get the padding from the camera
|
||||
return edgeInsets != null ? edgeInsets : getCameraPosition().padding;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -672,29 +668,31 @@ final class NativeMapView implements NativeMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jumpTo(@NonNull LatLng center, double zoom, double pitch, double angle) {
|
||||
public void jumpTo(@NonNull LatLng center, double zoom, double pitch, double angle, double[] padding) {
|
||||
if (checkState("jumpTo")) {
|
||||
return;
|
||||
}
|
||||
nativeJumpTo(angle, center.getLatitude(), center.getLongitude(), pitch, zoom);
|
||||
nativeJumpTo(angle, center.getLatitude(), center.getLongitude(), pitch, zoom,
|
||||
getAnimationPaddingAndClearCachedInsets(padding));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void easeTo(@NonNull LatLng center, double zoom, double angle, double pitch, long duration,
|
||||
public void easeTo(@NonNull LatLng center, double zoom, double angle, double pitch, double[] padding, long duration,
|
||||
boolean easingInterpolator) {
|
||||
if (checkState("easeTo")) {
|
||||
return;
|
||||
}
|
||||
nativeEaseTo(angle, center.getLatitude(), center.getLongitude(), duration, pitch, zoom,
|
||||
easingInterpolator);
|
||||
getAnimationPaddingAndClearCachedInsets(padding), easingInterpolator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flyTo(@NonNull LatLng center, double zoom, double angle, double pitch, long duration) {
|
||||
public void flyTo(@NonNull LatLng center, double zoom, double angle, double pitch, double[] padding, long duration) {
|
||||
if (checkState("flyTo")) {
|
||||
return;
|
||||
}
|
||||
nativeFlyTo(angle, center.getLatitude(), center.getLongitude(), duration, pitch, zoom);
|
||||
nativeFlyTo(angle, center.getLatitude(), center.getLongitude(), duration, pitch, zoom,
|
||||
getAnimationPaddingAndClearCachedInsets(padding));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -703,7 +701,11 @@ final class NativeMapView implements NativeMap {
|
||||
if (checkState("getCameraValues")) {
|
||||
return new CameraPosition.Builder().build();
|
||||
}
|
||||
return nativeGetCameraPosition();
|
||||
if (edgeInsets != null) {
|
||||
return new CameraPosition.Builder(nativeGetCameraPosition()).padding(edgeInsets).build();
|
||||
} else {
|
||||
return nativeGetCameraPosition();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1126,7 +1128,7 @@ final class NativeMapView implements NativeMap {
|
||||
private native void nativeMoveBy(double dx, double dy, long duration);
|
||||
|
||||
@Keep
|
||||
private native void nativeSetLatLng(double latitude, double longitude, long duration);
|
||||
private native void nativeSetLatLng(double latitude, double longitude, double[] padding, long duration);
|
||||
|
||||
@NonNull
|
||||
@Keep
|
||||
@@ -1175,12 +1177,6 @@ final class NativeMapView implements NativeMap {
|
||||
@Keep
|
||||
private native void nativeRotateBy(double sx, double sy, double ex, double ey, long duration);
|
||||
|
||||
@Keep
|
||||
private native void nativeSetContentPadding(float top, float left, float bottom, float right);
|
||||
|
||||
@Keep
|
||||
private native float[] nativeGetContentPadding();
|
||||
|
||||
@Keep
|
||||
private native void nativeSetBearing(double degrees, long duration);
|
||||
|
||||
@@ -1270,16 +1266,17 @@ final class NativeMapView implements NativeMap {
|
||||
private native double nativeGetTopOffsetPixelsForAnnotationSymbol(String symbolName);
|
||||
|
||||
@Keep
|
||||
private native void nativeJumpTo(double angle, double latitude, double longitude, double pitch, double zoom);
|
||||
private native void nativeJumpTo(double angle, double latitude, double longitude, double pitch, double zoom,
|
||||
double[] padding);
|
||||
|
||||
@Keep
|
||||
private native void nativeEaseTo(double angle, double latitude, double longitude,
|
||||
long duration, double pitch, double zoom,
|
||||
long duration, double pitch, double zoom, double[] padding,
|
||||
boolean easingInterpolator);
|
||||
|
||||
@Keep
|
||||
private native void nativeFlyTo(double angle, double latitude, double longitude,
|
||||
long duration, double pitch, double zoom);
|
||||
long duration, double pitch, double zoom, double[] padding);
|
||||
|
||||
@NonNull
|
||||
@Keep
|
||||
@@ -1437,6 +1434,20 @@ final class NativeMapView implements NativeMap {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
private double[] getAnimationPaddingAndClearCachedInsets(double[] providedPadding) {
|
||||
if (providedPadding == null) {
|
||||
providedPadding = this.edgeInsets;
|
||||
}
|
||||
this.edgeInsets = null;
|
||||
return providedPadding == null ? null :
|
||||
new double[] {
|
||||
providedPadding[1] / pixelRatio,
|
||||
providedPadding[0] / pixelRatio,
|
||||
providedPadding[3] / pixelRatio,
|
||||
providedPadding[2] / pixelRatio
|
||||
};
|
||||
}
|
||||
|
||||
public interface ViewCallback {
|
||||
@Nullable
|
||||
Bitmap getViewContent();
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.maps;
|
||||
import android.graphics.PointF;
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.constants.GeometryConstants;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
@@ -24,7 +25,6 @@ public class Projection {
|
||||
private final NativeMap nativeMapView;
|
||||
@NonNull
|
||||
private final MapView mapView;
|
||||
private int[] contentPadding = new int[] {0, 0, 0, 0};
|
||||
|
||||
Projection(@NonNull NativeMap nativeMapView, @NonNull MapView mapView) {
|
||||
this.nativeMapView = nativeMapView;
|
||||
@@ -32,8 +32,7 @@ public class Projection {
|
||||
}
|
||||
|
||||
void setContentPadding(int[] contentPadding) {
|
||||
this.contentPadding = contentPadding;
|
||||
float[] output = new float[contentPadding.length];
|
||||
double[] output = new double[contentPadding.length];
|
||||
for (int i = 0; i < contentPadding.length; i++) {
|
||||
output[i] = contentPadding[i];
|
||||
}
|
||||
@@ -41,11 +40,15 @@ public class Projection {
|
||||
}
|
||||
|
||||
int[] getContentPadding() {
|
||||
return contentPadding;
|
||||
double[] padding = nativeMapView.getCameraPosition().padding;
|
||||
return new int[] {(int) padding[0], (int) padding[1], (int) padding[2], (int) padding[3]};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated unused
|
||||
*/
|
||||
@Deprecated
|
||||
public void invalidateContentPadding() {
|
||||
setContentPadding(contentPadding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,10 +129,11 @@ public class Projection {
|
||||
top = 0;
|
||||
bottom = mapView.getHeight();
|
||||
} else {
|
||||
left = (float) contentPadding[0];
|
||||
right = (float) (mapView.getWidth() - contentPadding[2]);
|
||||
top = (float) contentPadding[1];
|
||||
bottom = (float) (mapView.getHeight() - contentPadding[3]);
|
||||
int[] contentPadding = getContentPadding();
|
||||
left = contentPadding[0];
|
||||
right = mapView.getWidth() - contentPadding[2];
|
||||
top = contentPadding[1];
|
||||
bottom = mapView.getHeight() - contentPadding[3];
|
||||
}
|
||||
|
||||
LatLng center = fromScreenLocation(new PointF(left + (right - left) / 2, top + (bottom - top) / 2));
|
||||
|
||||
@@ -108,7 +108,8 @@ public final class Transform implements MapView.OnCameraDidChangeListener {
|
||||
if (isValidCameraPosition(cameraPosition)) {
|
||||
cancelTransitions();
|
||||
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
|
||||
nativeMap.jumpTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.tilt, cameraPosition.bearing);
|
||||
nativeMap.jumpTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.tilt, cameraPosition.bearing,
|
||||
cameraPosition.padding);
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
invalidateCameraPosition();
|
||||
handler.post(new Runnable() {
|
||||
@@ -135,7 +136,7 @@ public final class Transform implements MapView.OnCameraDidChangeListener {
|
||||
}
|
||||
mapView.addOnCameraDidChangeListener(this);
|
||||
nativeMap.easeTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.bearing, cameraPosition.tilt,
|
||||
durationMs, easingInterpolator);
|
||||
cameraPosition.padding, durationMs, easingInterpolator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +156,7 @@ public final class Transform implements MapView.OnCameraDidChangeListener {
|
||||
}
|
||||
mapView.addOnCameraDidChangeListener(this);
|
||||
nativeMap.flyTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.bearing,
|
||||
cameraPosition.tilt, durationMs);
|
||||
cameraPosition.tilt, cameraPosition.padding, durationMs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
package com.mapbox.mapboxsdk.camera;
|
||||
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Parcelable;
|
||||
import android.os.Parcel;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class CameraPositionTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
@@ -23,7 +26,7 @@ public class CameraPositionTest {
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
assertNotNull("cameraPosition should not be null", cameraPosition);
|
||||
}
|
||||
|
||||
@@ -32,9 +35,10 @@ public class CameraPositionTest {
|
||||
TypedArray typedArray = null;
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder(typedArray).build();
|
||||
assertEquals("bearing should match", -1, cameraPosition.bearing, DELTA);
|
||||
assertEquals("latlng should match", null, cameraPosition.target);
|
||||
assertNull("latlng should be null", cameraPosition.target);
|
||||
assertEquals("tilt should match", -1, cameraPosition.tilt, DELTA);
|
||||
assertEquals("zoom should match", -1, cameraPosition.zoom, DELTA);
|
||||
assertNull("padding should be null", cameraPosition.padding);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,16 +67,16 @@ public class CameraPositionTest {
|
||||
@Test
|
||||
public void testToString() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
assertEquals("toString should match", "Target: LatLng [latitude=1.0, longitude=2.0, altitude=0.0], Zoom:3.0, "
|
||||
+ "Bearing:5.0, Tilt:4.0", cameraPosition.toString());
|
||||
+ "Bearing:5.0, Tilt:4.0, Padding:[0.0, 500.0, 0.0, 0.0]", cameraPosition.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5);
|
||||
assertEquals("hashCode should match", -1007681505, cameraPosition.hashCode());
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
assertEquals("hashCode should match", -420915327, cameraPosition.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,11 +90,12 @@ public class CameraPositionTest {
|
||||
@Test
|
||||
public void testEquals() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5);
|
||||
CameraPosition cameraPositionBearing = new CameraPosition(latLng, 3, 4, 9);
|
||||
CameraPosition cameraPositionTilt = new CameraPosition(latLng, 3, 9, 5);
|
||||
CameraPosition cameraPositionZoom = new CameraPosition(latLng, 9, 4, 5);
|
||||
CameraPosition cameraPositionTarget = new CameraPosition(new LatLng(), 3, 4, 5);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionBearing = new CameraPosition(latLng, 3, 4, 9, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionTilt = new CameraPosition(latLng, 3, 9, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionZoom = new CameraPosition(latLng, 9, 4, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionTarget = new CameraPosition(new LatLng(), 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionPadding = new CameraPosition(new LatLng(), 3, 4, 5, new double[] {0, 501, 0, 0});
|
||||
|
||||
assertEquals("cameraPosition should match itself", cameraPosition, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match null", null, cameraPosition);
|
||||
@@ -99,12 +104,17 @@ public class CameraPositionTest {
|
||||
assertNotEquals("cameraPosition should not match for tilt", cameraPositionTilt, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for zoom", cameraPositionZoom, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for target", cameraPositionTarget, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for padding", cameraPositionPadding, cameraPosition);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
CameraPosition object = new CameraPosition(new LatLng(1, 2), 3, 4, 5);
|
||||
Parcelable parcelable = MockParcel.obtain(object);
|
||||
assertEquals("Parcel should match original object", parcelable, object);
|
||||
CameraPosition cameraPosition1 = new CameraPosition(new LatLng(1, 2), 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
Parcel parcel = Parcel.obtain();
|
||||
cameraPosition1.writeToParcel(parcel, 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
CameraPosition cameraPosition2 = CameraPosition.CREATOR.createFromParcel(parcel);
|
||||
assertEquals("Parcel should match original object", cameraPosition1, cameraPosition2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ class TransformTest {
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
every { nativeMapView.cameraPosition } returns CameraPosition.DEFAULT
|
||||
every { nativeMapView.cancelTransitions() } answers {}
|
||||
every { nativeMapView.jumpTo(any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.flyTo(any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.jumpTo(any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.minZoom = any() } answers {}
|
||||
every { nativeMapView.maxZoom = any() } answers {}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class TransformTest {
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
transform.moveCamera(mapboxMap, update, callback)
|
||||
|
||||
verify { nativeMapView.jumpTo(target, -1.0, -1.0, -1.0) }
|
||||
verify { nativeMapView.jumpTo(target, -1.0, -1.0, -1.0, null) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user