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

Possible to set zoom beyond maximum limit #1405

Closed
friedbunny opened this issue May 4, 2015 · 2 comments
Closed

Possible to set zoom beyond maximum limit #1405

friedbunny opened this issue May 4, 2015 · 2 comments

Comments

@friedbunny
Copy link
Contributor

When setting the zoom level programmatically, Transform::setLatLngZoom and the subsequent Transform::_setScaleXY do not check if the zoom level is sane.

In iOS, it's possible to set mapView.zoomLevel = 21.f and it will render the map, even though the maximum zoom level via gestures is z18. Values higher than 21.9f break rendering but are settable. Using a zoom gesture will pop the map back to z18.

Here is one solution that works, but I get the feeling that Transform::_setScaleXY is the right place to do this, not Transform::setLatLng:

diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 6c0f136..95448a7 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -118,7 +118,7 @@ void Transform::setLatLng(const LatLng latLng, const Duration duration) {
 void Transform::setLatLngZoom(const LatLng latLng, const double zoom, const Duration duration) {
     std::lock_guard<std::recursive_mutex> lock(mtx);

-    double new_scale = std::pow(2.0, zoom);
+    double new_scale = std::pow(2.0, std::fmin(std::fmax(zoom, getMinZoom()), getMaxZoom()));

     const double s = new_scale * util::tileSize;
     current.Bc = s / 360;

/cc @kkaefer

@friedbunny friedbunny changed the title Possible to set maximum zoom beyond limit Possible to set zoom beyond maximum limit May 4, 2015
@friedbunny
Copy link
Contributor Author

Let's link this thread up with the ability to customize the max zoom, #509.

@1ec5
Copy link
Contributor

1ec5 commented Jan 27, 2016

This is now addressed by copious use of TransformState::constrain() (#3026).

@1ec5 1ec5 closed this as completed Jan 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants