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

Add ability complete flight #8788

Merged
merged 6 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Added `Globe.undergroundColor` and `Globe.undergroundColorAlphaByDistance` for controlling how the back side of the globe is rendered when the camera is underground or the globe is translucent. [#8867](https://github.com/CesiumGS/cesium/pull/8867)
- Added a new sandcastle example to show how to add fog using a `PostProcessStage` [#8798](https://github.com/CesiumGS/cesium/pull/8798)
- Supported `#rgba` and `#rrggbbaa` formats in `Color.fromCssColorString`. [8873](https://github.com/CesiumGS/cesium/pull/8873)
- Added `Camera.completeFlight`, which causes the current camera flight to immediately jump to the final destination and call its complete callback. [#8788](https://github.com/CesiumGS/cesium/pull/8788)

##### Fixes :wrench:

Expand Down
36 changes: 34 additions & 2 deletions Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -3172,8 +3172,8 @@ var newOptions = {
};

/**
* Cancels the current camera flight if one is in progress.
* The camera is left at it's current location.
* Cancels the current camera flight and leaves the camera at its current location.
* If no flight is in progress, this this function does nothing.
*/
Camera.prototype.cancelFlight = function () {
if (defined(this._currentFlight)) {
Expand All @@ -3182,6 +3182,38 @@ Camera.prototype.cancelFlight = function () {
}
};

/**
* Completes the current camera flight and moves the camera immediately to its final destination.
* If no flight is in progress, this this function does nothing.
*/
Camera.prototype.completeFlight = function () {
if (defined(this._currentFlight)) {
this._currentFlight.cancelTween();

var options = {
destination: undefined,
orientation: {
heading: undefined,
pitch: undefined,
roll: undefined,
},
};

options.destination = newOptions.destination;
options.orientation.heading = newOptions.heading;
options.orientation.pitch = newOptions.pitch;
options.orientation.roll = newOptions.roll;

this.setView(options);

if (defined(this._currentFlight.complete)) {
this._currentFlight.complete();
}

this._currentFlight = undefined;
}
};

/**
* Flies the camera from its current position to a new position.
*
Expand Down
35 changes: 35 additions & 0 deletions Specs/Scene/CameraSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3494,6 +3494,7 @@ describe("Scene/Camera", function () {
startObject: {},
stopObject: {},
duration: 0.001,
complete: jasmine.createSpy("complete"),
cancelTween: jasmine.createSpy("cancelTween"),
});

Expand All @@ -3509,9 +3510,43 @@ describe("Scene/Camera", function () {
camera.cancelFlight();

expect(createdTween.cancelTween).toHaveBeenCalled();
expect(createdTween.complete).not.toHaveBeenCalled();
expect(camera._currentFlight).toBeUndefined();
});

it("can complete a flight", function () {
spyOn(CameraFlightPath, "createTween").and.returnValue({
startObject: {},
stopObject: {},
duration: 0.001,
complete: jasmine.createSpy("complete"),
cancelTween: jasmine.createSpy("cancelTween"),
});

spyOn(camera, "setView");

var options = {
destination: Cartesian3.fromDegrees(-117.16, 32.71, 15000.0),
orientation: {
heading: 1,
pitch: 2,
roll: 3,
},
};
camera.flyTo(options);

expect(camera._currentFlight).toBeDefined();

var createdTween = camera._currentFlight;
spyOn(createdTween, "cancelTween");
camera.completeFlight();

expect(createdTween.cancelTween).toHaveBeenCalled();
expect(createdTween.complete).toHaveBeenCalled();
expect(camera._currentFlight).toBeUndefined();
expect(camera.setView).toHaveBeenCalledWith(options);
});

it("flyTo with heading, pitch and roll", function () {
scene.mode = SceneMode.SCENE3D;

Expand Down