All files / engine/Source/DataSources KmlTourFlyTo.js

85% Statements 34/40
58.33% Branches 14/24
80% Functions 4/5
85% Lines 34/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110                                      11x 11x 11x 11x   11x 11x 11x                   1x 2x 2x 2x 2x 2x 2x 2x       2x 2x 1x 1x 1x 1x             1x                               1x 5x       5x 3x     5x       5x 2x 2x 3x 3x     5x     5x                      
import BoundingSphere from "../Core/BoundingSphere.js";
import combine from "../Core/combine.js";
import defined from "../Core/defined.js";
import EasingFunction from "../Core/EasingFunction.js";
/**
 * Transitions the KmlTour to the next destination. This transition is facilitated
 * using a specified flyToMode over a given number of seconds.
 *
 * @alias KmlTourFlyTo
 * @constructor
 *
 * @param {number} duration entry duration
 * @param {string} flyToMode KML fly to mode: bounce, smooth, etc
 * @param {KmlCamera|KmlLookAt} view KmlCamera or KmlLookAt
 *
 * @see KmlTour
 * @see KmlTourWait
 */
function KmlTourFlyTo(duration, flyToMode, view) {
  this.type = "KmlTourFlyTo";
  this.blocking = true;
  this.activeCamera = null;
  this.activeCallback = null;
 
  this.duration = duration;
  this.view = view;
  this.flyToMode = flyToMode;
}
 
/**
 * Play this playlist entry
 *
 * @param {KmlTourFlyTo.DoneCallback} done function which will be called when playback ends
 * @param {Camera} camera Cesium camera
 * @param {object} [cameraOptions] which will be merged with camera flyTo options. See {@link Camera#flyTo}
 */
KmlTourFlyTo.prototype.play = function (done, camera, cameraOptions) {
  this.activeCamera = camera;
  Eif (defined(done) && done !== null) {
    const self = this;
    this.activeCallback = function (terminated) {
      delete self.activeCallback;
      delete self.activeCamera;
      done(defined(terminated) ? false : terminated);
    };
  }
 
  const options = this.getCameraOptions(cameraOptions);
  if (this.view.headingPitchRoll) {
    camera.flyTo(options);
  } else Eif (this.view.headingPitchRange) {
    const target = new BoundingSphere(this.view.position);
    camera.flyToBoundingSphere(target, options);
  }
};
 
/**
 * Stop execution of curent entry. Cancel camera flyTo
 */
KmlTourFlyTo.prototype.stop = function () {
  if (defined(this.activeCamera)) {
    this.activeCamera.cancelFlight();
  }
  if (defined(this.activeCallback)) {
    this.activeCallback(true);
  }
};
 
/**
 * Returns options for {@link Camera#flyTo} or {@link Camera#flyToBoundingSphere}
 * depends on this.view type.
 *
 * @param {object} cameraOptions options to merge with generated. See {@link Camera#flyTo}
 * @returns {object} {@link Camera#flyTo} or {@link Camera#flyToBoundingSphere} options
 */
KmlTourFlyTo.prototype.getCameraOptions = function (cameraOptions) {
  let options = {
    duration: this.duration,
  };
 
  if (defined(this.activeCallback)) {
    options.complete = this.activeCallback;
  }
 
  Iif (this.flyToMode === "smooth") {
    options.easingFunction = EasingFunction.LINEAR_NONE;
  }
 
  if (this.view.headingPitchRoll) {
    options.destination = this.view.position;
    options.orientation = this.view.headingPitchRoll;
  } else Eif (this.view.headingPitchRange) {
    options.offset = this.view.headingPitchRange;
  }
 
  Iif (defined(cameraOptions)) {
    options = combine(options, cameraOptions);
  }
  return options;
};
 
/**
 * A function that will be executed when the flight completes.
 * @callback KmlTourFlyTo.DoneCallback
 *
 * @param {boolean} terminated true if {@link KmlTourFlyTo#stop} was
 * called before entry done playback.
 */
export default KmlTourFlyTo;