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

PositionPropertyArray.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import defined from "../Core/defined.js";
  2. import DeveloperError from "../Core/DeveloperError.js";
  3. import Event from "../Core/Event.js";
  4. import EventHelper from "../Core/EventHelper.js";
  5. import JulianDate from "../Core/JulianDate.js";
  6. import ReferenceFrame from "../Core/ReferenceFrame.js";
  7. import Property from "./Property.js";
  8. /**
  9. * A {@link Property} whose value is an array whose items are the computed value
  10. * of other PositionProperty instances.
  11. *
  12. * @alias PositionPropertyArray
  13. * @constructor
  14. *
  15. * @param {Property[]} [value] An array of Property instances.
  16. * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined.
  17. */
  18. function PositionPropertyArray(value, referenceFrame) {
  19. this._value = undefined;
  20. this._definitionChanged = new Event();
  21. this._eventHelper = new EventHelper();
  22. this._referenceFrame = referenceFrame ?? ReferenceFrame.FIXED;
  23. this.setValue(value);
  24. }
  25. Object.defineProperties(PositionPropertyArray.prototype, {
  26. /**
  27. * Gets a value indicating if this property is constant. This property
  28. * is considered constant if all property items in the array are constant.
  29. * @memberof PositionPropertyArray.prototype
  30. *
  31. * @type {boolean}
  32. * @readonly
  33. */
  34. isConstant: {
  35. get: function () {
  36. const value = this._value;
  37. if (!defined(value)) {
  38. return true;
  39. }
  40. const length = value.length;
  41. for (let i = 0; i < length; i++) {
  42. if (!Property.isConstant(value[i])) {
  43. return false;
  44. }
  45. }
  46. return true;
  47. },
  48. },
  49. /**
  50. * Gets the event that is raised whenever the definition of this property changes.
  51. * The definition is changed whenever setValue is called with data different
  52. * than the current value or one of the properties in the array also changes.
  53. * @memberof PositionPropertyArray.prototype
  54. *
  55. * @type {Event}
  56. * @readonly
  57. */
  58. definitionChanged: {
  59. get: function () {
  60. return this._definitionChanged;
  61. },
  62. },
  63. /**
  64. * Gets the reference frame in which the position is defined.
  65. * @memberof PositionPropertyArray.prototype
  66. * @type {ReferenceFrame}
  67. * @default ReferenceFrame.FIXED;
  68. */
  69. referenceFrame: {
  70. get: function () {
  71. return this._referenceFrame;
  72. },
  73. },
  74. });
  75. const timeScratch = new JulianDate();
  76. /**
  77. * Gets the value of the property.
  78. *
  79. * @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
  80. * @param {Cartesian3[]} [result] The object to store the value into, if omitted, a new instance is created and returned.
  81. * @returns {Cartesian3[]} The modified result parameter or a new instance if the result parameter was not supplied.
  82. */
  83. PositionPropertyArray.prototype.getValue = function (time, result) {
  84. if (!defined(time)) {
  85. time = JulianDate.now(timeScratch);
  86. }
  87. return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
  88. };
  89. /**
  90. * Gets the value of the property at the provided time and in the provided reference frame.
  91. *
  92. * @param {JulianDate} time The time for which to retrieve the value.
  93. * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.
  94. * @param {Cartesian3[]} [result] The object to store the value into, if omitted, a new instance is created and returned.
  95. * @returns {Cartesian3[]} The modified result parameter or a new instance if the result parameter was not supplied.
  96. */
  97. PositionPropertyArray.prototype.getValueInReferenceFrame = function (
  98. time,
  99. referenceFrame,
  100. result,
  101. ) {
  102. //>>includeStart('debug', pragmas.debug);
  103. if (!defined(time)) {
  104. throw new DeveloperError("time is required.");
  105. }
  106. if (!defined(referenceFrame)) {
  107. throw new DeveloperError("referenceFrame is required.");
  108. }
  109. //>>includeEnd('debug');
  110. const value = this._value;
  111. if (!defined(value)) {
  112. return undefined;
  113. }
  114. const length = value.length;
  115. if (!defined(result)) {
  116. result = new Array(length);
  117. }
  118. let i = 0;
  119. let x = 0;
  120. while (i < length) {
  121. const property = value[i];
  122. const itemValue = property.getValueInReferenceFrame(
  123. time,
  124. referenceFrame,
  125. result[i],
  126. );
  127. if (defined(itemValue)) {
  128. result[x] = itemValue;
  129. x++;
  130. }
  131. i++;
  132. }
  133. result.length = x;
  134. return result;
  135. };
  136. /**
  137. * Sets the value of the property.
  138. *
  139. * @param {Property[]} value An array of Property instances.
  140. */
  141. PositionPropertyArray.prototype.setValue = function (value) {
  142. const eventHelper = this._eventHelper;
  143. eventHelper.removeAll();
  144. if (defined(value)) {
  145. this._value = value.slice();
  146. const length = value.length;
  147. for (let i = 0; i < length; i++) {
  148. const property = value[i];
  149. if (defined(property)) {
  150. eventHelper.add(
  151. property.definitionChanged,
  152. PositionPropertyArray.prototype._raiseDefinitionChanged,
  153. this,
  154. );
  155. }
  156. }
  157. } else {
  158. this._value = undefined;
  159. }
  160. this._definitionChanged.raiseEvent(this);
  161. };
  162. /**
  163. * Compares this property to the provided property and returns
  164. * <code>true</code> if they are equal, <code>false</code> otherwise.
  165. *
  166. * @param {Property} [other] The other property.
  167. * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  168. */
  169. PositionPropertyArray.prototype.equals = function (other) {
  170. return (
  171. this === other || //
  172. (other instanceof PositionPropertyArray && //
  173. this._referenceFrame === other._referenceFrame && //
  174. Property.arrayEquals(this._value, other._value))
  175. );
  176. };
  177. PositionPropertyArray.prototype._raiseDefinitionChanged = function () {
  178. this._definitionChanged.raiseEvent(this);
  179. };
  180. export default PositionPropertyArray;