summaryrefslogtreecommitdiff
path: root/src/mbgl/map/transform_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/map/transform_state.cpp')
-rw-r--r--src/mbgl/map/transform_state.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 9ff68a1a60..5cbd307698 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -352,21 +352,26 @@ bool TransformState::rotatedNorth() const {
}
void TransformState::constrain(double& scale_, double& x_, double& y_) const {
- // Constrain minimum scale to avoid zooming out far enough to show off-world areas.
- scale_ = util::max(scale_,
- static_cast<double>(rotatedNorth() ? size.height : size.width) / util::tileSize,
- static_cast<double>(rotatedNorth() ? size.width : size.height) / util::tileSize);
+ if (constrainMode == ConstrainMode::None) {
+ return;
+ }
+
+ const double ratioX = (rotatedNorth() ? size.height : size.width) / util::tileSize;
+ const double ratioY = (rotatedNorth() ? size.width : size.height) / util::tileSize;
+
+ // Constrain minimum scale to avoid zooming out far enough to show off-world areas on the Y axis.
+ // If Y axis ratio is too small to be constrained, use X axis ratio instead.
+ scale_ = util::max(scale_, ratioY < 1.0 ? ratioX : ratioY);
+
+ // Constrain min/max pan to avoid showing off-world areas on the Y axis.
+ double max_y = (scale_ * util::tileSize - (rotatedNorth() ? size.width : size.height)) / 2;
+ y_ = std::max(-max_y, std::min(y_, max_y));
- // Constrain min/max pan to avoid showing off-world areas.
if (constrainMode == ConstrainMode::WidthAndHeight) {
+ // Constrain min/max pan to avoid showing off-world areas on the X axis.
double max_x = (scale_ * util::tileSize - (rotatedNorth() ? size.height : size.width)) / 2;
x_ = std::max(-max_x, std::min(x_, max_x));
}
-
- if (constrainMode != ConstrainMode::None) {
- double max_y = (scale_ * util::tileSize - (rotatedNorth() ? size.width : size.height)) / 2;
- y_ = std::max(-max_y, std::min(y_, max_y));
- }
}
void TransformState::moveLatLng(const LatLng& latLng, const ScreenCoordinate& anchor) {