summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-03-30 16:25:12 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2017-04-11 12:51:09 +0300
commitc1c6c1e298521c177b64665b823d1444ce5e2cfe (patch)
treec5decfae633986d01579e731be2a78ec04d72542 /src
parentbc7f6da1356fdfc22d8fa1d5f76821ab171647eb (diff)
downloadqtlocation-mapboxgl-c1c6c1e298521c177b64665b823d1444ce5e2cfe.tar.gz
[core] Added Map::{get,set}LatLngBounds
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/map.cpp9
-rw-r--r--src/mbgl/map/transform.cpp6
-rw-r--r--src/mbgl/map/transform.hpp1
-rw-r--r--src/mbgl/map/transform_state.cpp15
-rw-r--r--src/mbgl/map/transform_state.hpp4
5 files changed, 33 insertions, 2 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index f42c11bdbb..261d2f149f 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -666,6 +666,15 @@ void Map::resetZoom() {
#pragma mark - Bounds
+LatLngBounds Map::getLatLngBounds() const {
+ return impl->transform.getState().getLatLngBounds();
+}
+
+void Map::setLatLngBounds(const LatLngBounds& bounds) {
+ impl->cameraMutated = true;
+ impl->transform.setLatLngBounds(bounds);
+ impl->onUpdate(Update::Repaint);
+}
void Map::setMinZoom(const double minZoom) {
impl->transform.setMinZoom(minZoom);
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index b8c3c3fefb..469db09e0a 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -435,6 +435,12 @@ void Transform::setScale(double scale, optional<EdgeInsets> padding, const Anima
#pragma mark - Bounds
+void Transform::setLatLngBounds(const LatLngBounds& bounds) {
+ if (bounds.valid()) {
+ state.setLatLngBounds(bounds);
+ }
+}
+
void Transform::setMinZoom(const double minZoom) {
if (std::isnan(minZoom)) return;
state.setMinZoom(minZoom);
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 4b97e07b52..a4a08f4ad9 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -57,6 +57,7 @@ public:
// Bounds
+ void setLatLngBounds(const LatLngBounds&);
void setMinZoom(double);
void setMaxZoom(double);
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 3336c71125..764845bc8c 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -142,6 +142,15 @@ double TransformState::getScale() const {
#pragma mark - Bounds
+void TransformState::setLatLngBounds(const LatLngBounds& bounds_) {
+ bounds = bounds_;
+ setLatLngZoom(getLatLng(LatLng::Unwrapped), getZoom());
+}
+
+LatLngBounds TransformState::getLatLngBounds() const {
+ return bounds;
+}
+
void TransformState::setMinZoom(const double minZoom) {
if (minZoom <= getMaxZoom()) {
min_scale = zoomScale(util::clamp(minZoom, util::MIN_ZOOM, util::MAX_ZOOM));
@@ -324,16 +333,18 @@ void TransformState::moveLatLng(const LatLng& latLng, const ScreenCoordinate& an
}
void TransformState::setLatLngZoom(const LatLng &latLng, double zoom) {
+ const LatLng constrained = bounds.constrain(latLng);
+
double newScale = zoomScale(zoom);
const double newWorldSize = newScale * util::tileSize;
Bc = newWorldSize / util::DEGREES_MAX;
Cc = newWorldSize / util::M2PI;
const double m = 1 - 1e-15;
- const double f = util::clamp(std::sin(util::DEG2RAD * latLng.latitude()), -m, m);
+ const double f = util::clamp(std::sin(util::DEG2RAD * constrained.latitude()), -m, m);
ScreenCoordinate point = {
- -latLng.longitude() * Bc,
+ -constrained.longitude() * Bc,
0.5 * Cc * std::log((1 + f) / (1 - f)),
};
setScalePoint(newScale, point);
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index 4a0218e10e..b8baefdba1 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -51,6 +51,8 @@ public:
double getZoomFraction() const;
// Bounds
+ void setLatLngBounds(const LatLngBounds&);
+ LatLngBounds getLatLngBounds() const;
void setMinZoom(double);
double getMinZoom() const;
void setMaxZoom(double);
@@ -84,6 +86,8 @@ private:
bool rotatedNorth() const;
void constrain(double& scale, double& x, double& y) const;
+ LatLngBounds bounds = LatLngBounds::world();
+
// Limit the amount of zooming possible on the map.
double min_scale = std::pow(2, 0);
double max_scale = std::pow(2, 20);