[core] Added {set,get}{Min,Max}Pitch
This commit is contained in:
@@ -117,6 +117,10 @@ public:
|
|||||||
double getMinZoom() const;
|
double getMinZoom() const;
|
||||||
void setMaxZoom(double);
|
void setMaxZoom(double);
|
||||||
double getMaxZoom() const;
|
double getMaxZoom() const;
|
||||||
|
void setMinPitch(double);
|
||||||
|
double getMinPitch() const;
|
||||||
|
void setMaxPitch(double);
|
||||||
|
double getMaxPitch() const;
|
||||||
|
|
||||||
// Rotation
|
// Rotation
|
||||||
void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {});
|
void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {});
|
||||||
|
|||||||
@@ -698,6 +698,28 @@ double Map::getMaxZoom() const {
|
|||||||
return impl->transform.getState().getMaxZoom();
|
return impl->transform.getState().getMaxZoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Map::setMinPitch(double minPitch) {
|
||||||
|
impl->transform.setMinPitch(minPitch * util::DEG2RAD);
|
||||||
|
if (getPitch() < minPitch) {
|
||||||
|
setPitch(minPitch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double Map::getMinPitch() const {
|
||||||
|
return impl->transform.getState().getMinPitch() * util::RAD2DEG;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::setMaxPitch(double maxPitch) {
|
||||||
|
impl->transform.setMaxPitch(maxPitch * util::DEG2RAD);
|
||||||
|
if (getPitch() > maxPitch) {
|
||||||
|
setPitch(maxPitch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double Map::getMaxPitch() const {
|
||||||
|
return impl->transform.getState().getMaxPitch() * util::RAD2DEG;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Size
|
#pragma mark - Size
|
||||||
|
|
||||||
void Map::setSize(const Size size) {
|
void Map::setSize(const Size size) {
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
|
|||||||
// Constrain camera options.
|
// Constrain camera options.
|
||||||
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
|
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
|
||||||
const double scale = state.zoomScale(zoom);
|
const double scale = state.zoomScale(zoom);
|
||||||
pitch = util::clamp(pitch, 0., util::PITCH_MAX);
|
pitch = util::clamp(pitch, state.min_pitch, state.max_pitch);
|
||||||
|
|
||||||
Update update = state.getZoom() == zoom ? Update::Repaint : Update::RecalculateStyle;
|
Update update = state.getZoom() == zoom ? Update::Repaint : Update::RecalculateStyle;
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
|
|||||||
|
|
||||||
// Constrain camera options.
|
// Constrain camera options.
|
||||||
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
|
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
|
||||||
pitch = util::clamp(pitch, 0., util::PITCH_MAX);
|
pitch = util::clamp(pitch, state.min_pitch, state.max_pitch);
|
||||||
|
|
||||||
// Minimize rotation by taking the shorter path around the circle.
|
// Minimize rotation by taking the shorter path around the circle.
|
||||||
angle = _normalizeAngle(angle, state.angle);
|
angle = _normalizeAngle(angle, state.angle);
|
||||||
@@ -451,6 +451,16 @@ void Transform::setMaxZoom(const double maxZoom) {
|
|||||||
state.setMaxZoom(maxZoom);
|
state.setMaxZoom(maxZoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Transform::setMinPitch(double minPitch) {
|
||||||
|
if (std::isnan(minPitch)) return;
|
||||||
|
state.setMinPitch(minPitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transform::setMaxPitch(double maxPitch) {
|
||||||
|
if (std::isnan(maxPitch)) return;
|
||||||
|
state.setMaxPitch(maxPitch);
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Angle
|
#pragma mark - Angle
|
||||||
|
|
||||||
void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& animation) {
|
void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& animation) {
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ public:
|
|||||||
void setLatLngBounds(const LatLngBounds&);
|
void setLatLngBounds(const LatLngBounds&);
|
||||||
void setMinZoom(double);
|
void setMinZoom(double);
|
||||||
void setMaxZoom(double);
|
void setMaxZoom(double);
|
||||||
|
void setMinPitch(double);
|
||||||
|
void setMaxPitch(double);
|
||||||
|
|
||||||
// Zoom
|
// Zoom
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,25 @@ double TransformState::getMaxZoom() const {
|
|||||||
return scaleZoom(max_scale);
|
return scaleZoom(max_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TransformState::setMinPitch(double minPitch) {
|
||||||
|
if (minPitch <= getMaxPitch()) {
|
||||||
|
min_pitch = minPitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double TransformState::getMinPitch() const {
|
||||||
|
return min_pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TransformState::setMaxPitch(double maxPitch) {
|
||||||
|
if (maxPitch >= getMinPitch()) {
|
||||||
|
max_pitch = maxPitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double TransformState::getMaxPitch() const {
|
||||||
|
return max_pitch;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Rotation
|
#pragma mark - Rotation
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ public:
|
|||||||
double getMinZoom() const;
|
double getMinZoom() const;
|
||||||
void setMaxZoom(double);
|
void setMaxZoom(double);
|
||||||
double getMaxZoom() const;
|
double getMaxZoom() const;
|
||||||
|
void setMinPitch(double);
|
||||||
|
double getMinPitch() const;
|
||||||
|
void setMaxPitch(double);
|
||||||
|
double getMaxPitch() const;
|
||||||
|
|
||||||
// Rotation
|
// Rotation
|
||||||
float getAngle() const;
|
float getAngle() const;
|
||||||
@@ -91,6 +95,8 @@ private:
|
|||||||
// Limit the amount of zooming possible on the map.
|
// Limit the amount of zooming possible on the map.
|
||||||
double min_scale = std::pow(2, 0);
|
double min_scale = std::pow(2, 0);
|
||||||
double max_scale = std::pow(2, 20);
|
double max_scale = std::pow(2, 20);
|
||||||
|
double min_pitch = 0.0;
|
||||||
|
double max_pitch = util::PITCH_MAX;
|
||||||
|
|
||||||
NorthOrientation orientation = NorthOrientation::Upwards;
|
NorthOrientation orientation = NorthOrientation::Upwards;
|
||||||
|
|
||||||
|
|||||||
@@ -573,3 +573,21 @@ TEST(Transform, LatLngBounds) {
|
|||||||
ASSERT_EQ(transform.getLatLng().latitude(), 0.0);
|
ASSERT_EQ(transform.getLatLng().latitude(), 0.0);
|
||||||
ASSERT_EQ(transform.getLatLng().longitude(), 0.0);
|
ASSERT_EQ(transform.getLatLng().longitude(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Transform, PitchBounds) {
|
||||||
|
Transform transform;
|
||||||
|
transform.resize({ 1000, 1000 });
|
||||||
|
transform.setLatLngZoom({ 0, 0 }, transform.getState().getMaxZoom());
|
||||||
|
|
||||||
|
ASSERT_DOUBLE_EQ(transform.getState().getPitch() * util::RAD2DEG, 0.0);
|
||||||
|
ASSERT_DOUBLE_EQ(transform.getState().getMinPitch() * util::RAD2DEG, 0.0);
|
||||||
|
ASSERT_DOUBLE_EQ(transform.getState().getMaxPitch() * util::RAD2DEG, 60.0);
|
||||||
|
|
||||||
|
transform.setMinPitch(45.0 * util::DEG2RAD);
|
||||||
|
transform.setPitch(0.0 * util::DEG2RAD);
|
||||||
|
ASSERT_NEAR(transform.getState().getPitch() * util::RAD2DEG, 45.0, 1e-5);
|
||||||
|
|
||||||
|
transform.setMaxPitch(55.0 * util::DEG2RAD);
|
||||||
|
transform.setPitch(60.0 * util::DEG2RAD);
|
||||||
|
ASSERT_NEAR(transform.getState().getPitch() * util::RAD2DEG, 55.0, 1e-5);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user