From 04e31a86000bf80163e34e433dc075e92e86f05e Mon Sep 17 00:00:00 2001 From: Cody Date: Sat, 22 Jul 2017 19:34:28 -0400 Subject: [PATCH 1/9] Fix minimum zoom getting reset on flyTo --- Source/Widgets/Viewer/Viewer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Widgets/Viewer/Viewer.js b/Source/Widgets/Viewer/Viewer.js index 7ca93367ca3c..817689e8ca5e 100644 --- a/Source/Widgets/Viewer/Viewer.js +++ b/Source/Widgets/Viewer/Viewer.js @@ -1870,6 +1870,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to var zoomPromise = viewer._zoomPromise; var zoomOptions = defaultValue(viewer._zoomOptions, {}); +console.log('hey'); //If zoomTarget was an ImageryLayer if (entities instanceof Rectangle) { var options = { @@ -1915,7 +1916,6 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to var boundingSphere = BoundingSphere.fromBoundingSpheres(boundingSpheres); var controller = scene.screenSpaceCameraController; - controller.minimumZoomDistance = Math.min(controller.minimumZoomDistance, boundingSphere.radius * 0.5); if (!viewer._zoomIsFlight) { camera.viewBoundingSphere(boundingSphere, viewer._zoomOptions); From d1c876a80994e2638bfd8cf07bb55fa6bfde1e2e Mon Sep 17 00:00:00 2001 From: Cody Date: Sat, 22 Jul 2017 19:34:59 -0400 Subject: [PATCH 2/9] Fix flyTo going past minimum zoom for billboards --- Source/Scene/Camera.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 3f957272d903..91eeee60b632 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2853,12 +2853,12 @@ define([ return Math.max(right, top) * 1.50; } - var MINIMUM_ZOOM = 100.0; - function adjustBoundingSphereOffset(camera, boundingSphere, offset) { if (!defined(offset)) { offset = HeadingPitchRange.clone(Camera.DEFAULT_OFFSET); } + + var MINIMUM_ZOOM = camera._scene.screenSpaceCameraController.minimumZoomDistance; var range = offset.range; if (!defined(range) || range === 0.0) { From 2676a5ee43ecef39eedcb1ccda1470dc2e93f4ee Mon Sep 17 00:00:00 2001 From: Cody Date: Sat, 22 Jul 2017 19:36:13 -0400 Subject: [PATCH 3/9] Remove console statement --- Source/Widgets/Viewer/Viewer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Widgets/Viewer/Viewer.js b/Source/Widgets/Viewer/Viewer.js index 817689e8ca5e..f8713d048f6d 100644 --- a/Source/Widgets/Viewer/Viewer.js +++ b/Source/Widgets/Viewer/Viewer.js @@ -1870,7 +1870,6 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to var zoomPromise = viewer._zoomPromise; var zoomOptions = defaultValue(viewer._zoomOptions, {}); -console.log('hey'); //If zoomTarget was an ImageryLayer if (entities instanceof Rectangle) { var options = { From bcb14c7efe57df16b1b2144b7a2e1cf745db799a Mon Sep 17 00:00:00 2001 From: Cody Date: Sat, 22 Jul 2017 21:43:40 -0400 Subject: [PATCH 4/9] Handle case when outside maximumZoomDistance, or when the zoomDistances haven't been set --- CHANGES.md | 1 + Source/DataSources/EntityView.js | 3 --- Source/Scene/Camera.js | 13 +++++++++---- Source/Widgets/Viewer/Viewer.js | 1 - 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8dc9ee882d44..464b00dbdd30 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,6 +23,7 @@ Change Log * Fixed crash when using the `Cesium3DTilesInspectorViewModel` and removing a tileset [#5607](https://github.com/AnalyticalGraphicsInc/cesium/issues/5607) * Fixed polygon outline in Polygon Sandcastle demo [#5642](https://github.com/AnalyticalGraphicsInc/cesium/issues/5642) * Fixed label positioning when using `HeightReference.CLAMP_TO_GROUND` and no position [#5648](https://github.com/AnalyticalGraphicsInc/cesium/pull/5648) +* Fixed `viewer.flyTo` not respecting zoom limits, and resetting minimumZoomDistance if the camera zoomed past the minimumZoomDistance. [5573](https://github.com/AnalyticalGraphicsInc/cesium/issues/5573) * Updated `Billboard`, `Label` and `PointPrimitive` constructors to clone `NearFarScale` parameters [#5654](https://github.com/AnalyticalGraphicsInc/cesium/pull/5654) * Added `FrustumGeometry` and `FrustumOutlineGeometry`. [#5649](https://github.com/AnalyticalGraphicsInc/cesium/pull/5649) * Added an `options` parameter to the constructors of `PerspectiveFrustum`, `PerspectiveOffCenterFrustum`, `OrthographicFrustum`, and `OrthographicOffCenterFrustum` to set properties. [#5649](https://github.com/AnalyticalGraphicsInc/cesium/pull/5649) diff --git a/Source/DataSources/EntityView.js b/Source/DataSources/EntityView.js index 48e792d5b54d..6ae6914298db 100644 --- a/Source/DataSources/EntityView.js +++ b/Source/DataSources/EntityView.js @@ -317,9 +317,6 @@ define([ var hasViewFrom = defined(viewFromProperty); if (!hasViewFrom && defined(boundingSphere)) { - var controller = scene.screenSpaceCameraController; - controller.minimumZoomDistance = Math.min(controller.minimumZoomDistance, boundingSphere.radius * 0.5); - //The default HPR is not ideal for high altitude objects so //we scale the pitch as we get further from the earth for a more //downward view. diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 91eeee60b632..0176fb25b4a8 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2857,14 +2857,20 @@ define([ if (!defined(offset)) { offset = HeadingPitchRange.clone(Camera.DEFAULT_OFFSET); } - - var MINIMUM_ZOOM = camera._scene.screenSpaceCameraController.minimumZoomDistance; + var DEFAULT_ZOOM = 100.0; + var MINIMUM_ZOOM = camera._scene.screenSpaceCameraController.minimumZoomDistance; + var MAXIMUM_ZOOM = camera._scene.screenSpaceCameraController.maximumZoomDistance; var range = offset.range; if (!defined(range) || range === 0.0) { var radius = boundingSphere.radius; - if (radius === 0.0) { + // If the minimumZoomDistance hasn't been set yet, it is equal to 1, + if (radius < MINIMUM_ZOOM && MINIMUM_ZOOM > 1) { offset.range = MINIMUM_ZOOM; + } else if(radius > MAXIMUM_ZOOM) { + offset.range = MAXIMUM_ZOOM; + } else if(radius === 0) { + offset.range = DEFAULT_ZOOM; } else if (camera.frustum instanceof OrthographicFrustum || camera._mode === SceneMode.SCENE2D) { offset.range = distanceToBoundingSphere2D(camera, radius); } else { @@ -2950,7 +2956,6 @@ define([ //>>includeEnd('debug'); options = defaultValue(options, defaultValue.EMPTY_OBJECT); - var scene2D = this._mode === SceneMode.SCENE2D || this._mode === SceneMode.COLUMBUS_VIEW; this._setTransform(Matrix4.IDENTITY); var offset = adjustBoundingSphereOffset(this, boundingSphere, options.offset); diff --git a/Source/Widgets/Viewer/Viewer.js b/Source/Widgets/Viewer/Viewer.js index f8713d048f6d..ceab4b056c03 100644 --- a/Source/Widgets/Viewer/Viewer.js +++ b/Source/Widgets/Viewer/Viewer.js @@ -1914,7 +1914,6 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to viewer.trackedEntity = undefined; var boundingSphere = BoundingSphere.fromBoundingSpheres(boundingSpheres); - var controller = scene.screenSpaceCameraController; if (!viewer._zoomIsFlight) { camera.viewBoundingSphere(boundingSphere, viewer._zoomOptions); From e04bf0f0adeec38705045d26e50368741f3353f5 Mon Sep 17 00:00:00 2001 From: Cody Date: Sun, 23 Jul 2017 13:25:23 -0400 Subject: [PATCH 5/9] Write tests for Camera to not fly outside limits on flyToBoundingSphere --- Specs/Scene/CameraSpec.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index 786ee962f3a5..b545ea0cf0a5 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -2605,6 +2605,36 @@ defineSuite([ expect(distance).toBeLessThan(sphere.radius * 3.0); }); + it('flyToBoundingSphere does not zoom closer than minimumZoomDistance', function() { + scene.mode = SceneMode.SCENE3D; + var MIN_VALUE = 1000; + scene.screenSpaceCameraController.minimumZoomDistance = MIN_VALUE; + + var sphere = new BoundingSphere(Cartesian3.fromDegrees(-117.16, 32.71, 0.0), 10.0); + + camera.flyToBoundingSphere(sphere, { + duration : 0.0 + }); + + var distance = Cartesian3.distance(camera.position, sphere.center); + expect(CesiumMath.equalsEpsilon(distance, MIN_VALUE, 0.1)).toBe(true); + }); + + it('flyToBoundingSphere does not zoom further than maximumZoomDistance', function() { + scene.mode = SceneMode.SCENE3D; + var MAX_VALUE = 10000; + scene.screenSpaceCameraController.maximumZoomDistance = MAX_VALUE; + + var sphere = new BoundingSphere(Cartesian3.fromDegrees(-117.16, 32.71, 0.0), 100000); + + camera.flyToBoundingSphere(sphere, { + duration : 0.0 + }); + + var distance = Cartesian3.distance(camera.position, sphere.center); + expect(CesiumMath.equalsEpsilon(distance, MAX_VALUE, 0.1)).toBe(true); + }); + it('distanceToBoundingSphere', function() { scene.mode = SceneMode.SCENE3D; From 875b4c899a4c5b31656257373cc4aae6ac301bd6 Mon Sep 17 00:00:00 2001 From: Cody Guldner Date: Mon, 24 Jul 2017 10:42:53 -0400 Subject: [PATCH 6/9] Change some variable names to camelCase --- CHANGES.md | 2 +- Source/Scene/Camera.js | 16 ++++++++-------- Specs/Scene/CameraSpec.js | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 464b00dbdd30..9dae1e7db16c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,7 +23,7 @@ Change Log * Fixed crash when using the `Cesium3DTilesInspectorViewModel` and removing a tileset [#5607](https://github.com/AnalyticalGraphicsInc/cesium/issues/5607) * Fixed polygon outline in Polygon Sandcastle demo [#5642](https://github.com/AnalyticalGraphicsInc/cesium/issues/5642) * Fixed label positioning when using `HeightReference.CLAMP_TO_GROUND` and no position [#5648](https://github.com/AnalyticalGraphicsInc/cesium/pull/5648) -* Fixed `viewer.flyTo` not respecting zoom limits, and resetting minimumZoomDistance if the camera zoomed past the minimumZoomDistance. [5573](https://github.com/AnalyticalGraphicsInc/cesium/issues/5573) +* Fixed `Viewer.flyTo` not respecting zoom limits, and resetting minimumZoomDistance if the camera zoomed past the minimumZoomDistance. [5573](https://github.com/AnalyticalGraphicsInc/cesium/issues/5573) * Updated `Billboard`, `Label` and `PointPrimitive` constructors to clone `NearFarScale` parameters [#5654](https://github.com/AnalyticalGraphicsInc/cesium/pull/5654) * Added `FrustumGeometry` and `FrustumOutlineGeometry`. [#5649](https://github.com/AnalyticalGraphicsInc/cesium/pull/5649) * Added an `options` parameter to the constructors of `PerspectiveFrustum`, `PerspectiveOffCenterFrustum`, `OrthographicFrustum`, and `OrthographicOffCenterFrustum` to set properties. [#5649](https://github.com/AnalyticalGraphicsInc/cesium/pull/5649) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 0176fb25b4a8..1aec4fd420f4 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2858,19 +2858,19 @@ define([ offset = HeadingPitchRange.clone(Camera.DEFAULT_OFFSET); } - var DEFAULT_ZOOM = 100.0; - var MINIMUM_ZOOM = camera._scene.screenSpaceCameraController.minimumZoomDistance; - var MAXIMUM_ZOOM = camera._scene.screenSpaceCameraController.maximumZoomDistance; + var defaultZoom = 100.0; + var minimumZoom = camera._scene.screenSpaceCameraController.minimumZoomDistance; + var maximumZoom = camera._scene.screenSpaceCameraController.maximumZoomDistance; var range = offset.range; if (!defined(range) || range === 0.0) { var radius = boundingSphere.radius; // If the minimumZoomDistance hasn't been set yet, it is equal to 1, - if (radius < MINIMUM_ZOOM && MINIMUM_ZOOM > 1) { - offset.range = MINIMUM_ZOOM; - } else if(radius > MAXIMUM_ZOOM) { - offset.range = MAXIMUM_ZOOM; + if (radius < minimumZoom && minimumZoom > 1) { + offset.range = minimumZoom; + } else if(radius > maximumZoom) { + offset.range = maximumZoom; } else if(radius === 0) { - offset.range = DEFAULT_ZOOM; + offset.range = defaultZoom; } else if (camera.frustum instanceof OrthographicFrustum || camera._mode === SceneMode.SCENE2D) { offset.range = distanceToBoundingSphere2D(camera, radius); } else { diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index b545ea0cf0a5..0e9641dcfde0 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -2607,8 +2607,8 @@ defineSuite([ it('flyToBoundingSphere does not zoom closer than minimumZoomDistance', function() { scene.mode = SceneMode.SCENE3D; - var MIN_VALUE = 1000; - scene.screenSpaceCameraController.minimumZoomDistance = MIN_VALUE; + var minValue = 1000; + scene.screenSpaceCameraController.minimumZoomDistance = minValue; var sphere = new BoundingSphere(Cartesian3.fromDegrees(-117.16, 32.71, 0.0), 10.0); @@ -2617,13 +2617,13 @@ defineSuite([ }); var distance = Cartesian3.distance(camera.position, sphere.center); - expect(CesiumMath.equalsEpsilon(distance, MIN_VALUE, 0.1)).toBe(true); + expect(CesiumMath.equalsEpsilon(distance, minValue, 0.1)).toBe(true); }); it('flyToBoundingSphere does not zoom further than maximumZoomDistance', function() { scene.mode = SceneMode.SCENE3D; - var MAX_VALUE = 10000; - scene.screenSpaceCameraController.maximumZoomDistance = MAX_VALUE; + var maxValue = 10000; + scene.screenSpaceCameraController.maximumZoomDistance = maxValue; var sphere = new BoundingSphere(Cartesian3.fromDegrees(-117.16, 32.71, 0.0), 100000); @@ -2632,7 +2632,7 @@ defineSuite([ }); var distance = Cartesian3.distance(camera.position, sphere.center); - expect(CesiumMath.equalsEpsilon(distance, MAX_VALUE, 0.1)).toBe(true); + expect(CesiumMath.equalsEpsilon(distance, maxValue, 0.1)).toBe(true); }); it('distanceToBoundingSphere', function() { From 4ba29645d7e3c55f56ea54991ae5e56f47ded860 Mon Sep 17 00:00:00 2001 From: Cody Guldner Date: Mon, 24 Jul 2017 12:28:05 -0400 Subject: [PATCH 7/9] Simplify if statement --- Source/Scene/Camera.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 1aec4fd420f4..e7166a54c873 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2864,18 +2864,14 @@ define([ var range = offset.range; if (!defined(range) || range === 0.0) { var radius = boundingSphere.radius; - // If the minimumZoomDistance hasn't been set yet, it is equal to 1, - if (radius < minimumZoom && minimumZoom > 1) { - offset.range = minimumZoom; - } else if(radius > maximumZoom) { - offset.range = maximumZoom; - } else if(radius === 0) { + if(radius === 0) { offset.range = defaultZoom; } else if (camera.frustum instanceof OrthographicFrustum || camera._mode === SceneMode.SCENE2D) { offset.range = distanceToBoundingSphere2D(camera, radius); } else { offset.range = distanceToBoundingSphere3D(camera, radius); } + offset.range = CesiumMath.clamp(offset.range, minimumZoom, maximumZoom); } return offset; From 9d00cbd35c93caa66956f9c3a13d21dba3e5ca02 Mon Sep 17 00:00:00 2001 From: Cody Date: Fri, 28 Jul 2017 16:18:31 -0400 Subject: [PATCH 8/9] Style changes --- Source/Scene/Camera.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index e7166a54c873..acb2bfc9ca6e 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2853,19 +2853,20 @@ define([ return Math.max(right, top) * 1.50; } + var MINIMUM_ZOOM = 100.0; + function adjustBoundingSphereOffset(camera, boundingSphere, offset) { if (!defined(offset)) { offset = HeadingPitchRange.clone(Camera.DEFAULT_OFFSET); } - var defaultZoom = 100.0; var minimumZoom = camera._scene.screenSpaceCameraController.minimumZoomDistance; var maximumZoom = camera._scene.screenSpaceCameraController.maximumZoomDistance; var range = offset.range; if (!defined(range) || range === 0.0) { var radius = boundingSphere.radius; - if(radius === 0) { - offset.range = defaultZoom; + if (radius === 0) { + offset.range = MINIMUM_ZOOM; } else if (camera.frustum instanceof OrthographicFrustum || camera._mode === SceneMode.SCENE2D) { offset.range = distanceToBoundingSphere2D(camera, radius); } else { From 0ccf646426b42cc6816675ace8ba8ce0d30e6cd5 Mon Sep 17 00:00:00 2001 From: Cody Date: Fri, 28 Jul 2017 16:19:18 -0400 Subject: [PATCH 9/9] Style changes --- Source/Scene/Camera.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index acb2bfc9ca6e..f7155fc5c35e 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2865,7 +2865,7 @@ define([ var range = offset.range; if (!defined(range) || range === 0.0) { var radius = boundingSphere.radius; - if (radius === 0) { + if (radius === 0.0) { offset.range = MINIMUM_ZOOM; } else if (camera.frustum instanceof OrthographicFrustum || camera._mode === SceneMode.SCENE2D) { offset.range = distanceToBoundingSphere2D(camera, radius);