DataSourceClock.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*global define*/
  2. define([
  3. '../Core/Clock',
  4. '../Core/defaultValue',
  5. '../Core/defined',
  6. '../Core/defineProperties',
  7. '../Core/DeveloperError',
  8. '../Core/Event',
  9. '../Core/JulianDate',
  10. './createPropertyDescriptor'
  11. ], function(
  12. Clock,
  13. defaultValue,
  14. defined,
  15. defineProperties,
  16. DeveloperError,
  17. Event,
  18. JulianDate,
  19. createPropertyDescriptor) {
  20. "use strict";
  21. /**
  22. * Represents CZML document-level clock settings.
  23. *
  24. * @alias DataSourceClock
  25. * @constructor
  26. */
  27. var DataSourceClock = function() {
  28. this._startTime = undefined;
  29. this._stopTime = undefined;
  30. this._currentTime = undefined;
  31. this._clockRange = undefined;
  32. this._clockStep = undefined;
  33. this._multiplier = undefined;
  34. this._definitionChanged = new Event();
  35. };
  36. defineProperties(DataSourceClock.prototype, {
  37. /**
  38. * Gets the event that is raised whenever a new property is assigned.
  39. * @memberof DataSourceClock.prototype
  40. *
  41. * @type {Event}
  42. * @readonly
  43. */
  44. definitionChanged : {
  45. get : function() {
  46. return this._definitionChanged;
  47. }
  48. },
  49. /**
  50. * Gets or sets the start time of the clock to use when looping or clamped.
  51. * @memberof DataSourceClock.prototype
  52. * @type {JulianDate}
  53. */
  54. startTime : createPropertyDescriptor('startTime'),
  55. /**
  56. * Gets or sets the stop time of the clock to use when looping or clamped.
  57. * @memberof DataSourceClock.prototype
  58. * @type {JulianDate}
  59. */
  60. stopTime : createPropertyDescriptor('stopTime'),
  61. /**
  62. * Gets or sets the initial time to use when switching to this clock.
  63. * @memberof DataSourceClock.prototype
  64. * @type {JulianDate}
  65. */
  66. currentTime : createPropertyDescriptor('currentTime'),
  67. /**
  68. * Gets or sets how the clock should behave when <code>startTime</code> or <code>stopTime</code> is reached.
  69. * @memberof DataSourceClock.prototype
  70. * @type {ClockRange}
  71. */
  72. clockRange : createPropertyDescriptor('clockRange'),
  73. /**
  74. * Gets or sets if clock advancement is frame dependent or system clock dependent.
  75. * @memberof DataSourceClock.prototype
  76. * @type {ClockStep}
  77. */
  78. clockStep : createPropertyDescriptor('clockStep'),
  79. /**
  80. * Gets or sets how much time advances with each tick, negative values allow for advancing backwards.
  81. * If <code>clockStep</code> is set to ClockStep.TICK_DEPENDENT this is the number of seconds to advance.
  82. * If <code>clockStep</code> is set to ClockStep.SYSTEM_CLOCK_MULTIPLIER this value is multiplied by the
  83. * elapsed system time since the last call to tick.
  84. * @memberof DataSourceClock.prototype
  85. * @type {Number}
  86. */
  87. multiplier : createPropertyDescriptor('multiplier')
  88. });
  89. /**
  90. * Duplicates a DataSourceClock instance.
  91. *
  92. * @param {DataSourceClock} [result] The object onto which to store the result.
  93. * @returns {DataSourceClock} The modified result parameter or a new instance if one was not provided.
  94. */
  95. DataSourceClock.prototype.clone = function(result) {
  96. if (!defined(result)) {
  97. result = new DataSourceClock();
  98. }
  99. result.startTime = this.startTime;
  100. result.stopTime = this.stopTime;
  101. result.currentTime = this.currentTime;
  102. result.clockRange = this.clockRange;
  103. result.clockStep = this.clockStep;
  104. result.multiplier = this.multiplier;
  105. return result;
  106. };
  107. /**
  108. * Returns true if this DataSourceClock is equivalent to the other
  109. *
  110. * @param {DataSourceClock} other The other DataSourceClock to compare to.
  111. * @returns {Boolean} <code>true</code> if the DataSourceClocks are equal; otherwise, <code>false</code>.
  112. */
  113. DataSourceClock.prototype.equals = function(other) {
  114. return this === other ||
  115. defined(other) &&
  116. JulianDate.equals(this.startTime, other.startTime) &&
  117. JulianDate.equals(this.stopTime, other.stopTime) &&
  118. JulianDate.equals(this.currentTime, other.currentTime) &&
  119. this.clockRange === other.clockRange &&
  120. this.clockStep === other.clockStep &&
  121. this.multiplier === other.multiplier;
  122. };
  123. /**
  124. * Assigns each unassigned property on this object to the value
  125. * of the same property on the provided source object.
  126. *
  127. * @param {DataSourceClock} source The object to be merged into this object.
  128. */
  129. DataSourceClock.prototype.merge = function(source) {
  130. //>>includeStart('debug', pragmas.debug);
  131. if (!defined(source)) {
  132. throw new DeveloperError('source is required.');
  133. }
  134. //>>includeEnd('debug');
  135. this.startTime = defaultValue(this.startTime, source.startTime);
  136. this.stopTime = defaultValue(this.stopTime, source.stopTime);
  137. this.currentTime = defaultValue(this.currentTime, source.currentTime);
  138. this.clockRange = defaultValue(this.clockRange, source.clockRange);
  139. this.clockStep = defaultValue(this.clockStep, source.clockStep);
  140. this.multiplier = defaultValue(this.multiplier, source.multiplier);
  141. };
  142. /**
  143. * Gets the value of this clock instance as a {@link Clock} object.
  144. *
  145. * @returns {Clock} The modified result parameter or a new instance if one was not provided.
  146. */
  147. DataSourceClock.prototype.getValue = function(result) {
  148. if (!defined(result)) {
  149. result = new Clock();
  150. }
  151. result.startTime = this.startTime;
  152. result.stopTime = this.stopTime;
  153. result.clockRange = this.clockRange;
  154. result.clockStep = this.clockStep;
  155. result.multiplier = this.multiplier;
  156. result.currentTime = this.currentTime;
  157. return result;
  158. };
  159. return DataSourceClock;
  160. });