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

CompositeMaterialProperty.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 CompositeProperty from "./CompositeProperty.js";
  6. import Property from "./Property.js";
  7. /**
  8. * A {@link CompositeProperty} which is also a {@link MaterialProperty}.
  9. *
  10. * @alias CompositeMaterialProperty
  11. * @constructor
  12. */
  13. function CompositeMaterialProperty() {
  14. this._definitionChanged = new Event();
  15. this._composite = new CompositeProperty();
  16. this._composite.definitionChanged.addEventListener(
  17. CompositeMaterialProperty.prototype._raiseDefinitionChanged,
  18. this,
  19. );
  20. }
  21. Object.defineProperties(CompositeMaterialProperty.prototype, {
  22. /**
  23. * Gets a value indicating if this property is constant. A property is considered
  24. * constant if getValue always returns the same result for the current definition.
  25. * @memberof CompositeMaterialProperty.prototype
  26. *
  27. * @type {boolean}
  28. * @readonly
  29. */
  30. isConstant: {
  31. get: function () {
  32. return this._composite.isConstant;
  33. },
  34. },
  35. /**
  36. * Gets the event that is raised whenever the definition of this property changes.
  37. * The definition is changed whenever setValue is called with data different
  38. * than the current value.
  39. * @memberof CompositeMaterialProperty.prototype
  40. *
  41. * @type {Event}
  42. * @readonly
  43. */
  44. definitionChanged: {
  45. get: function () {
  46. return this._definitionChanged;
  47. },
  48. },
  49. /**
  50. * Gets the interval collection.
  51. * @memberof CompositeMaterialProperty.prototype
  52. *
  53. * @type {TimeIntervalCollection}
  54. */
  55. intervals: {
  56. get: function () {
  57. return this._composite._intervals;
  58. },
  59. },
  60. });
  61. /**
  62. * Gets the {@link Material} type at the provided time.
  63. *
  64. * @param {JulianDate} time The time for which to retrieve the type.
  65. * @returns {string} The type of material.
  66. */
  67. CompositeMaterialProperty.prototype.getType = function (time) {
  68. //>>includeStart('debug', pragmas.debug);
  69. if (!defined(time)) {
  70. throw new DeveloperError("time is required");
  71. }
  72. //>>includeEnd('debug');
  73. const innerProperty =
  74. this._composite._intervals.findDataForIntervalContainingDate(time);
  75. if (defined(innerProperty)) {
  76. return innerProperty.getType(time);
  77. }
  78. return undefined;
  79. };
  80. const timeScratch = new JulianDate();
  81. /**
  82. * Gets the value of the property at the provided time.
  83. *
  84. * @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
  85. * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  86. * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
  87. */
  88. CompositeMaterialProperty.prototype.getValue = function (time, result) {
  89. if (!defined(time)) {
  90. time = JulianDate.now(timeScratch);
  91. }
  92. const innerProperty =
  93. this._composite._intervals.findDataForIntervalContainingDate(time);
  94. if (defined(innerProperty)) {
  95. return innerProperty.getValue(time, result);
  96. }
  97. return undefined;
  98. };
  99. /**
  100. * Compares this property to the provided property and returns
  101. * <code>true</code> if they are equal, <code>false</code> otherwise.
  102. *
  103. * @param {Property} [other] The other property.
  104. * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  105. */
  106. CompositeMaterialProperty.prototype.equals = function (other) {
  107. return (
  108. this === other || //
  109. (other instanceof CompositeMaterialProperty && //
  110. this._composite.equals(other._composite, Property.equals))
  111. );
  112. };
  113. /**
  114. * @private
  115. */
  116. CompositeMaterialProperty.prototype._raiseDefinitionChanged = function () {
  117. this._definitionChanged.raiseEvent(this);
  118. };
  119. export default CompositeMaterialProperty;