DataSourceClock.js 5.2 KB

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