Skip to content

Commit

Permalink
Merge pull request #5668 from burn123/flyToZoomLimits
Browse files Browse the repository at this point in the history
Fix viewer.flyTo ignoring and resetting minimumZoomDistance
  • Loading branch information
Hannah authored Jul 31, 2017
2 parents 9c8d6d1 + 0ccf646 commit 3dd45ba
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions Source/DataSources/EntityView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -2870,6 +2872,7 @@ define([
} else {
offset.range = distanceToBoundingSphere3D(camera, radius);
}
offset.range = CesiumMath.clamp(offset.range, minimumZoom, maximumZoom);
}

return offset;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions Specs/Scene/CameraSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3dd45ba

Please sign in to comment.