summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-08-12 12:32:49 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2018-10-02 06:16:13 -0700
commit19179e08bc58e10361bdb387122a6db59552b9ec (patch)
treeedf30fe1e0da98f28d0e04de4b3c7605ed1b2b80 /src
parent0ef0a9763c2132a3c5b3bf5833622c235e606f29 (diff)
downloadqtlocation-mapboxgl-19179e08bc58e10361bdb387122a6db59552b9ec.tar.gz
[core] Do not constrain on X axis in ConstrainMode::HeightOnly
Diffstat (limited to 'src')
-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) {