DataSourceClock.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import Clock from '../Core/Clock.js';
  2. import defaultValue from '../Core/defaultValue.js';
  3. import defined from '../Core/defined.js';
  4. import defineProperties from '../Core/defineProperties.js';
  5. import DeveloperError from '../Core/DeveloperError.js';
  6. import Event from '../Core/Event.js';
  7. import JulianDate from '../Core/JulianDate.js';
  8. import createRawPropertyDescriptor from './createRawPropertyDescriptor.js';
  9. /**
  10. * Represents desired clock settings for a particular {@link DataSource}. These settings may be applied
  11. * to the {@link Clock} when the DataSource is loaded.
  12. *
  13. * @alias DataSourceClock
  14. * @constructor
  15. */
  16. function DataSourceClock() {
  17. this._definitionChanged = new Event();
  18. this._startTime = undefined;
  19. this._stopTime = undefined;
  20. this._currentTime = undefined;
  21. this._clockRange = undefined;
  22. this._clockStep = undefined;
  23. this._multiplier = undefined;
  24. }
  25. defineProperties(DataSourceClock.prototype, {
  26. /**
  27. * Gets the event that is raised whenever a new property is assigned.
  28. * @memberof DataSourceClock.prototype
  29. *
  30. * @type {Event}
  31. * @readonly
  32. */
  33. definitionChanged : {
  34. get : function() {
  35. return this._definitionChanged;
  36. }
  37. },
  38. /**
  39. * Gets or sets the desired start time of the clock.
  40. * See {@link Clock#startTime}.
  41. * @memberof DataSourceClock.prototype
  42. * @type {JulianDate}
  43. */
  44. startTime : createRawPropertyDescriptor('startTime'),
  45. /**
  46. * Gets or sets the desired stop time of the clock.
  47. * See {@link Clock#stopTime}.
  48. * @memberof DataSourceClock.prototype
  49. * @type {JulianDate}
  50. */
  51. stopTime : createRawPropertyDescriptor('stopTime'),
  52. /**
  53. * Gets or sets the desired current time when this data source is loaded.
  54. * See {@link Clock#currentTime}.
  55. * @memberof DataSourceClock.prototype
  56. * @type {JulianDate}
  57. */
  58. currentTime : createRawPropertyDescriptor('currentTime'),
  59. /**
  60. * Gets or sets the desired clock range setting.
  61. * See {@link Clock#clockRange}.
  62. * @memberof DataSourceClock.prototype
  63. * @type {ClockRange}
  64. */
  65. clockRange : createRawPropertyDescriptor('clockRange'),
  66. /**
  67. * Gets or sets the desired clock step setting.
  68. * See {@link Clock#clockStep}.
  69. * @memberof DataSourceClock.prototype
  70. * @type {ClockStep}
  71. */
  72. clockStep : createRawPropertyDescriptor('clockStep'),
  73. /**
  74. * Gets or sets the desired clock multiplier.
  75. * See {@link Clock#multiplier}.
  76. * @memberof DataSourceClock.prototype
  77. * @type {Number}
  78. */
  79. multiplier : createRawPropertyDescriptor('multiplier')
  80. });
  81. /**
  82. * Duplicates a DataSourceClock instance.
  83. *
  84. * @param {DataSourceClock} [result] The object onto which to store the result.
  85. * @returns {DataSourceClock} The modified result parameter or a new instance if one was not provided.
  86. */
  87. DataSourceClock.prototype.clone = function(result) {
  88. if (!defined(result)) {
  89. result = new DataSourceClock();
  90. }
  91. result.startTime = this.startTime;
  92. result.stopTime = this.stopTime;
  93. result.currentTime = this.currentTime;
  94. result.clockRange = this.clockRange;
  95. result.clockStep = this.clockStep;
  96. result.multiplier = this.multiplier;
  97. return result;
  98. };
  99. /**
  100. * Returns true if this DataSourceClock is equivalent to the other
  101. *
  102. * @param {DataSourceClock} other The other DataSourceClock to compare to.
  103. * @returns {Boolean} <code>true</code> if the DataSourceClocks are equal; otherwise, <code>false</code>.
  104. */
  105. DataSourceClock.prototype.equals = function(other) {
  106. return this === other ||
  107. defined(other) &&
  108. JulianDate.equals(this.startTime, other.startTime) &&
  109. JulianDate.equals(this.stopTime, other.stopTime) &&
  110. JulianDate.equals(this.currentTime, other.currentTime) &&
  111. this.clockRange === other.clockRange &&
  112. this.clockStep === other.clockStep &&
  113. this.multiplier === other.multiplier;
  114. };
  115. /**
  116. * Assigns each unassigned property on this object to the value
  117. * of the same property on the provided source object.
  118. *
  119. * @param {DataSourceClock} source The object to be merged into this object.
  120. */
  121. DataSourceClock.prototype.merge = function(source) {
  122. //>>includeStart('debug', pragmas.debug);
  123. if (!defined(source)) {
  124. throw new DeveloperError('source is required.');
  125. }
  126. //>>includeEnd('debug');
  127. this.startTime = defaultValue(this.startTime, source.startTime);
  128. this.stopTime = defaultValue(this.stopTime, source.stopTime);
  129. this.currentTime = defaultValue(this.currentTime, source.currentTime);
  130. this.clockRange = defaultValue(this.clockRange, source.clockRange);
  131. this.clockStep = defaultValue(this.clockStep, source.clockStep);
  132. this.multiplier = defaultValue(this.multiplier, source.multiplier);
  133. };
  134. /**
  135. * Gets the value of this clock instance as a {@link Clock} object.
  136. *
  137. * @returns {Clock} The modified result parameter or a new instance if one was not provided.
  138. */
  139. DataSourceClock.prototype.getValue = function(result) {
  140. if (!defined(result)) {
  141. result = new Clock();
  142. }
  143. result.startTime = defaultValue(this.startTime, result.startTime);
  144. result.stopTime = defaultValue(this.stopTime, result.stopTime);
  145. result.currentTime = defaultValue(this.currentTime, result.currentTime);
  146. result.clockRange = defaultValue(this.clockRange, result.clockRange);
  147. result.multiplier = defaultValue(this.multiplier, result.multiplier);
  148. result.clockStep = defaultValue(this.clockStep, result.clockStep);
  149. return result;
  150. };
  151. export default DataSourceClock;