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

CompositePositionProperty.js 5.0KB

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