ConstantPositionProperty.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import Cartesian3 from '../Core/Cartesian3.js';
  2. import defaultValue from '../Core/defaultValue.js';
  3. import defined from '../Core/defined.js';
  4. import defineProperties from '../Core/defineProperties.js';
  5. import DeveloperError from '../Core/DeveloperError.js';
  6. import Event from '../Core/Event.js';
  7. import ReferenceFrame from '../Core/ReferenceFrame.js';
  8. import PositionProperty from './PositionProperty.js';
  9. /**
  10. * A {@link PositionProperty} whose value does not change in respect to the
  11. * {@link ReferenceFrame} in which is it defined.
  12. *
  13. * @alias ConstantPositionProperty
  14. * @constructor
  15. *
  16. * @param {Cartesian3} [value] The property value.
  17. * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined.
  18. */
  19. function ConstantPositionProperty(value, referenceFrame) {
  20. this._definitionChanged = new Event();
  21. this._value = Cartesian3.clone(value);
  22. this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);
  23. }
  24. defineProperties(ConstantPositionProperty.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 ConstantPositionProperty.prototype
  29. *
  30. * @type {Boolean}
  31. * @readonly
  32. */
  33. isConstant : {
  34. get : function() {
  35. return !defined(this._value) || this._referenceFrame === ReferenceFrame.FIXED;
  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 ConstantPositionProperty.prototype
  43. *
  44. * @type {Event}
  45. * @readonly
  46. */
  47. definitionChanged : {
  48. get : function() {
  49. return this._definitionChanged;
  50. }
  51. },
  52. /**
  53. * Gets the reference frame in which the position is defined.
  54. * @memberof ConstantPositionProperty.prototype
  55. * @type {ReferenceFrame}
  56. * @default ReferenceFrame.FIXED;
  57. */
  58. referenceFrame : {
  59. get : function() {
  60. return this._referenceFrame;
  61. }
  62. }
  63. });
  64. /**
  65. * Gets the value of the property at the provided time in the fixed frame.
  66. *
  67. * @param {JulianDate} time The time for which to retrieve the value.
  68. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  69. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  70. */
  71. ConstantPositionProperty.prototype.getValue = function(time, result) {
  72. return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
  73. };
  74. /**
  75. * Sets the value of the property.
  76. *
  77. * @param {Cartesian3} value The property value.
  78. * @param {ReferenceFrame} [referenceFrame=this.referenceFrame] The reference frame in which the position is defined.
  79. */
  80. ConstantPositionProperty.prototype.setValue = function(value, referenceFrame) {
  81. var definitionChanged = false;
  82. if (!Cartesian3.equals(this._value, value)) {
  83. definitionChanged = true;
  84. this._value = Cartesian3.clone(value);
  85. }
  86. if (defined(referenceFrame) && this._referenceFrame !== referenceFrame) {
  87. definitionChanged = true;
  88. this._referenceFrame = referenceFrame;
  89. }
  90. if (definitionChanged) {
  91. this._definitionChanged.raiseEvent(this);
  92. }
  93. };
  94. /**
  95. * Gets the value of the property at the provided time and in the provided reference frame.
  96. *
  97. * @param {JulianDate} time The time for which to retrieve the value.
  98. * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.
  99. * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
  100. * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied.
  101. */
  102. ConstantPositionProperty.prototype.getValueInReferenceFrame = function(time, referenceFrame, result) {
  103. //>>includeStart('debug', pragmas.debug);
  104. if (!defined(time)) {
  105. throw new DeveloperError('time is required.');
  106. }
  107. if (!defined(referenceFrame)) {
  108. throw new DeveloperError('referenceFrame is required.');
  109. }
  110. //>>includeEnd('debug');
  111. return PositionProperty.convertToReferenceFrame(time, this._value, this._referenceFrame, referenceFrame, result);
  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. ConstantPositionProperty.prototype.equals = function(other) {
  121. return this === other ||
  122. (other instanceof ConstantPositionProperty &&
  123. Cartesian3.equals(this._value, other._value) &&
  124. this._referenceFrame === other._referenceFrame);
  125. };
  126. export default ConstantPositionProperty;