CompositeMaterialProperty.js 4.4 KB

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