summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2015-11-17 17:19:54 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2015-11-18 09:37:27 +0200
commitadfac6f0615b7f79da2c80d0580428a92e9f0089 (patch)
treeb6cac5234e13cdd5148efdbb8f3cd1e9c7ed349f /src
parentcb9b397985b98a75aa9fa5e6f2b135c205f7cafd (diff)
downloadqtlocation-mapboxgl-adfac6f0615b7f79da2c80d0580428a92e9f0089.tar.gz
[core] Added ConstrainMode::{HeightOnly,WidthAndHeight}
ConstrainMode gives flexibility to our engine to choose between constraining both vertically and horizontally, or just vertically (default behavior). Constrain in both axis means we can no longer pan the map beyond the map boundaries. This fixes an issue where e.g. annotations disappear upon crossing the map boundaries.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/map.cpp4
-rw-r--r--src/mbgl/map/transform.cpp9
-rw-r--r--src/mbgl/map/transform.hpp7
-rw-r--r--src/mbgl/map/transform_state.cpp29
-rw-r--r--src/mbgl/map/transform_state.hpp7
5 files changed, 34 insertions, 22 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 69931ed29d..713222fe54 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -14,9 +14,9 @@
namespace mbgl {
-Map::Map(View& view_, FileSource& fileSource, MapMode mapMode, GLContextMode contextMode)
+Map::Map(View& view_, FileSource& fileSource, MapMode mapMode, GLContextMode contextMode, ConstrainMode constrainMode)
: view(view_),
- transform(std::make_unique<Transform>(view)),
+ transform(std::make_unique<Transform>(view, constrainMode)),
data(std::make_unique<MapData>(mapMode, contextMode, view.getPixelRatio())),
context(std::make_unique<util::Thread<MapContext>>(util::ThreadContext{"Map", util::ThreadType::Map, util::ThreadPriority::Regular}, view, fileSource, *data))
{
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 91fe87791e..55a492c493 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -34,8 +34,9 @@ static double _normalizeAngle(double angle, double anchorAngle)
return angle;
}
-Transform::Transform(View &view_)
+Transform::Transform(View &view_, ConstrainMode constrainMode)
: view(view_)
+ , state(constrainMode)
{
}
@@ -48,7 +49,7 @@ bool Transform::resize(const std::array<uint16_t, 2> size) {
state.width = size[0];
state.height = size[1];
- state.constrain(state.scale, state.y);
+ state.constrain(state.scale, state.x, state.y);
view.notifyMapChange(MapChangeRegionDidChange);
@@ -105,7 +106,7 @@ void Transform::_moveBy(const PrecisionPoint& point, const Duration& duration) {
double x = state.x + std::cos(state.angle) * point.x + std::sin( state.angle) * point.y;
double y = state.y + std::cos(state.angle) * point.y + std::sin(-state.angle) * point.x;
- state.constrain(state.scale, y);
+ state.constrain(state.scale, x, y);
CameraOptions options;
options.duration = duration;
@@ -239,7 +240,7 @@ void Transform::_easeTo(const CameraOptions& options, double new_scale, double n
double x = xn;
double y = yn;
- state.constrain(scale, y);
+ state.constrain(scale, x, y);
double angle = _normalizeAngle(new_angle, state.angle);
state.angle = _normalizeAngle(state.angle, angle);
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 0fc900dac7..7f424eba2b 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -1,10 +1,11 @@
#ifndef MBGL_MAP_TRANSFORM
#define MBGL_MAP_TRANSFORM
-#include <mbgl/map/transform_state.hpp>
#include <mbgl/map/camera.hpp>
-#include <mbgl/util/chrono.hpp>
+#include <mbgl/map/mode.hpp>
+#include <mbgl/map/transform_state.hpp>
#include <mbgl/map/update.hpp>
+#include <mbgl/util/chrono.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/noncopyable.hpp>
@@ -18,7 +19,7 @@ class View;
class Transform : private util::noncopyable {
public:
- Transform(View&);
+ Transform(View&, ConstrainMode);
// Map view
bool resize(std::array<uint16_t, 2> size);
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index f58bfde8df..44a4c29402 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -7,7 +7,8 @@
using namespace mbgl;
-TransformState::TransformState()
+TransformState::TransformState(ConstrainMode constrainMode_)
+ : constrainMode(constrainMode_)
{
}
@@ -143,8 +144,9 @@ double TransformState::getScale() const {
double TransformState::getMinZoom() const {
double test_scale = scale;
- double test_y = y;
- constrain(test_scale, test_y);
+ double unused_x = x;
+ double unused_y = y;
+ constrain(test_scale, unused_x, unused_y);
return ::log2(::fmin(min_scale, test_scale));
}
@@ -316,17 +318,22 @@ mat4 TransformState::getPixelMatrix() const {
#pragma mark - (private helper functions)
-void TransformState::constrain(double& scale_, double& y_) const {
- // Constrain minimum zoom to avoid zooming out far enough to show off-world areas.
- if (scale_ < height / util::tileSize) {
- scale_ = height / util::tileSize;
+void TransformState::constrain(double& scale_, double& x_, double& y_) const {
+ // Constrain minimum scale to avoid zooming out far enough to show off-world areas.
+ if (constrainMode == ConstrainMode::WidthAndHeight) {
+ scale_ = std::max(scale_, static_cast<double>(width / util::tileSize));
}
- // Constrain min/max vertical pan to avoid showing off-world areas.
- double max_y = ((scale_ * util::tileSize) - height) / 2;
+ scale_ = std::max(scale_, static_cast<double>(height / util::tileSize));
- if (y_ > max_y) y_ = max_y;
- if (y_ < -max_y) y_ = -max_y;
+ // Constrain min/max pan to avoid showing off-world areas.
+ if (constrainMode == ConstrainMode::WidthAndHeight) {
+ double max_x = (scale_ * util::tileSize - width) / 2;
+ x_ = std::max(-max_x, std::min(x_, max_x));
+ }
+
+ double max_y = (scale_ * util::tileSize - height) / 2;
+ y_ = std::max(-max_y, std::min(y_, max_y));
}
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index 0373798f00..37ea7fa0f4 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -1,6 +1,7 @@
#ifndef MBGL_MAP_TRANSFORM_STATE
#define MBGL_MAP_TRANSFORM_STATE
+#include <mbgl/map/mode.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/vec.hpp>
@@ -21,7 +22,7 @@ class TransformState {
friend class Transform;
public:
- TransformState();
+ TransformState(ConstrainMode = ConstrainMode::HeightOnly);
// Matrix
void matrixFor(mat4& matrix, const TileID& id, const int8_t z) const;
@@ -73,7 +74,7 @@ public:
TileCoordinate pointToCoordinate(const PrecisionPoint&) const;
private:
- void constrain(double& scale, double& y) const;
+ void constrain(double& scale, double& x, double& y) const;
// Limit the amount of zooming possible on the map.
double min_scale = std::pow(2, 0);
@@ -93,6 +94,8 @@ private:
mat4 getPixelMatrix() const;
private:
+ ConstrainMode constrainMode;
+
// animation state
bool rotating = false;
bool scaling = false;