From b6897303ad47944cbc42112c606a28e8e944ab87 Mon Sep 17 00:00:00 2001 From: Brandon Berisford Date: Sun, 11 Aug 2024 14:57:12 -0500 Subject: [PATCH 1/2] make screenSpaceCameraController zoomFactor public. --- CHANGES.md | 12 +++++++ CONTRIBUTORS.md | 1 + .../Scene/ScreenSpaceCameraController.js | 15 +++++--- .../Scene/ScreenSpaceCameraControllerSpec.js | 34 +++++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 76fdfb03e6cc..bfaf713a7bcb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,17 @@ # Change Log +### 1.122 - 2024-08-11 + +#### @cesium/engine + +##### Breaking Changes :mega: + +- `ScreenSpaceCameraController._zoomFactor` replaced with public zoomFactor attribute. + +##### Additions :tada: + +- Exposes `ScreenSpaceCameraController.zoomFactor` to allow adjusting the zoom factor (speed). [#9145](https://github.com/CesiumGS/cesium/pull/9145) + ### 1.121 - 2024-09-01 #### @cesium/engine diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 3596f223f9dd..36a55ad4d5fa 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -392,3 +392,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu - [Zhongxiang Wang](https://github.com/plainheart) - [Tim Schneider](https://github.com/Tim-S) - [Vladislav Yunev](https://github.com/YunVlad) +- [Brandon Berisford](https://github.com/BeyondBelief96) diff --git a/packages/engine/Source/Scene/ScreenSpaceCameraController.js b/packages/engine/Source/Scene/ScreenSpaceCameraController.js index 0a9fc83a1184..44493e3def42 100644 --- a/packages/engine/Source/Scene/ScreenSpaceCameraController.js +++ b/packages/engine/Source/Scene/ScreenSpaceCameraController.js @@ -137,6 +137,14 @@ function ScreenSpaceCameraController(scene) { * @default {@link Number.POSITIVE_INFINITY} */ this.maximumZoomDistance = Number.POSITIVE_INFINITY; + + /** + * A multiplier for the speed at which the camera will zoom. + * @type {Number} + * @default 5.0 + */ + this.zoomFactor = 5.0; + /** * The input that allows the user to pan around the map. This only applies in 2D and Columbus view modes. *

@@ -324,7 +332,6 @@ function ScreenSpaceCameraController(scene) { ); // Constants, Make any of these public? - this._zoomFactor = 5.0; this._rotateFactor = undefined; this._rotateRateRangeAdjustment = undefined; this._maximumRotateRate = 1.77; @@ -1005,7 +1012,7 @@ function zoom2D(controller, startPosition, movement) { controller, startPosition, movement, - controller._zoomFactor, + controller.zoomFactor, camera.getMagnitude() ); } @@ -1763,7 +1770,7 @@ function zoomCV(controller, startPosition, movement) { controller, startPosition, movement, - controller._zoomFactor, + controller.zoomFactor, distance ); } @@ -2363,7 +2370,7 @@ function zoom3D(controller, startPosition, movement) { controller, startPosition, movement, - controller._zoomFactor, + controller.zoomFactor, distance, Cartesian3.dot(unitPosition, camera.direction) ); diff --git a/packages/engine/Specs/Scene/ScreenSpaceCameraControllerSpec.js b/packages/engine/Specs/Scene/ScreenSpaceCameraControllerSpec.js index 58d777315985..d5367349c33a 100644 --- a/packages/engine/Specs/Scene/ScreenSpaceCameraControllerSpec.js +++ b/packages/engine/Specs/Scene/ScreenSpaceCameraControllerSpec.js @@ -1978,6 +1978,40 @@ describe("Scene/ScreenSpaceCameraController", function () { ); }); + it("can adjust zoom factor", function () { + setUp3D(); + + // Zoom out + const mouseWheelMovement = -120; + + // Slow zoom + const initialPosition = Cartesian3.clone(camera.position); + controller.zoomFactor = 1.0; + simulateMouseWheel(mouseWheelMovement); + updateController(); + const slowZoomPosition = Cartesian3.clone(camera.position); + const slowZoomMagnitude = Cartesian3.magnitude(slowZoomPosition); + + // Medium zoom + camera.position = Cartesian3.clone(initialPosition); + controller.zoomFactor = 5.0; + simulateMouseWheel(mouseWheelMovement); + updateController(); + const mediumZoomPosition = Cartesian3.clone(camera.position); + const mediumZoomMagnitude = Cartesian3.magnitude(mediumZoomPosition); + + // Fast zoom + camera.position = Cartesian3.clone(initialPosition); + controller.zoomFactor = 10.0; + simulateMouseWheel(mouseWheelMovement); + updateController(); + const fastZoomPosition = Cartesian3.clone(camera.position); + const fastZoomMagnitude = Cartesian3.magnitude(fastZoomPosition); + + expect(fastZoomMagnitude).toBeGreaterThan(mediumZoomMagnitude); + expect(mediumZoomMagnitude).toBeGreaterThan(slowZoomMagnitude); + }); + it("is destroyed", function () { expect(controller.isDestroyed()).toEqual(false); controller.destroy(); From 159d02d626756558f4f3836b8c613acc30df598a Mon Sep 17 00:00:00 2001 From: Brandon Berisford Date: Tue, 13 Aug 2024 12:34:26 -0500 Subject: [PATCH 2/2] moved my changes to be under the next release in the changelog markdown file. --- CHANGES.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bfaf713a7bcb..72ce5aaab957 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # Change Log -### 1.122 - 2024-08-11 +### 1.121 - 2024-09-01 #### @cesium/engine @@ -10,16 +10,10 @@ ##### Additions :tada: -- Exposes `ScreenSpaceCameraController.zoomFactor` to allow adjusting the zoom factor (speed). [#9145](https://github.com/CesiumGS/cesium/pull/9145) - -### 1.121 - 2024-09-01 - -#### @cesium/engine - -##### Additions :tada: - - Made the `time` parameter optional for `Property`, using `JulianDate.now()` as default. [#12099](https://github.com/CesiumGS/cesium/pull/12099) +- Exposes `ScreenSpaceCameraController.zoomFactor` to allow adjusting the zoom factor (speed). [#9145](https://github.com/CesiumGS/cesium/pull/9145) + ### 1.120 - 2024-08-01 #### @cesium/engine