summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/map.cpp20
-rw-r--r--src/mbgl/map/transform.cpp24
-rw-r--r--src/mbgl/map/transform.hpp3
-rw-r--r--src/mbgl/map/transform_state.cpp29
-rw-r--r--src/mbgl/map/transform_state.hpp8
5 files changed, 79 insertions, 5 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 061669f560..994cefa868 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -306,6 +306,22 @@ void Map::setBounds(const BoundOptions& options) {
}
}
+ if (options.maxPitch) {
+ impl->transform.setMaxPitch(*options.maxPitch);
+ if (impl->transform.getPitch() > impl->transform.getState().getMaxPitch()) {
+ changeCamera = true;
+ cameraOptions.withPitch(*options.maxPitch);
+ }
+ }
+
+ if (options.minPitch) {
+ impl->transform.setMinPitch(*options.minPitch);
+ if (impl->transform.getPitch() < impl->transform.getState().getMinPitch()) {
+ changeCamera = true;
+ cameraOptions.withPitch(*options.minPitch);
+ }
+ }
+
if (changeCamera) {
jumpTo(cameraOptions);
}
@@ -315,7 +331,9 @@ BoundOptions Map::getBounds() const {
return BoundOptions()
.withLatLngBounds(impl->transform.getState().getLatLngBounds())
.withMinZoom(impl->transform.getState().getMinZoom())
- .withMaxZoom(impl->transform.getState().getMaxZoom());
+ .withMaxZoom(impl->transform.getState().getMaxZoom())
+ .withMinPitch(impl->transform.getState().getMinPitch())
+ .withMaxPitch(impl->transform.getState().getMaxPitch());
}
#pragma mark - Map options
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 9245d7c5bc..b40456ebdc 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -123,7 +123,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
// Constrain camera options.
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
- pitch = util::clamp(pitch, util::PITCH_MIN, util::PITCH_MAX);
+ pitch = util::clamp(pitch, state.getMinPitch(), state.getMaxPitch());
// Minimize rotation by taking the shorter path around the circle.
bearing = _normalizeAngle(bearing, state.getBearing());
@@ -196,7 +196,7 @@ void Transform::flyTo(const CameraOptions& camera, const AnimationOptions& anima
// Constrain camera options.
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
- pitch = util::clamp(pitch, util::PITCH_MIN, util::PITCH_MAX);
+ pitch = util::clamp(pitch, state.getMinPitch(), state.getMaxPitch());
// Minimize rotation by taking the shorter path around the circle.
bearing = _normalizeAngle(bearing, state.getBearing());
@@ -379,6 +379,26 @@ void Transform::setMaxZoom(const double maxZoom) {
state.setMaxZoom(maxZoom);
}
+void Transform::setMinPitch(const double minPitch) {
+ if (std::isnan(minPitch)) return;
+ if (minPitch * util::DEG2RAD < util::PITCH_MIN) {
+ Log::Warning(Event::General,
+ "Trying to set minimum pitch below the limit (%.0f degrees), the value will be clamped.",
+ util::PITCH_MIN * util::RAD2DEG);
+ }
+ state.setMinPitch(minPitch * util::DEG2RAD);
+}
+
+void Transform::setMaxPitch(const double maxPitch) {
+ if (std::isnan(maxPitch)) return;
+ if (maxPitch * util::DEG2RAD > util::PITCH_MAX) {
+ Log::Warning(Event::General,
+ "Trying to set maximum pitch above the limit (%.0f degrees), the value will be clamped.",
+ util::PITCH_MAX * util::RAD2DEG);
+ }
+ state.setMaxPitch(maxPitch * util::DEG2RAD);
+}
+
#pragma mark - Bearing
void Transform::rotateBy(const ScreenCoordinate& first,
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 3dd1a3ffc5..3f815fa3f1 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -59,6 +59,9 @@ public:
void setMinZoom(double);
void setMaxZoom(double);
+ void setMinPitch(double);
+ void setMaxPitch(double);
+
// Zoom
/** Returns the zoom level. */
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index c8f1c7f594..c5bb38653a 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -1,11 +1,12 @@
#include <mbgl/map/transform_state.hpp>
+#include <mbgl/math/clamp.hpp>
+#include <mbgl/math/log2.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/interpolate.hpp>
+#include <mbgl/util/logging.hpp>
#include <mbgl/util/projection.hpp>
#include <mbgl/util/tile_coordinate.hpp>
-#include <mbgl/math/log2.hpp>
-#include <mbgl/math/clamp.hpp>
namespace mbgl {
TransformState::TransformState(ConstrainMode constrainMode_, ViewportMode viewportMode_)
@@ -340,6 +341,30 @@ double TransformState::getMaxZoom() const {
return scaleZoom(max_scale);
}
+void TransformState::setMinPitch(const double pitch_) {
+ if (pitch_ <= maxPitch) {
+ minPitch = util::clamp(pitch_, util::PITCH_MIN, maxPitch);
+ } else {
+ Log::Warning(Event::General, "Trying to set minimum pitch to larger than maximum pitch, no changes made.");
+ }
+}
+
+double TransformState::getMinPitch() const {
+ return minPitch;
+}
+
+void TransformState::setMaxPitch(const double pitch_) {
+ if (pitch_ >= minPitch) {
+ maxPitch = util::clamp(pitch_, minPitch, util::PITCH_MAX);
+ } else {
+ Log::Warning(Event::General, "Trying to set maximum pitch to smaller than minimum pitch, no changes made.");
+ }
+}
+
+double TransformState::getMaxPitch() const {
+ return maxPitch;
+}
+
#pragma mark - Scale
double TransformState::getScale() const {
return scale;
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index 8597f3b5df..1561ffc904 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -163,6 +163,10 @@ public:
double getMinZoom() const;
void setMaxZoom(double);
double getMaxZoom() const;
+ void setMinPitch(double);
+ double getMinPitch() const;
+ void setMaxPitch(double);
+ double getMaxPitch() const;
// Rotation
double getBearing() const;
@@ -225,6 +229,10 @@ private:
double min_scale = std::pow(2, 0);
double max_scale = std::pow(2, util::DEFAULT_MAX_ZOOM);
+ // Limit the amount of pitch
+ double minPitch = util::PITCH_MIN;
+ double maxPitch = util::PITCH_MAX;
+
NorthOrientation orientation = NorthOrientation::Upwards;
// logical dimensions