diff options
author | Justin R. Miller <incanus@codesorcery.net> | 2014-05-22 16:11:21 -0700 |
---|---|---|
committer | Justin R. Miller <incanus@codesorcery.net> | 2014-05-22 16:11:21 -0700 |
commit | 1ff173a0494bdc76bc4a262948b62dd114ef1d61 (patch) | |
tree | 063011885855f2793ece8d34cc65946689a22ea2 /src | |
parent | 12594ce8f1c69061f477c50604b21a3211e5dd72 (diff) | |
download | qtlocation-mapboxgl-1ff173a0494bdc76bc4a262948b62dd114ef1d61.tar.gz |
fixes #48: constrain min zoom/vertical pan to within world
Diffstat (limited to 'src')
-rw-r--r-- | src/map/transform.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/map/transform.cpp b/src/map/transform.cpp index 93942edadd..e05bb38f3d 100644 --- a/src/map/transform.cpp +++ b/src/map/transform.cpp @@ -32,6 +32,7 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio, current.pixelRatio = final.pixelRatio = ratio; current.framebuffer[0] = final.framebuffer[0] = fb_w; current.framebuffer[1] = final.framebuffer[1] = fb_h; + constrain(current.scale, current.y); return true; } else { return false; @@ -52,6 +53,8 @@ void Transform::_moveBy(const double dx, const double dy, const time duration) { final.x = current.x + std::cos(current.angle) * dx + std::sin(current.angle) * dy; final.y = current.y + std::cos(current.angle) * dy + std::sin(-current.angle) * dx; + constrain(final.scale, final.y); + if (duration == 0) { current.x = final.x; current.y = final.y; @@ -243,6 +246,8 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl final.x = xn; final.y = yn; + constrain(final.scale, final.y); + if (duration == 0) { current.scale = final.scale; current.x = final.x; @@ -264,6 +269,19 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl Cc = s / (2 * M_PI); } +#pragma mark - Constraints + +void Transform::constrain(double& scale, double& y) { + // Constrain minimum zoom to avoid zooming out far enough to show off-world areas. + if (scale < (current.height / util::tileSize)) scale = (current.height / util::tileSize); + + // Constrain min/max vertical pan to avoid showing off-world areas. + double max_y = ((scale * util::tileSize) - current.height) / 2; + + if (y > max_y) y = max_y; + if (y < -max_y) y = -max_y; +} + #pragma mark - Angle void Transform::rotateBy(const double start_x, const double start_y, const double end_x, |