diff --git a/CHANGES.md b/CHANGES.md index 5e0e29d56022..a767204e2aca 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -29,6 +29,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 3f957272d903..f7155fc5c35e 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -2860,6 +2860,8 @@ define([ offset = HeadingPitchRange.clone(Camera.DEFAULT_OFFSET); } + 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; @@ -2870,6 +2872,7 @@ define([ } else { offset.range = distanceToBoundingSphere3D(camera, radius); } + offset.range = CesiumMath.clamp(offset.range, minimumZoom, maximumZoom); } return offset; @@ -2950,7 +2953,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 7ca93367ca3c..ceab4b056c03 100644 --- a/Source/Widgets/Viewer/Viewer.js +++ b/Source/Widgets/Viewer/Viewer.js @@ -1914,8 +1914,6 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to viewer.trackedEntity = undefined; 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); diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index 786ee962f3a5..0e9641dcfde0 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 minValue = 1000; + scene.screenSpaceCameraController.minimumZoomDistance = minValue; + + 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, minValue, 0.1)).toBe(true); + }); + + it('flyToBoundingSphere does not zoom further than maximumZoomDistance', function() { + scene.mode = SceneMode.SCENE3D; + var maxValue = 10000; + scene.screenSpaceCameraController.maximumZoomDistance = maxValue; + + 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, maxValue, 0.1)).toBe(true); + }); + it('distanceToBoundingSphere', function() { scene.mode = SceneMode.SCENE3D;