Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

add setters, getters for map's minZoom and maxZoom #3712

Merged
merged 4 commits into from
Jan 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -74,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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also mention that the default maximum zoom level has been increased from 18 to 20.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not actually sure if the default change is a good idea. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s the default in GL JS? 22? Are the issues enumerated in #509 (comment) still relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the actual default is 20, https://github.com/mapbox/mapbox-gl-js/blob/739aa39e340f523fd9b7e431a0bb366b41a91711/js/ui/map.js#L142 . The default in transform.js should probably be removed.

The issues in #509 (comment) are gone (fixed by #1666),

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should increase the default to 20, then. In dense, urban business districts at z18, POIs often collide each other out, leaving a pretty sparse map (as seen in #1690).

- The default `maximumZoomLevel` changed from 18 to 20.

## iOS 3.0.1

Expand Down
24 changes: 24 additions & 0 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ class Map : private util::noncopyable {
CameraOptions cameraForLatLngBounds(const LatLngBounds&, const EdgeInsets&);
CameraOptions cameraForLatLngs(const std::vector<LatLng>&, const EdgeInsets&);
void resetZoom();
void setMinZoom(const double minZoom);
double getMinZoom() const;
void setMaxZoom(const double maxZoom);
double getMaxZoom() const;

// Rotation
Expand Down
30 changes: 23 additions & 7 deletions include/mbgl/osx/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,60 @@ public void setZoomLevel(@FloatRange(from = 0.0, to = MAXIMUM_ZOOM_LEVEL) double
mNativeMapView.setZoom(zoomLevel, duration);
}

/**
* <p>
* Sets the minimum zoom level the map can be displayed at.
* </p>
*
* @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);
}

/**
* <p>
* Gets the maximum zoom level the map can be displayed at.
* </p>
*
* @return The minimum zoom level.
*/
@UiThread
public double getMinZoom() {
return mNativeMapView.getMinZoom();
}

/**
* <p>
* Sets the maximum zoom level the map can be displayed at.
* </p>
*
* @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);
}

/**
* <p>
* Gets the maximum zoom level the map can be displayed at.
* </p>
*
* @return The maximum zoom level.
*/
@UiThread
public double getMaxZoom() {
return mNativeMapView.getMaxZoom();
}

/**
* Returns whether the user may zoom the map.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,27 @@ 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<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().setMinZoom(zoom);
}

jdouble JNICALL nativeGetMinZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetMinZoom");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
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<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().setMaxZoom(zoom);
}

jdouble JNICALL nativeGetMaxZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetMaxZoom");
assert(nativeMapViewPtr != 0);
Expand Down Expand Up @@ -2087,7 +2101,9 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
reinterpret_cast<void *>(&nativeGetLatLngZoom)},
{"nativeResetZoom", "(J)V", reinterpret_cast<void *>(&nativeResetZoom)},
{"nativeGetMinZoom", "(J)D", reinterpret_cast<void *>(&nativeGetMinZoom)},
{"nativeSetMinZoom", "(JD)V", reinterpret_cast<void *>(&nativeSetMinZoom)},
{"nativeGetMaxZoom", "(J)D", reinterpret_cast<void *>(&nativeGetMaxZoom)},
{"nativeSetMaxZoom", "(JD)V", reinterpret_cast<void *>(&nativeSetMaxZoom)},
{"nativeRotateBy", "(JDDDDJ)V", reinterpret_cast<void *>(&nativeRotateBy)},
{"nativeSetBearing", "(JDJ)V",
reinterpret_cast<void *>(
Expand Down
20 changes: 20 additions & 0 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
10 changes: 10 additions & 0 deletions platform/osx/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
14 changes: 14 additions & 0 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 8 additions & 0 deletions src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/mbgl/map/transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 8 additions & 0 deletions src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/mbgl/map/transform_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down