KmlTourWait.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import defined from "../Core/defined.js";
  2. /**
  3. * Pauses the KmlTour for a given number of seconds.
  4. *
  5. * @alias KmlTourWait
  6. * @constructor
  7. *
  8. * @param {number} duration entry duration
  9. *
  10. * @see KmlTour
  11. * @see KmlTourFlyTo
  12. */
  13. function KmlTourWait(duration) {
  14. this.type = "KmlTourWait";
  15. this.blocking = true;
  16. this.duration = duration;
  17. this.timeout = null;
  18. }
  19. /**
  20. * Play this playlist entry
  21. *
  22. * @param {KmlTourWait.DoneCallback} done function which will be called when playback ends
  23. */
  24. KmlTourWait.prototype.play = function (done) {
  25. const self = this;
  26. this.activeCallback = done;
  27. this.timeout = setTimeout(function () {
  28. delete self.activeCallback;
  29. done(false);
  30. }, this.duration * 1000);
  31. };
  32. /**
  33. * Stop execution of curent entry, cancel curent timeout
  34. */
  35. KmlTourWait.prototype.stop = function () {
  36. clearTimeout(this.timeout);
  37. if (defined(this.activeCallback)) {
  38. this.activeCallback(true);
  39. }
  40. };
  41. /**
  42. * A function which will be called when playback ends.
  43. *
  44. * @callback KmlTourWait.DoneCallback
  45. * @param {boolean} terminated true if {@link KmlTourWait#stop} was
  46. * called before entry done playback.
  47. */
  48. export default KmlTourWait;