From 16442341799dceea63e7cd6c3f77331f68f642e7 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 26 Jan 2016 18:50:37 -0800 Subject: [PATCH 1/4] [core] add setMaxZoom, setMinZoom also change the default maxZoom to 20 to match -js. --- include/mbgl/map/map.hpp | 2 ++ src/mbgl/map/map.cpp | 14 ++++++++++++++ src/mbgl/map/transform.cpp | 8 ++++++++ src/mbgl/map/transform.hpp | 3 +++ src/mbgl/map/transform_state.cpp | 8 ++++++++ src/mbgl/map/transform_state.hpp | 4 +++- 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 1112ac6c934..5b89bf4a916 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -116,7 +116,9 @@ class Map : private util::noncopyable { CameraOptions cameraForLatLngBounds(const LatLngBounds&, const EdgeInsets&); CameraOptions cameraForLatLngs(const std::vector&, const EdgeInsets&); void resetZoom(); + void setMinZoom(const double minZoom); double getMinZoom() const; + void setMaxZoom(const double maxZoom); double getMaxZoom() const; // Rotation diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index a45a9ffaff0..e013619cfa9 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -303,10 +303,24 @@ void Map::resetZoom() { setZoom(0); } +void Map::setMinZoom(const double minZoom) { + transform->setMinZoom(minZoom); + if (getZoom() < minZoom) { + setZoom(minZoom); + } +} + double Map::getMinZoom() const { return transform->getState().getMinZoom(); } +void Map::setMaxZoom(const double maxZoom) { + transform->setMaxZoom(maxZoom); + if (getZoom() > maxZoom) { + setZoom(maxZoom); + } +} + double Map::getMaxZoom() const { return transform->getState().getMaxZoom(); } diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 208f9a089a8..b8c816ddc2f 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -465,6 +465,14 @@ void Transform::setScale(double scale, const EdgeInsets& padding, const Duration setScale(scale, center, duration); } +void Transform::setMinZoom(const double minZoom) { + state.setMinZoom(minZoom); +} + +void Transform::setMaxZoom(const double maxZoom) { + state.setMaxZoom(maxZoom); +} + #pragma mark - Angle void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& duration) { diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index 8c9ea088856..806413058de 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -79,6 +79,9 @@ class Transform : private util::noncopyable { /** Returns the scale factor. */ double getScale() const; + void setMinZoom(const double minZoom); + void setMaxZoom(const double maxZoom); + // Angle void rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& = Duration::zero()); diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index c9c904dab95..79f9a19b08a 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -168,6 +168,10 @@ double TransformState::getScale() const { return scale; } +void TransformState::setMinZoom(const double minZoom) { + min_scale = zoomScale(minZoom); +} + double TransformState::getMinZoom() const { double test_scale = min_scale; double unused_x = x; @@ -177,6 +181,10 @@ double TransformState::getMinZoom() const { return scaleZoom(test_scale); } +void TransformState::setMaxZoom(const double maxZoom) { + max_scale = zoomScale(maxZoom); +} + double TransformState::getMaxZoom() const { return scaleZoom(max_scale); } diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index 2911d8624a4..9d97bd9d6bf 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -52,7 +52,9 @@ class TransformState { int32_t getIntegerZoom() const; double getZoomFraction() const; double getScale() const; + void setMinZoom(const double minZoom); double getMinZoom() const; + void setMaxZoom(const double maxZoom); double getMaxZoom() const; // Rotation @@ -83,7 +85,7 @@ class TransformState { // Limit the amount of zooming possible on the map. double min_scale = std::pow(2, 0); - double max_scale = std::pow(2, 18); + double max_scale = std::pow(2, 20); NorthOrientation orientation = NorthOrientation::Upwards; From ca0099b6a439a140316a09d8d44aaa2803f3de35 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 27 Jan 2016 11:01:38 -0800 Subject: [PATCH 2/4] [android] getters, setters for minZoom, maxZoom adds: map.getMminZoom(); map.setMminZoom(double); map.getMaxZoom(); map.setMaxZoom(double); --- CHANGELOG.md | 1 + .../com/mapbox/mapboxsdk/views/MapView.java | 54 +++++++++++++++++++ .../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 31c853a1b7a..45eedeb6f58 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 53667efadf5..b4ae0865157 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 void setZoomLevel(@FloatRange(from = 0.0, to = MAXIMUM_ZOOM_LEVEL) double 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 2d9d1ebb2d1..2ca34de088b 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 @@ public void resetZoom() { 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 @@ private native void nativeSetLatLngZoom(long nativeMapViewPtr, 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 e59f67cc196..16574562159 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( From 371a210be877e21ad6564f739d1c5f3ef7f3c532 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 27 Jan 2016 11:34:12 -0800 Subject: [PATCH 3/4] [ios] getters, setters for minZoom, maxZoom adds: minimumZoomLevel setMinimumZoomLevel maximumZoomLevel setMaximumZoomLevel --- CHANGELOG.md | 2 ++ include/mbgl/ios/MGLMapView.h | 24 ++++++++++++++++++++++++ platform/ios/src/MGLMapView.mm | 20 ++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45eedeb6f58..822028f4c85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,8 @@ Known issues: - Fixed crash caused by MGLAnnotationImage with non-integer width or height ([#2198](https://github.com/mapbox/mapbox-gl-native/issues/2198)) - Fixed “include of non-modular header” errors in Swift projects managed by CocoaPods. ([#3679](https://github.com/mapbox/mapbox-gl-native/pull/3679)) - Avoids triggering the blue background location status bar when user has granted "when in use" permission. ([#3671](https://github.com/mapbox/mapbox-gl-native/issues/3671)) +- Added new methods to MGLMapView for getting and setting the minimum and maximum zoom levels: `minimumZoomLevel`, `setMinimumZoomLevel`, `maximumZoomLevel`, `setMaximumZoomLevel`. ([#509](https://github.com/mapbox/mapbox-gl-native/issues/509)) +- The default `maximumZoomLevel` changed from 18 to 20. ## iOS 3.0.1 diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index b27db4976a6..bd4b048d64c 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -463,6 +463,30 @@ IB_DESIGNABLE */ - (void)setZoomLevel:(double)zoomLevel animated:(BOOL)animated; +/** + * The minimum zoom level at which the map can be shown. + * + * Depending on the map view’s aspect ratio, the map view may be prevented + * from reaching the minimum zoom level, in order to keep the map from + * repeating within the current viewport. + * + * If the value of this property is greater than that of the + * maximumZoomLevel property, the behavior is undefined. + * + * The default minimumZoomLevel is 0. + */ +@property (nonatomic) double minimumZoomLevel; + +/** + * The maximum zoom level the map can be shown at. + * + * If the value of this property is smaller than that of the + * minimumZoomLevel property, the behavior is undefined. + * + * The default maximumZoomLevel is 20. + */ +@property (nonatomic) double maximumZoomLevel; + /** The heading of the map, measured in degrees clockwise from true north. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index e3016864194..954fc8a9358 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1784,6 +1784,26 @@ - (void)setZoomLevel:(double)zoomLevel animated:(BOOL)animated MGLDurationInSeconds(duration)); } +- (void)setMinimumZoomLevel:(double)minimumZoomLevel +{ + _mbglMap->setMinZoom(minimumZoomLevel); +} + +- (double)minimumZoomLevel +{ + return _mbglMap->getMinZoom(); +} + +- (void)setMaximumZoomLevel:(double)maximumZoomLevel +{ + _mbglMap->setMaxZoom(maximumZoomLevel); +} + +- (double)maximumZoomLevel +{ + return _mbglMap->getMaxZoom(); +} + - (MGLCoordinateBounds)visibleCoordinateBounds { return [self convertRect:self.bounds toCoordinateBoundsFromView:self]; From b738087080b924061c4e6ce4c8b60ae4573f4f10 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 27 Jan 2016 12:06:05 -0800 Subject: [PATCH 4/4] [osx] setMaximumZoomLevel, setMinimumZoomLevel adds: setMaximumZoomLevel setMinimumZoomLevel and makes `maximumZoomLevel` and `minimumZoomLevel` not readonly --- include/mbgl/osx/MGLMapView.h | 30 +++++++++++++++++++++++------- platform/osx/src/MGLMapView.mm | 10 ++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/include/mbgl/osx/MGLMapView.h b/include/mbgl/osx/MGLMapView.h index 62a689fa196..ca55ba7cd5f 100644 --- a/include/mbgl/osx/MGLMapView.h +++ b/include/mbgl/osx/MGLMapView.h @@ -182,13 +182,29 @@ IB_DESIGNABLE */ @property (nonatomic) double zoomLevel; -/** The minimum zoom level that can be displayed by the receiver using the - current style. */ -@property (nonatomic, readonly) double maximumZoomLevel; - -/** The maximum zoom level that can be displayed by the receiver using the - current style. */ -@property (nonatomic, readonly) double minimumZoomLevel; +/** + * The minimum zoom level at which the map can be shown. + * + * Depending on the map view’s aspect ratio, the map view may be prevented + * from reaching the minimum zoom level, in order to keep the map from + * repeating within the current viewport. + * + * If the value of this property is greater than that of the + * maximumZoomLevel property, the behavior is undefined. + * + * The default minimumZoomLevel is 0. + */ +@property (nonatomic) double minimumZoomLevel; + +/** + * The maximum zoom level the map can be shown at. + * + * If the value of this property is smaller than that of the + * minimumZoomLevel property, the behavior is undefined. + * + * The default maximumZoomLevel is 20. + */ +@property (nonatomic) double maximumZoomLevel; /** Changes the zoom level of the map and optionally animates the change. diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index fe95427e524..96144d964f7 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -900,6 +900,16 @@ - (void)scaleBy:(double)scaleFactor atPoint:(NSPoint)point animated:(BOOL)animat [self didChangeValueForKey:@"centerCoordinate"]; } +- (void)setMinimumZoomLevel:(double)minimumZoomLevel +{ + _mbglMap->setMinZoom(minimumZoomLevel); +} + +- (void)setMaximumZoomLevel:(double)maximumZoomLevel +{ + _mbglMap->setMaxZoom(maximumZoomLevel); +} + - (double)maximumZoomLevel { return _mbglMap->getMaxZoom(); }