CompositeMaterialProperty.js 3.7 KB

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