智慧水务管理系统 - 精河县供水工程综合管理平台

ConstantPositionProperty.js 5.0KB

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