ConstantPositionProperty.js 5.5 KB

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