CompositePositionProperty.js 5.5 KB

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