diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index 7ffe338d8..7a46c46cd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -278,6 +278,10 @@ public final class MapView extends FrameLayout { private boolean mTiltEnabled = true; private boolean mAllowConcurrentMultipleOpenInfoWindows = false; private String mStyleUrl; + private int mContentPaddingLeft; + private int mContentPaddingTop; + private int mContentPaddingRight; + private int mContentPaddingBottom; // // Inner classes @@ -4341,6 +4345,38 @@ public final class MapView extends FrameLayout { setWidgetMargins(mAttributionsView, left, top, right, bottom); } + + /** + * Sets the distance from the edges of the map view’s frame to the edges of the map + * view’s logical viewport. + * + * When the value of this property is equal to {0,0,0,0}, viewport + * properties such as `centerCoordinate` assume a viewport that matches the map + * view’s frame. Otherwise, those properties are inset, excluding part of the + * frame from the viewport. For instance, if the only the top edge is inset, the + * map center is effectively shifted downward. + * + * @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. + */ + @UiThread + public void setContentPadding(int left, int top, int right, int bottom) { + + if (left == mContentPaddingLeft && top == mContentPaddingTop && right == mContentPaddingRight && bottom == mContentPaddingBottom) { + return; + } + + mContentPaddingLeft = left; + mContentPaddingTop = top; + mContentPaddingRight = right; + mContentPaddingBottom = bottom; + + mNativeMapView.setContentPadding(top / mScreenDensity, left / mScreenDensity, bottom / mScreenDensity, right / mScreenDensity); + } + + /** *
* Enables or disables the attribution button. The attribution is a button with an "i" than when
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java
old mode 100644
new mode 100755
index c90b925f3..2d9d1ebb2
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java
@@ -336,6 +336,10 @@ final class NativeMapView {
nativeRotateBy(mNativeMapViewPtr, sx, sy, ex, ey, duration);
}
+ public void setContentPadding(double top, double left, double bottom, double right) {
+ nativeSetContentPadding(mNativeMapViewPtr, top, left, bottom, right);
+ }
+
public void setBearing(double degrees) {
setBearing(degrees, 0);
}
@@ -591,6 +595,8 @@ final class NativeMapView {
private native void nativeRotateBy(long nativeMapViewPtr, double sx,
double sy, double ex, double ey, long duration);
+ private native void nativeSetContentPadding(long nativeMapViewPtr, double top, double left, double bottom, double right);
+
private native void nativeSetBearing(long nativeMapViewPtr, double degrees,
long duration);
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
old mode 100644
new mode 100755
index cd013e451..a6fff62bb
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -648,7 +648,7 @@ void JNICALL nativeSetLatLng(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, j
return;
}
- nativeMapView->getMap().setLatLng(mbgl::LatLng(latitude, longitude), mbgl::Duration(duration));
+ nativeMapView->getMap().setLatLng(mbgl::LatLng(latitude, longitude), nativeMapView->getInsets(), mbgl::Duration(duration));
}
jobject JNICALL nativeGetLatLng(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
@@ -1505,6 +1505,7 @@ void JNICALL nativeJumpTo(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdou
options.angle = angle;
}
options.center = mbgl::LatLng(latitude, longitude);
+ options.padding = nativeMapView->getInsets();
if (pitch != -1) {
options.pitch = pitch;
}
@@ -1537,6 +1538,7 @@ void JNICALL nativeEaseTo(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdou
cameraOptions.angle = angle;
}
cameraOptions.center = mbgl::LatLng(latitude, longitude);
+ cameraOptions.padding = nativeMapView->getInsets();
if (pitch != -1) {
cameraOptions.pitch = pitch;
}
@@ -1549,6 +1551,14 @@ void JNICALL nativeEaseTo(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdou
nativeMapView->getMap().easeTo(cameraOptions, animationOptions);
}
+void JNICALL nativeSetContentPadding(JNIEnv *env, jobject obj,long nativeMapViewPtr, double top, double left, double bottom, double right) {
+ mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetContentPadding");
+ assert(nativeMapViewPtr != 0);
+ NativeMapView *nativeMapView = reinterpret_cast