Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Transform::flyTo invalid zoom checks #9381

Merged
merged 2 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
Point<double> framePoint = util::interpolate(startPoint, endPoint, us);
double frameZoom = startZoom + state.scaleZoom(1 / w(s));

// Zoom can be NaN if size is empty.
if (std::isnan(frameZoom)) {
frameZoom = zoom;
}

// Convert to geographic coordinates and set the new viewpoint.
LatLng frameLatLng = Projection::unproject(framePoint, startScale);
state.setLatLngZoom(frameLatLng, frameZoom);
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void TransformState::setLatLngZoom(const LatLng& latLng, double zoom) {
constrained = bounds->constrain(latLng);
}

double newScale = zoomScale(zoom);
double newScale = util::clamp(zoomScale(zoom), min_scale, max_scale);
const double newWorldSize = newScale * util::tileSize;
Bc = newWorldSize / util::DEGREES_MAX;
Cc = newWorldSize / util::M2PI;
Expand Down
21 changes: 21 additions & 0 deletions test/map/transform.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ TEST(Transform, InvalidZoom) {
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
ASSERT_DOUBLE_EQ(1, transform.getZoom());

transform.setZoom(transform.getState().getMaxZoom() + 0.1);
ASSERT_DOUBLE_EQ(transform.getZoom(), transform.getState().getMaxZoom());

CameraOptions cameraOptions;
cameraOptions.center = LatLng { util::LATITUDE_MAX, util::LONGITUDE_MAX };
cameraOptions.zoom = transform.getState().getMaxZoom();

// Executing flyTo with an empty size causes frameZoom to be NaN.
transform.flyTo(cameraOptions);
transform.updateTransitions(transform.getTransitionStart() + transform.getTransitionDuration());
ASSERT_DOUBLE_EQ(transform.getZoom(), transform.getState().getMaxZoom());

// Executing flyTo with maximum zoom level to the same zoom level causes
// frameZoom to be bigger than maximum zoom.
transform.resize(Size { 100, 100 });
transform.flyTo(cameraOptions);
transform.updateTransitions(transform.getTransitionStart() + transform.getTransitionDuration());

ASSERT_TRUE(transform.getState().valid());
ASSERT_DOUBLE_EQ(transform.getState().getMaxZoom(), transform.getZoom());
}


Expand Down