Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make screenSpaceCameraController zoomFactor public. #12121

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

### 1.122 - 2024-08-11
BeyondBelief96 marked this conversation as resolved.
Show resolved Hide resolved

#### @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
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Tim Schneider](https://github.com/Tim-S)
- [Vladislav Yunev](https://github.com/YunVlad)
- [Levi Montgomery](https://github.com/Levi-Montgomery)
- [Brandon Berisford](https://github.com/BeyondBelief96)
15 changes: 11 additions & 4 deletions packages/engine/Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1005,7 +1012,7 @@ function zoom2D(controller, startPosition, movement) {
controller,
startPosition,
movement,
controller._zoomFactor,
controller.zoomFactor,
camera.getMagnitude()
);
}
Expand Down Expand Up @@ -1763,7 +1770,7 @@ function zoomCV(controller, startPosition, movement) {
controller,
startPosition,
movement,
controller._zoomFactor,
controller.zoomFactor,
distance
);
}
Expand Down Expand Up @@ -2363,7 +2370,7 @@ function zoom3D(controller, startPosition, movement) {
controller,
startPosition,
movement,
controller._zoomFactor,
controller.zoomFactor,
distance,
Cartesian3.dot(unitPosition, camera.direction)
);
Expand Down
34 changes: 34 additions & 0 deletions packages/engine/Specs/Scene/ScreenSpaceCameraControllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down