[core] Added ConstrainMode::{HeightOnly,WidthAndHeight}
ConstrainMode gives flexibility to our engine to choose between constraining both vertically and horizontally, or just vertically (default behavior). Constrain in both axis means we can no longer pan the map beyond the map boundaries. This fixes an issue where e.g. annotations disappear upon crossing the map boundaries.
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
TransformState::TransformState()
|
||||
TransformState::TransformState(ConstrainMode constrainMode_)
|
||||
: constrainMode(constrainMode_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -143,8 +144,9 @@ double TransformState::getScale() const {
|
||||
|
||||
double TransformState::getMinZoom() const {
|
||||
double test_scale = scale;
|
||||
double test_y = y;
|
||||
constrain(test_scale, test_y);
|
||||
double unused_x = x;
|
||||
double unused_y = y;
|
||||
constrain(test_scale, unused_x, unused_y);
|
||||
|
||||
return ::log2(::fmin(min_scale, test_scale));
|
||||
}
|
||||
@@ -316,17 +318,22 @@ mat4 TransformState::getPixelMatrix() const {
|
||||
|
||||
#pragma mark - (private helper functions)
|
||||
|
||||
void TransformState::constrain(double& scale_, double& y_) const {
|
||||
// Constrain minimum zoom to avoid zooming out far enough to show off-world areas.
|
||||
if (scale_ < height / util::tileSize) {
|
||||
scale_ = height / util::tileSize;
|
||||
void TransformState::constrain(double& scale_, double& x_, double& y_) const {
|
||||
// Constrain minimum scale to avoid zooming out far enough to show off-world areas.
|
||||
if (constrainMode == ConstrainMode::WidthAndHeight) {
|
||||
scale_ = std::max(scale_, static_cast<double>(width / util::tileSize));
|
||||
}
|
||||
|
||||
// Constrain min/max vertical pan to avoid showing off-world areas.
|
||||
double max_y = ((scale_ * util::tileSize) - height) / 2;
|
||||
scale_ = std::max(scale_, static_cast<double>(height / util::tileSize));
|
||||
|
||||
if (y_ > max_y) y_ = max_y;
|
||||
if (y_ < -max_y) y_ = -max_y;
|
||||
// Constrain min/max pan to avoid showing off-world areas.
|
||||
if (constrainMode == ConstrainMode::WidthAndHeight) {
|
||||
double max_x = (scale_ * util::tileSize - width) / 2;
|
||||
x_ = std::max(-max_x, std::min(x_, max_x));
|
||||
}
|
||||
|
||||
double max_y = (scale_ * util::tileSize - height) / 2;
|
||||
y_ = std::max(-max_y, std::min(y_, max_y));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user