CompositePositionProperty.js 5.4 KB

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