summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-02-10 15:15:29 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-02-10 15:15:29 -0800
commitbd59ab9a5285bf56ecc7a02e180a21f269ad68c0 (patch)
treeb1c6be1c99cd940ed08955aefcb8994ae03c1c52 /src
parent71611ec61247593aa6e9b568595114647363532d (diff)
downloadqtlocation-mapboxgl-bd59ab9a5285bf56ecc7a02e180a21f269ad68c0.tar.gz
[core, ios, osx] Only constrain after adding to a window
Introduced a setter/getter for constrain mode. On iOS and OS X, the zoom level inspectable causes the zoom level to be set independently from the longitude and latitude. Thus, the latitude inspectable had no effect because the latitude was constrained to 0 at z0. Temporarily removing the heightwise constraint allows the map to center on the intended location before zooming, which is the usual case for storyboards and XIBs. On iOS, the only guarantee we have timing-wise is that all the inspectables are applied after initialization but before the view is added to a window. So we reimpose the heightwise constraint as soon as the view is added to a window, that is, before the user has a chance to pan the map out of bounds. Fixes #3868.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/map.cpp10
-rw-r--r--src/mbgl/map/transform.cpp11
-rw-r--r--src/mbgl/map/transform.hpp4
-rw-r--r--src/mbgl/map/transform_state.cpp12
-rw-r--r--src/mbgl/map/transform_state.hpp3
5 files changed, 38 insertions, 2 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 2df86a8f1c..7e0fdd29fe 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -395,6 +395,16 @@ NorthOrientation Map::getNorthOrientation() const {
return transform->getNorthOrientation();
}
+#pragma mark - Constrain mode
+
+void Map::setConstrainMode(mbgl::ConstrainMode mode) {
+ transform->setConstrainMode(mode);
+ update(Update::Repaint);
+}
+
+ConstrainMode Map::getConstrainMode() const {
+ return transform->getConstrainMode();
+}
#pragma mark - Projection
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index b8c816ddc2..0f7af8c9e9 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -560,6 +560,17 @@ NorthOrientation Transform::getNorthOrientation() const {
return state.getNorthOrientation();
}
+#pragma mark - Constrain mode
+
+void Transform::setConstrainMode(mbgl::ConstrainMode mode) {
+ state.constrainMode = mode;
+ state.constrain(state.scale, state.x, state.y);
+}
+
+ConstrainMode Transform::getConstrainMode() const {
+ return state.getConstrainMode();
+}
+
#pragma mark - Transition
void Transform::startTransition(const CameraOptions& camera,
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 806413058d..48615421fe 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -119,6 +119,10 @@ public:
// North Orientation
void setNorthOrientation(NorthOrientation);
NorthOrientation getNorthOrientation() const;
+
+ // Constrain mode
+ void setConstrainMode(ConstrainMode);
+ ConstrainMode getConstrainMode() const;
// Transitions
bool inTransition() const;
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 5e74f76229..009534fc8b 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -94,6 +94,12 @@ double TransformState::getNorthOrientationAngle() const {
return angleOrientation;
}
+#pragma mark - Constrain mode
+
+ConstrainMode TransformState::getConstrainMode() const {
+ return constrainMode;
+}
+
#pragma mark - Position
LatLng TransformState::getLatLng() const {
@@ -367,8 +373,10 @@ void TransformState::constrain(double& scale_, double& x_, double& y_) const {
x_ = std::max(-max_x, std::min(x_, max_x));
}
- double max_y = (scale_ * util::tileSize - (rotatedNorth() ? width : height)) / 2;
- y_ = std::max(-max_y, std::min(y_, max_y));
+ if (constrainMode != ConstrainMode::None) {
+ double max_y = (scale_ * util::tileSize - (rotatedNorth() ? width : height)) / 2;
+ y_ = std::max(-max_y, std::min(y_, max_y));
+ }
}
void TransformState::moveLatLng(const LatLng& latLng, const PrecisionPoint& anchor) {
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index 2aef5707fa..dfcc1ed1a0 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -36,6 +36,9 @@ public:
// North Orientation
NorthOrientation getNorthOrientation() const;
double getNorthOrientationAngle() const;
+
+ // Constrain mode
+ ConstrainMode getConstrainMode() const;
// Position
LatLng getLatLng() const;