GridMaterialProperty.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import Cartesian2 from '../Core/Cartesian2.js';
  2. import Color from '../Core/Color.js';
  3. import defaultValue from '../Core/defaultValue.js';
  4. import defined from '../Core/defined.js';
  5. import defineProperties from '../Core/defineProperties.js';
  6. import Event from '../Core/Event.js';
  7. import createPropertyDescriptor from './createPropertyDescriptor.js';
  8. import Property from './Property.js';
  9. var defaultColor = Color.WHITE;
  10. var defaultCellAlpha = 0.1;
  11. var defaultLineCount = new Cartesian2(8, 8);
  12. var defaultLineOffset = new Cartesian2(0, 0);
  13. var defaultLineThickness = new Cartesian2(1, 1);
  14. /**
  15. * A {@link MaterialProperty} that maps to grid {@link Material} uniforms.
  16. * @alias GridMaterialProperty
  17. *
  18. * @param {Object} [options] Object with the following properties:
  19. * @param {Property} [options.color=Color.WHITE] A Property specifying the grid {@link Color}.
  20. * @param {Property} [options.cellAlpha=0.1] A numeric Property specifying cell alpha values.
  21. * @param {Property} [options.lineCount=new Cartesian2(8, 8)] A {@link Cartesian2} Property specifying the number of grid lines along each axis.
  22. * @param {Property} [options.lineThickness=new Cartesian2(1.0, 1.0)] A {@link Cartesian2} Property specifying the thickness of grid lines along each axis.
  23. * @param {Property} [options.lineOffset=new Cartesian2(0.0, 0.0)] A {@link Cartesian2} Property specifying starting offset of grid lines along each axis.
  24. *
  25. * @constructor
  26. */
  27. function GridMaterialProperty(options) {
  28. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  29. this._definitionChanged = new Event();
  30. this._color = undefined;
  31. this._colorSubscription = undefined;
  32. this._cellAlpha = undefined;
  33. this._cellAlphaSubscription = undefined;
  34. this._lineCount = undefined;
  35. this._lineCountSubscription = undefined;
  36. this._lineThickness = undefined;
  37. this._lineThicknessSubscription = undefined;
  38. this._lineOffset = undefined;
  39. this._lineOffsetSubscription = undefined;
  40. this.color = options.color;
  41. this.cellAlpha = options.cellAlpha;
  42. this.lineCount = options.lineCount;
  43. this.lineThickness = options.lineThickness;
  44. this.lineOffset = options.lineOffset;
  45. }
  46. defineProperties(GridMaterialProperty.prototype, {
  47. /**
  48. * Gets a value indicating if this property is constant. A property is considered
  49. * constant if getValue always returns the same result for the current definition.
  50. * @memberof GridMaterialProperty.prototype
  51. *
  52. * @type {Boolean}
  53. * @readonly
  54. */
  55. isConstant : {
  56. get : function() {
  57. return Property.isConstant(this._color) &&
  58. Property.isConstant(this._cellAlpha) &&
  59. Property.isConstant(this._lineCount) &&
  60. Property.isConstant(this._lineThickness) &&
  61. Property.isConstant(this._lineOffset);
  62. }
  63. },
  64. /**
  65. * Gets the event that is raised whenever the definition of this property changes.
  66. * The definition is considered to have changed if a call to getValue would return
  67. * a different result for the same time.
  68. * @memberof GridMaterialProperty.prototype
  69. *
  70. * @type {Event}
  71. * @readonly
  72. */
  73. definitionChanged : {
  74. get : function() {
  75. return this._definitionChanged;
  76. }
  77. },
  78. /**
  79. * Gets or sets the Property specifying the grid {@link Color}.
  80. * @memberof GridMaterialProperty.prototype
  81. * @type {Property}
  82. * @default Color.WHITE
  83. */
  84. color : createPropertyDescriptor('color'),
  85. /**
  86. * Gets or sets the numeric Property specifying cell alpha values.
  87. * @memberof GridMaterialProperty.prototype
  88. * @type {Property}
  89. * @default 0.1
  90. */
  91. cellAlpha : createPropertyDescriptor('cellAlpha'),
  92. /**
  93. * Gets or sets the {@link Cartesian2} Property specifying the number of grid lines along each axis.
  94. * @memberof GridMaterialProperty.prototype
  95. * @type {Property}
  96. * @default new Cartesian2(8.0, 8.0)
  97. */
  98. lineCount : createPropertyDescriptor('lineCount'),
  99. /**
  100. * Gets or sets the {@link Cartesian2} Property specifying the thickness of grid lines along each axis.
  101. * @memberof GridMaterialProperty.prototype
  102. * @type {Property}
  103. * @default new Cartesian2(1.0, 1.0)
  104. */
  105. lineThickness : createPropertyDescriptor('lineThickness'),
  106. /**
  107. * Gets or sets the {@link Cartesian2} Property specifying the starting offset of grid lines along each axis.
  108. * @memberof GridMaterialProperty.prototype
  109. * @type {Property}
  110. * @default new Cartesian2(0.0, 0.0)
  111. */
  112. lineOffset : createPropertyDescriptor('lineOffset')
  113. });
  114. /**
  115. * Gets the {@link Material} type at the provided time.
  116. *
  117. * @param {JulianDate} time The time for which to retrieve the type.
  118. * @returns {String} The type of material.
  119. */
  120. GridMaterialProperty.prototype.getType = function(time) {
  121. return 'Grid';
  122. };
  123. /**
  124. * Gets the value of the property at the provided time.
  125. *
  126. * @param {JulianDate} time The time for which to retrieve the value.
  127. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  128. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  129. */
  130. GridMaterialProperty.prototype.getValue = function(time, result) {
  131. if (!defined(result)) {
  132. result = {};
  133. }
  134. result.color = Property.getValueOrClonedDefault(this._color, time, defaultColor, result.color);
  135. result.cellAlpha = Property.getValueOrDefault(this._cellAlpha, time, defaultCellAlpha);
  136. result.lineCount = Property.getValueOrClonedDefault(this._lineCount, time, defaultLineCount, result.lineCount);
  137. result.lineThickness = Property.getValueOrClonedDefault(this._lineThickness, time, defaultLineThickness, result.lineThickness);
  138. result.lineOffset = Property.getValueOrClonedDefault(this._lineOffset, time, defaultLineOffset, result.lineOffset);
  139. return result;
  140. };
  141. /**
  142. * Compares this property to the provided property and returns
  143. * <code>true</code> if they are equal, <code>false</code> otherwise.
  144. *
  145. * @param {Property} [other] The other property.
  146. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  147. */
  148. GridMaterialProperty.prototype.equals = function(other) {
  149. return this === other || //
  150. (other instanceof GridMaterialProperty && //
  151. Property.equals(this._color, other._color) && //
  152. Property.equals(this._cellAlpha, other._cellAlpha) && //
  153. Property.equals(this._lineCount, other._lineCount) && //
  154. Property.equals(this._lineThickness, other._lineThickness) && //
  155. Property.equals(this._lineOffset, other._lineOffset));
  156. };
  157. export default GridMaterialProperty;