TimeIntervalCollectionPositionProperty.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*global define*/
  2. define([
  3. '../Core/defaultValue',
  4. '../Core/defined',
  5. '../Core/defineProperties',
  6. '../Core/DeveloperError',
  7. '../Core/Event',
  8. '../Core/ReferenceFrame',
  9. '../Core/TimeIntervalCollection',
  10. './PositionProperty',
  11. './Property'
  12. ], function(
  13. defaultValue,
  14. defined,
  15. defineProperties,
  16. DeveloperError,
  17. Event,
  18. ReferenceFrame,
  19. TimeIntervalCollection,
  20. PositionProperty,
  21. Property) {
  22. "use strict";
  23. /**
  24. * A {@link TimeIntervalCollectionProperty} which is also a {@link PositionProperty}.
  25. *
  26. * @alias TimeIntervalCollectionPositionProperty
  27. * @constructor
  28. *
  29. * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined.
  30. */
  31. var TimeIntervalCollectionPositionProperty = function(referenceFrame) {
  32. this._definitionChanged = new Event();
  33. this._intervals = new TimeIntervalCollection();
  34. this._intervals.changedEvent.addEventListener(TimeIntervalCollectionPositionProperty.prototype._intervalsChanged, this);
  35. this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);
  36. };
  37. defineProperties(TimeIntervalCollectionPositionProperty.prototype, {
  38. /**
  39. * Gets a value indicating if this property is constant. A property is considered
  40. * constant if getValue always returns the same result for the current definition.
  41. * @memberof TimeIntervalCollectionPositionProperty.prototype
  42. *
  43. * @type {Boolean}
  44. * @readonly
  45. */
  46. isConstant : {
  47. get : function() {
  48. return this._intervals.isEmpty;
  49. }
  50. },
  51. /**
  52. * Gets the event that is raised whenever the definition of this property changes.
  53. * The definition is considered to have changed if a call to getValue would return
  54. * a different result for the same time.
  55. * @memberof TimeIntervalCollectionPositionProperty.prototype
  56. *
  57. * @type {Event}
  58. * @readonly
  59. */
  60. definitionChanged : {
  61. get : function() {
  62. return this._definitionChanged;
  63. }
  64. },
  65. /**
  66. * Gets the interval collection.
  67. * @memberof TimeIntervalCollectionPositionProperty.prototype
  68. * @type {TimeIntervalCollection}
  69. */
  70. intervals : {
  71. get : function() {
  72. return this._intervals;
  73. }
  74. },
  75. /**
  76. * Gets the reference frame in which the position is defined.
  77. * @memberof TimeIntervalCollectionPositionProperty.prototype
  78. * @type {ReferenceFrame}
  79. * @default ReferenceFrame.FIXED;
  80. */
  81. referenceFrame : {
  82. get : function() {
  83. return this._referenceFrame;
  84. }
  85. }
  86. });
  87. /**
  88. * Gets the value of the property at the provided time in the fixed frame.
  89. *
  90. * @param {JulianDate} time The time for which to retrieve the value.
  91. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  92. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  93. */
  94. TimeIntervalCollectionPositionProperty.prototype.getValue = function(time, result) {
  95. return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
  96. };
  97. /**
  98. * Gets the value of the property at the provided time and in the provided reference frame.
  99. *
  100. * @param {JulianDate} time The time for which to retrieve the value.
  101. * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.
  102. * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
  103. * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied.
  104. */
  105. TimeIntervalCollectionPositionProperty.prototype.getValueInReferenceFrame = function(time, referenceFrame, result) {
  106. //>>includeStart('debug', pragmas.debug);
  107. if (!defined(time)) {
  108. throw new DeveloperError('time is required.');
  109. }
  110. if (!defined(referenceFrame)) {
  111. throw new DeveloperError('referenceFrame is required.');
  112. }
  113. //>>includeEnd('debug');
  114. var position = this._intervals.findDataForIntervalContainingDate(time);
  115. if (defined(position)) {
  116. return PositionProperty.convertToReferenceFrame(time, position, this._referenceFrame, referenceFrame, result);
  117. }
  118. return undefined;
  119. };
  120. /**
  121. * Compares this property to the provided property and returns
  122. * <code>true</code> if they are equal, <code>false</code> otherwise.
  123. *
  124. * @param {Property} [other] The other property.
  125. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  126. */
  127. TimeIntervalCollectionPositionProperty.prototype.equals = function(other) {
  128. return this === other || //
  129. (other instanceof TimeIntervalCollectionPositionProperty && //
  130. this._intervals.equals(other._intervals, Property.equals) && //
  131. this._referenceFrame === other._referenceFrame);
  132. };
  133. /**
  134. * @private
  135. */
  136. TimeIntervalCollectionPositionProperty.prototype._intervalsChanged = function() {
  137. this._definitionChanged.raiseEvent(this);
  138. };
  139. return TimeIntervalCollectionPositionProperty;
  140. });