Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom2D Bug Fix #5421

Merged
merged 4 commits into from
Jun 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Change Log
* Fixed bug where if polylines were set to follow the surface of an undefined globe, Cesium would crash [#5413] https://github.com/AnalyticalGraphicsInc/cesium/pull/5413
* Fixed a bug where picking clusters would return undefined instead of a list of the clustered entities. [#5286](https://github.com/AnalyticalGraphicsInc/cesium/issues/5286)
* Reduced the amount of Sun bloom post-process effect near the horizon. [#5381](https://github.com/AnalyticalGraphicsInc/cesium/issues/5381)
* Fixed a bug where camera zooming worked incorrectly when the display height was greater than the display width [#5421] (https://github.com/AnalyticalGraphicsInc/cesium/pull/5421)
* Added Sandcastle demo for ArcticDEM data. [#5224](https://github.com/AnalyticalGraphicsInc/cesium/issues/5224)

### 1.34 - 2017-06-01
Expand Down
65 changes: 46 additions & 19 deletions Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -1817,30 +1817,57 @@ define([
}
//>>includeEnd('debug');

var ratio;
amount = amount * 0.5;
var newRight = frustum.right - amount;
var newLeft = frustum.left + amount;

var maxRight = camera._maxCoord.x;
if (camera._scene.mapMode2D === MapMode2D.ROTATE) {
maxRight *= camera.maximumZoomFactor;
}
if((Math.abs(frustum.top) + Math.abs(frustum.bottom)) > (Math.abs(frustum.left) + Math.abs(frustum.right))) {
var newTop = frustum.top - amount;
var newBottom = frustum.bottom + amount;

if (newRight > maxRight) {
newRight = maxRight;
newLeft = -maxRight;
}
var maxBottom = camera._maxCoord.y;
if (camera._scene.mapMode2D === MapMode2D.ROTATE) {
maxBottom *= camera.maximumZoomFactor;
}

if (newRight <= newLeft) {
newRight = 1.0;
newLeft = -1.0;
}
if (newBottom > maxBottom) {
newBottom = maxBottom;
newTop = -maxBottom;
}

if (newTop <= newBottom) {
newTop = 1.0;
newBottom = -1.0;
}

ratio = frustum.right / frustum.top;
frustum.top = newTop;
frustum.bottom = newBottom;
frustum.right = frustum.top * ratio;
frustum.left = -frustum.right;
} else {
var newRight = frustum.right - amount;
var newLeft = frustum.left + amount;

var ratio = frustum.top / frustum.right;
frustum.right = newRight;
frustum.left = newLeft;
frustum.top = frustum.right * ratio;
frustum.bottom = -frustum.top;
var maxRight = camera._maxCoord.x;
if (camera._scene.mapMode2D === MapMode2D.ROTATE) {
maxRight *= camera.maximumZoomFactor;
}

if (newRight > maxRight) {
newRight = maxRight;
newLeft = -maxRight;
}

if (newRight <= newLeft) {
newRight = 1.0;
newLeft = -1.0;
}
ratio = frustum.top / frustum.right;
frustum.right = newRight;
frustum.left = newLeft;
frustum.top = frustum.right * ratio;
frustum.bottom = -frustum.top;
}
}

function zoom3D(camera, amount) {
Expand Down
38 changes: 38 additions & 0 deletions Specs/Scene/CameraSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,25 @@ defineSuite([
expect(camera.frustum.bottom).toEqual(-1.25, CesiumMath.EPSILON10);
});

it('zooms out 2D when frustrum has greater height than width', function() {
var frustum = new OrthographicOffCenterFrustum();
frustum.near = 1.0;
frustum.far = 2.0;
frustum.left = -1.0;
frustum.right = 1.0;
frustum.top = 2.0;
frustum.bottom = -2.0;
camera.frustum = frustum;

camera.update(SceneMode.SCENE2D);

camera.zoomOut(zoomAmount);
expect(camera.frustum.right).toEqualEpsilon(1.25, CesiumMath.EPSILON10);
expect(camera.frustum.left).toEqual(-1.25, CesiumMath.EPSILON10);
expect(camera.frustum.top).toEqual(2.5, CesiumMath.EPSILON10);
expect(camera.frustum.bottom).toEqual(-2.5, CesiumMath.EPSILON10);
});

it('zooms in 2D', function() {
var frustum = new OrthographicOffCenterFrustum();
frustum.near = 1.0;
Expand All @@ -1242,6 +1261,25 @@ defineSuite([
expect(camera.frustum.bottom).toEqual(-0.75, CesiumMath.EPSILON10);
});

it('zooms in 2D when frustrum has greater height than width', function() {
var frustum = new OrthographicOffCenterFrustum();
frustum.near = 1.0;
frustum.far = 2.0;
frustum.left = -1.0;
frustum.right = 1.0;
frustum.top = 2.0;
frustum.bottom = -2.0;
camera.frustum = frustum;

camera.update(SceneMode.SCENE2D);

camera.zoomIn(zoomAmount);
expect(camera.frustum.right).toEqualEpsilon(0.75, CesiumMath.EPSILON10);
expect(camera.frustum.left).toEqual(-0.75, CesiumMath.EPSILON10);
expect(camera.frustum.top).toEqual(1.5, CesiumMath.EPSILON10);
expect(camera.frustum.bottom).toEqual(-1.5, CesiumMath.EPSILON10);
});

it('clamps zoom out in 2D', function() {
var frustum = new OrthographicOffCenterFrustum();
frustum.near = 1.0;
Expand Down