diff --git a/CHANGES.md b/CHANGES.md index 8b190f0d9e36..8c33059ac98c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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: diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index cbfedd8b73c8..5e1608d32650 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -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)) { @@ -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. * diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index 34f1c857c97f..7dcb39f01bc4 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -3494,6 +3494,7 @@ describe("Scene/Camera", function () { startObject: {}, stopObject: {}, duration: 0.001, + complete: jasmine.createSpy("complete"), cancelTween: jasmine.createSpy("cancelTween"), }); @@ -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;