From ca0099b6a439a140316a09d8d44aaa2803f3de35 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 27 Jan 2016 11:01:38 -0800 Subject: [android] getters, setters for minZoom, maxZoom adds: map.getMminZoom(); map.setMminZoom(double); map.getMaxZoom(); map.setMaxZoom(double); --- CHANGELOG.md | 1 + .../java/com/mapbox/mapboxsdk/views/MapView.java | 54 ++++++++++++++++++++++ .../com/mapbox/mapboxsdk/views/NativeMapView.java | 12 +++++ platform/android/src/jni.cpp | 16 +++++++ 4 files changed, 83 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31c853a1b7..45eedeb6f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Fixed crash caused by annotation image with non-integer width or height ([#3031](https://github.com/mapbox/mapbox-gl-native/issues/3031)) * Tracking Mode Reverses Bearing Fix ([#3664](https://github.com/mapbox/mapbox-gl-native/issues/3664)) * GPS Extra Rotation Fix ([#3661](https://github.com/mapbox/mapbox-gl-native/issues/3661)) +* Added new methods for getting and setting the min and max zoom levels: `getMinZoom`, `setMinZoom`, `getMaxZoom`, `setMaxZoom`. ([#509](https://github.com/mapbox/mapbox-gl-native/issues/509)) ## 3.1.0 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 53667efadf..b4ae086515 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 @@ -1670,6 +1670,60 @@ public final class MapView extends FrameLayout { mNativeMapView.setZoom(zoomLevel, duration); } + /** + *

+ * Sets the minimum zoom level the map can be displayed at. + *

+ * + * @param minZoom The new minimum zoom level. + */ + @UiThread + public void setMinZoom(@FloatRange(from = 0.0, to = 25.0) double minZoom) { + if ((minZoom < 0.0) || (minZoom > 25.0)) { + throw new IllegalArgumentException("zoomLevel is < 0 or > 25"); + } + mNativeMapView.setMinZoom(minZoom); + } + + /** + *

+ * Gets the maximum zoom level the map can be displayed at. + *

+ * + * @return The minimum zoom level. + */ + @UiThread + public double getMinZoom() { + return mNativeMapView.getMinZoom(); + } + + /** + *

+ * Sets the maximum zoom level the map can be displayed at. + *

+ * + * @param maxZoom The new maximum zoom level. + */ + @UiThread + public void setMaxZoom(@FloatRange(from = 0.0, to = 25.0) double maxZoom) { + if ((maxZoom < 0.0) || (maxZoom > 25.0)) { + throw new IllegalArgumentException("zoomLevel is < 0 or > 25"); + } + mNativeMapView.setMaxZoom(maxZoom); + } + + /** + *

+ * Gets the maximum zoom level the map can be displayed at. + *

+ * + * @return The maximum zoom level. + */ + @UiThread + public double getMaxZoom() { + return mNativeMapView.getMaxZoom(); + } + /** * Returns whether the user may zoom the map. * 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 2d9d1ebb2d..2ca34de088 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 @@ -319,10 +319,18 @@ final class NativeMapView { nativeResetZoom(mNativeMapViewPtr); } + public void setMinZoom(double zoom) { + nativeSetMinZoom(mNativeMapViewPtr, zoom); + } + public double getMinZoom() { return nativeGetMinZoom(mNativeMapViewPtr); } + public void setMaxZoom(double zoom) { + nativeSetMaxZoom(mNativeMapViewPtr, zoom); + } + public double getMaxZoom() { return nativeGetMaxZoom(mNativeMapViewPtr); } @@ -588,8 +596,12 @@ final class NativeMapView { private native void nativeResetZoom(long nativeMapViewPtr); + private native void nativeSetMinZoom(long nativeMapViewPtr, double zoom); + private native double nativeGetMinZoom(long nativeMapViewPtr); + private native void nativeSetMaxZoom(long nativeMapViewPtr, double zoom); + private native double nativeGetMaxZoom(long nativeMapViewPtr); private native void nativeRotateBy(long nativeMapViewPtr, double sx, diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index e59f67cc19..1657456215 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -777,6 +777,13 @@ void JNICALL nativeResetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { nativeMapView->getMap().resetZoom(); } +void JNICALL nativeSetMinZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble zoom) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetMinZoom"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + nativeMapView->getMap().setMinZoom(zoom); +} + jdouble JNICALL nativeGetMinZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetMinZoom"); assert(nativeMapViewPtr != 0); @@ -784,6 +791,13 @@ jdouble JNICALL nativeGetMinZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPt return nativeMapView->getMap().getMinZoom(); } +void JNICALL nativeSetMaxZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble zoom) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetMaxZoom"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + nativeMapView->getMap().setMaxZoom(zoom); +} + jdouble JNICALL nativeGetMaxZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetMaxZoom"); assert(nativeMapViewPtr != 0); @@ -2087,7 +2101,9 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { reinterpret_cast(&nativeGetLatLngZoom)}, {"nativeResetZoom", "(J)V", reinterpret_cast(&nativeResetZoom)}, {"nativeGetMinZoom", "(J)D", reinterpret_cast(&nativeGetMinZoom)}, + {"nativeSetMinZoom", "(JD)V", reinterpret_cast(&nativeSetMinZoom)}, {"nativeGetMaxZoom", "(J)D", reinterpret_cast(&nativeGetMaxZoom)}, + {"nativeSetMaxZoom", "(JD)V", reinterpret_cast(&nativeSetMaxZoom)}, {"nativeRotateBy", "(JDDDDJ)V", reinterpret_cast(&nativeRotateBy)}, {"nativeSetBearing", "(JDJ)V", reinterpret_cast( -- cgit v1.2.1