diff --git a/CHANGES.md b/CHANGES.md index 900440b2f9f8..42cd1514f328 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ Beta Releases * Breaking changes: * Renamed `Viewer.automaticallyTrackFirstDataSourceClock` to `Viewer.automaticallyTrackDataSourceClocks`. * Added new `SelectionIndicator` and `InfoBox` widgets to `Viewer`, activated by `viewerDynamicObjectMixin`. +* Fix developer error when zooming in 2D. If the zoom would create an invalid frustum, nothing is done. [#1432](https://github.com/AnalyticalGraphicsInc/cesium/issues/1432) * `OpenStreetMapImageryProvider` now supports imagery with a minimum level. * Improved the quality of imagery near the poles when the imagery source uses a `GeographicTilingScheme`. * `CesiumTerrainProvider` now supports mesh-based terrain like the tiles created by STK Terrain Server. diff --git a/Source/Scene/CameraController.js b/Source/Scene/CameraController.js index 5178369ea7f1..448266c3cab7 100644 --- a/Source/Scene/CameraController.js +++ b/Source/Scene/CameraController.js @@ -639,6 +639,11 @@ define([ newLeft = -maxRight; } + if (newRight <= newLeft) { + newRight = 1.0; + newLeft = -1.0; + } + var ratio = frustum.top / frustum.right; frustum.right = newRight; frustum.left = newLeft; diff --git a/Source/Scene/ScreenSpaceCameraController.js b/Source/Scene/ScreenSpaceCameraController.js index 6c2b22e36ebb..1d2ae2bd4f46 100644 --- a/Source/Scene/ScreenSpaceCameraController.js +++ b/Source/Scene/ScreenSpaceCameraController.js @@ -446,9 +446,11 @@ define([ var p1 = Cartesian3.subtract(end, position, scratchTranslateP1); var direction = Cartesian3.subtract(p0, p1, scratchTranslateP0); var distance = Cartesian3.magnitude(direction); - Cartesian3.normalize(direction, direction); - cameraController.move(direction, distance); + if (distance > 0.0) { + Cartesian3.normalize(direction, direction); + cameraController.move(direction, distance); + } } function zoom2D(controller, movement) { diff --git a/Specs/Scene/CameraControllerSpec.js b/Specs/Scene/CameraControllerSpec.js index 86e98385bf63..0aaccc83d507 100644 --- a/Specs/Scene/CameraControllerSpec.js +++ b/Specs/Scene/CameraControllerSpec.js @@ -416,7 +416,7 @@ defineSuite([ expect(camera.frustum.bottom).toEqual(-0.75, CesiumMath.EPSILON10); }); - it('clamps zoom in 2D', function() { + it('clamps zoom out in 2D', function() { var frustum = new OrthographicFrustum(); frustum.near = 1.0; frustum.far = 2.0; @@ -442,6 +442,29 @@ defineSuite([ expect(frustum.bottom).toEqual(-frustum.top); }); + it('clamps zoom in in 2D', function() { + var frustum = new OrthographicFrustum(); + frustum.near = 1.0; + frustum.far = 2.0; + frustum.left = -2.0; + frustum.right = 2.0; + frustum.top = 1.0; + frustum.bottom = -1.0; + camera.frustum = frustum; + + var ellipsoid = Ellipsoid.WGS84; + var projection = new GeographicProjection(ellipsoid); + controller.update(SceneMode.SCENE2D, { projection : projection }); + + var max = projection.project(new Cartographic(Math.PI, CesiumMath.toRadians(85.05112878))); + var factor = 1000.0; + var dx = max.x * factor; + + controller.zoomIn(dx * 2.0); + expect(frustum.right).toEqual(1.0); + expect(frustum.left).toEqual(-1.0); + }); + it('zooms in 3D', function() { controller.zoomIn(zoomAmount); expect(camera.position).toEqualEpsilon(new Cartesian3(0.0, 0.0, 1.0 - zoomAmount), CesiumMath.EPSILON10);