diff options
author | Larry Geromegnace <larry.geromegnace@mappy.com> | 2016-01-22 11:49:19 +0100 |
---|---|---|
committer | Brad Leege <bleege@gmail.com> | 2016-01-27 10:57:38 -0600 |
commit | c114ed6562242c1549a96d5a79b9aed229ba48aa (patch) | |
tree | d94b0ad56c88bfe6d9eba24a134a18c03a9f2eb7 | |
parent | 0d3af143756381fe5a96336fb5882a26301302ca (diff) | |
download | qtlocation-mapboxgl-c114ed6562242c1549a96d5a79b9aed229ba48aa.tar.gz |
[android] Add API to be able to set insets on MapView.
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java | 36 | ||||
-rwxr-xr-x[-rw-r--r--] | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java | 6 | ||||
-rwxr-xr-x[-rw-r--r--] | platform/android/src/jni.cpp | 15 | ||||
-rwxr-xr-x[-rw-r--r--] | platform/android/src/native_map_view.cpp | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | platform/android/src/native_map_view.hpp | 3 |
5 files changed, 63 insertions, 1 deletions
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 7ffe338d87..7a46c46cd8 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); + } + + /** * <p> * 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 index c90b925f3d..2d9d1ebb2d 100644..100755 --- 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 index cd013e4519..a6fff62bb0 100644..100755 --- 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<NativeMapView *>(nativeMapViewPtr); + nativeMapView->setInsets({top, left, bottom, right}); +} + + void JNICALL nativeFlyTo(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble angle, jobject centerLatLng, jlong duration, jdouble pitch, jdouble zoom) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeFlyTo"); assert(nativeMapViewPtr != 0); @@ -1571,6 +1581,7 @@ void JNICALL nativeFlyTo(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdoub cameraOptions.angle = angle; } cameraOptions.center = mbgl::LatLng(latitude, longitude); + cameraOptions.padding = nativeMapView->getInsets(); if (pitch != -1) { cameraOptions.pitch = pitch; } @@ -2136,6 +2147,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { reinterpret_cast<void *>(&nativeAddCustomLayer)}, {"nativeRemoveCustomLayer", "(JLjava/lang/String;)V", reinterpret_cast<void *>(&nativeRemoveCustomLayer)}, + {"nativeSetContentPadding", "(JDDDD)V", + reinterpret_cast<void *>(&nativeSetContentPadding)} }; if (env->RegisterNatives(nativeMapViewClass, methods.data(), methods.size()) < 0) { diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 5d6e240797..8c7115a1e4 100644..100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -752,5 +752,9 @@ void NativeMapView::resizeFramebuffer(int w, int h) { map->update(mbgl::Update::Repaint); } +void NativeMapView::setInsets(mbgl::EdgeInsets insets_) { + insets = insets_; +} + } } diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index cc88403c39..bc5d457f5b 100644..100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -51,6 +51,8 @@ public: void resizeView(int width, int height); void resizeFramebuffer(int width, int height); + mbgl::EdgeInsets getInsets() { return insets;} + void setInsets(mbgl::EdgeInsets insets_); private: EGLConfig chooseConfig(const EGLConfig configs[], EGLint numConfigs); @@ -92,6 +94,7 @@ private: // Ensure these are initialised last std::unique_ptr<mbgl::DefaultFileSource> fileSource; std::unique_ptr<mbgl::Map> map; + mbgl::EdgeInsets insets; }; } } |