All files / engine/Source/DataSources KmlTourWait.js

100% Statements 14/14
50% Branches 1/2
100% Functions 4/4
100% Lines 14/14

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                          6x 6x 6x   6x               1x 3x 3x 3x 2x 2x             1x 1x 1x 1x                        
import defined from "../Core/defined.js";
/**
 * Pauses the KmlTour for a given number of seconds.
 *
 * @alias KmlTourWait
 * @constructor
 *
 * @param {number} duration entry duration
 *
 * @see KmlTour
 * @see KmlTourFlyTo
 */
function KmlTourWait(duration) {
  this.type = "KmlTourWait";
  this.blocking = true;
  this.duration = duration;
 
  this.timeout = null;
}
 
/**
 * Play this playlist entry
 *
 * @param {KmlTourWait.DoneCallback} done function which will be called when playback ends
 */
KmlTourWait.prototype.play = function (done) {
  const self = this;
  this.activeCallback = done;
  this.timeout = setTimeout(function () {
    delete self.activeCallback;
    done(false);
  }, this.duration * 1000);
};
 
/**
 * Stop execution of curent entry, cancel curent timeout
 */
KmlTourWait.prototype.stop = function () {
  clearTimeout(this.timeout);
  Eif (defined(this.activeCallback)) {
    this.activeCallback(true);
  }
};
 
/**
 * A function which will be called when playback ends.
 *
 * @callback KmlTourWait.DoneCallback
 * @param {boolean} terminated true if {@link KmlTourWait#stop} was
 * called before entry done playback.
 */
export default KmlTourWait;