CompositeMaterialProperty.js 4.3 KB

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