TimeIntervalCollectionPositionProperty.js 5.5 KB

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