KmlTourWait.js 1.1 KB

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