[core] Added {set,get}{Min,Max}Pitch

This commit is contained in:
Bruno de Oliveira Abinader
2017-04-03 18:37:03 +03:00
parent c1c6c1e298
commit c4fc89977b
7 changed files with 83 additions and 2 deletions

View File

@@ -117,6 +117,10 @@ public:
double getMinZoom() const;
void setMaxZoom(double);
double getMaxZoom() const;
void setMinPitch(double);
double getMinPitch() const;
void setMaxPitch(double);
double getMaxPitch() const;
// Rotation
void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {});

View File

@@ -698,6 +698,28 @@ double Map::getMaxZoom() const {
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
void Map::setSize(const Size size) {

View File

@@ -120,7 +120,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
// Constrain camera options.
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
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;
@@ -188,7 +188,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, 0., util::PITCH_MAX);
pitch = util::clamp(pitch, state.min_pitch, state.max_pitch);
// Minimize rotation by taking the shorter path around the circle.
angle = _normalizeAngle(angle, state.angle);
@@ -451,6 +451,16 @@ void Transform::setMaxZoom(const double 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
void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& animation) {

View File

@@ -60,6 +60,8 @@ public:
void setLatLngBounds(const LatLngBounds&);
void setMinZoom(double);
void setMaxZoom(double);
void setMinPitch(double);
void setMaxPitch(double);
// Zoom

View File

@@ -176,6 +176,25 @@ double TransformState::getMaxZoom() const {
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

View File

@@ -57,6 +57,10 @@ public:
double getMinZoom() const;
void setMaxZoom(double);
double getMaxZoom() const;
void setMinPitch(double);
double getMinPitch() const;
void setMaxPitch(double);
double getMaxPitch() const;
// Rotation
float getAngle() const;
@@ -91,6 +95,8 @@ private:
// Limit the amount of zooming possible on the map.
double min_scale = std::pow(2, 0);
double max_scale = std::pow(2, 20);
double min_pitch = 0.0;
double max_pitch = util::PITCH_MAX;
NorthOrientation orientation = NorthOrientation::Upwards;

View File

@@ -573,3 +573,21 @@ TEST(Transform, LatLngBounds) {
ASSERT_EQ(transform.getLatLng().latitude(), 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);
}