summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/map.cpp6
-rw-r--r--src/mbgl/map/transform.cpp10
-rw-r--r--src/mbgl/map/transform.hpp2
-rw-r--r--src/mbgl/map/transform_state.cpp11
-rw-r--r--src/mbgl/map/transform_state.hpp6
-rw-r--r--src/mbgl/util/geo.cpp4
6 files changed, 21 insertions, 18 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 0d2aa421f6..e45d4b85f2 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -275,13 +275,13 @@ LatLngBounds Map::latLngBoundsForCamera(const CameraOptions& camera) const {
#pragma mark - Bounds
-optional<LatLngBounds> Map::getLatLngBounds() const {
+LatLngBounds Map::getLatLngBounds() const {
return impl->transform.getState().getLatLngBounds();
}
-void Map::setLatLngBounds(optional<LatLngBounds> bounds) {
+void Map::setLatLngBounds(LatLngBounds bounds) {
impl->cameraMutated = true;
- impl->transform.setLatLngBounds(bounds);
+ impl->transform.setLatLngBounds(std::move(bounds));
impl->onUpdate();
}
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index a90bf9871f..e97f0da3f1 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -85,7 +85,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
const EdgeInsets& padding = camera.padding;
LatLng startLatLng = getLatLng(padding, LatLng::Unwrapped);
const LatLng& unwrappedLatLng = camera.center.value_or(startLatLng);
- const LatLng& latLng = state.bounds ? unwrappedLatLng : unwrappedLatLng.wrapped();
+ const LatLng& latLng = state.bounds != LatLngBounds::unbounded() ? unwrappedLatLng : unwrappedLatLng.wrapped();
double zoom = camera.zoom.value_or(getZoom());
double bearing = camera.bearing ? -*camera.bearing * util::DEG2RAD : getBearing();
double pitch = camera.pitch ? *camera.pitch * util::DEG2RAD : getPitch();
@@ -94,7 +94,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
return;
}
- if (!state.bounds) {
+ if (state.bounds == LatLngBounds::unbounded()) {
if (isGestureInProgress()) {
// If gesture in progress, we transfer the wrap rounds from the end longitude into
// start, so the "scroll effect" of rounding the world is the same while assuring the
@@ -344,11 +344,11 @@ double Transform::getZoom() const {
#pragma mark - Bounds
-void Transform::setLatLngBounds(optional<LatLngBounds> bounds) {
- if (bounds && !bounds->valid()) {
+void Transform::setLatLngBounds(LatLngBounds bounds) {
+ if (!bounds.valid()) {
throw std::runtime_error("failed to set bounds: bounds are invalid");
}
- state.setLatLngBounds(bounds);
+ state.setLatLngBounds(std::move(bounds));
}
void Transform::setMinZoom(const double minZoom) {
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 13750c2ec0..29ca9bd14e 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -52,7 +52,7 @@ public:
// Bounds
- void setLatLngBounds(optional<LatLngBounds>);
+ void setLatLngBounds(LatLngBounds);
void setMinZoom(double);
void setMaxZoom(double);
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 73c61fdf0f..45bee7ac7f 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -9,7 +9,8 @@
namespace mbgl {
TransformState::TransformState(ConstrainMode constrainMode_, ViewportMode viewportMode_)
- : constrainMode(constrainMode_)
+ : bounds(LatLngBounds::unbounded())
+ , constrainMode(constrainMode_)
, viewportMode(viewportMode_)
{
}
@@ -185,14 +186,14 @@ double TransformState::getZoomFraction() const {
#pragma mark - Bounds
-void TransformState::setLatLngBounds(optional<LatLngBounds> bounds_) {
+void TransformState::setLatLngBounds(LatLngBounds bounds_) {
if (bounds_ != bounds) {
bounds = bounds_;
setLatLngZoom(getLatLng(LatLng::Unwrapped), getZoom());
}
}
-optional<LatLngBounds> TransformState::getLatLngBounds() const {
+LatLngBounds TransformState::getLatLngBounds() const {
return bounds;
}
@@ -379,9 +380,7 @@ void TransformState::moveLatLng(const LatLng& latLng, const ScreenCoordinate& an
void TransformState::setLatLngZoom(const LatLng& latLng, double zoom) {
LatLng constrained = latLng;
- if (bounds) {
- constrained = bounds->constrain(latLng);
- }
+ constrained = bounds.constrain(latLng);
double newScale = util::clamp(zoomScale(zoom), min_scale, max_scale);
const double newWorldSize = newScale * util::tileSize;
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index 44eb1a8a3e..811fa253af 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -55,8 +55,8 @@ public:
double getZoomFraction() const;
// Bounds
- void setLatLngBounds(optional<LatLngBounds>);
- optional<LatLngBounds> getLatLngBounds() const;
+ void setLatLngBounds(LatLngBounds);
+ LatLngBounds getLatLngBounds() const;
void setMinZoom(double);
double getMinZoom() const;
void setMaxZoom(double);
@@ -93,7 +93,7 @@ private:
bool rotatedNorth() const;
void constrain(double& scale, double& x, double& y) const;
- optional<LatLngBounds> bounds;
+ LatLngBounds bounds;
// Limit the amount of zooming possible on the map.
double min_scale = std::pow(2, 0);
diff --git a/src/mbgl/util/geo.cpp b/src/mbgl/util/geo.cpp
index 19510e2039..1106779474 100644
--- a/src/mbgl/util/geo.cpp
+++ b/src/mbgl/util/geo.cpp
@@ -92,6 +92,10 @@ bool LatLngBounds::intersects(const LatLngBounds area, LatLng::WrapMode wrap /*=
}
LatLng LatLngBounds::constrain(const LatLng& p) const {
+ if (!bounded) {
+ return p;
+ }
+
double lat = p.latitude();
double lng = p.longitude();