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

GridMaterialProperty.js 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import Cartesian2 from "../Core/Cartesian2.js";
  2. import Color from "../Core/Color.js";
  3. import Frozen from "../Core/Frozen.js";
  4. import defined from "../Core/defined.js";
  5. import Event from "../Core/Event.js";
  6. import JulianDate from "../Core/JulianDate.js";
  7. import createPropertyDescriptor from "./createPropertyDescriptor.js";
  8. import Property from "./Property.js";
  9. const defaultColor = Color.WHITE;
  10. const defaultCellAlpha = 0.1;
  11. const defaultLineCount = new Cartesian2(8, 8);
  12. const defaultLineOffset = new Cartesian2(0, 0);
  13. const 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|Color} [options.color=Color.WHITE] A Property specifying the grid {@link Color}.
  20. * @param {Property|number} [options.cellAlpha=0.1] A numeric Property specifying cell alpha values.
  21. * @param {Property|Cartesian2} [options.lineCount=new Cartesian2(8, 8)] A {@link Cartesian2} Property specifying the number of grid lines along each axis.
  22. * @param {Property|Cartesian2} [options.lineThickness=new Cartesian2(1.0, 1.0)] A {@link Cartesian2} Property specifying the thickness of grid lines along each axis.
  23. * @param {Property|Cartesian2} [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 = options ?? Frozen.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. Object.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 (
  58. Property.isConstant(this._color) &&
  59. Property.isConstant(this._cellAlpha) &&
  60. Property.isConstant(this._lineCount) &&
  61. Property.isConstant(this._lineThickness) &&
  62. Property.isConstant(this._lineOffset)
  63. );
  64. },
  65. },
  66. /**
  67. * Gets the event that is raised whenever the definition of this property changes.
  68. * The definition is considered to have changed if a call to getValue would return
  69. * a different result for the same time.
  70. * @memberof GridMaterialProperty.prototype
  71. *
  72. * @type {Event}
  73. * @readonly
  74. */
  75. definitionChanged: {
  76. get: function () {
  77. return this._definitionChanged;
  78. },
  79. },
  80. /**
  81. * Gets or sets the Property specifying the grid {@link Color}.
  82. * @memberof GridMaterialProperty.prototype
  83. * @type {Property|undefined}
  84. * @default Color.WHITE
  85. */
  86. color: createPropertyDescriptor("color"),
  87. /**
  88. * Gets or sets the numeric Property specifying cell alpha values.
  89. * @memberof GridMaterialProperty.prototype
  90. * @type {Property|undefined}
  91. * @default 0.1
  92. */
  93. cellAlpha: createPropertyDescriptor("cellAlpha"),
  94. /**
  95. * Gets or sets the {@link Cartesian2} Property specifying the number of grid lines along each axis.
  96. * @memberof GridMaterialProperty.prototype
  97. * @type {Property|undefined}
  98. * @default new Cartesian2(8.0, 8.0)
  99. */
  100. lineCount: createPropertyDescriptor("lineCount"),
  101. /**
  102. * Gets or sets the {@link Cartesian2} Property specifying the thickness of grid lines along each axis.
  103. * @memberof GridMaterialProperty.prototype
  104. * @type {Property|undefined}
  105. * @default new Cartesian2(1.0, 1.0)
  106. */
  107. lineThickness: createPropertyDescriptor("lineThickness"),
  108. /**
  109. * Gets or sets the {@link Cartesian2} Property specifying the starting offset of grid lines along each axis.
  110. * @memberof GridMaterialProperty.prototype
  111. * @type {Property|undefined}
  112. * @default new Cartesian2(0.0, 0.0)
  113. */
  114. lineOffset: createPropertyDescriptor("lineOffset"),
  115. });
  116. /**
  117. * Gets the {@link Material} type at the provided time.
  118. *
  119. * @param {JulianDate} time The time for which to retrieve the type.
  120. * @returns {string} The type of material.
  121. */
  122. GridMaterialProperty.prototype.getType = function (time) {
  123. return "Grid";
  124. };
  125. const timeScratch = new JulianDate();
  126. /**
  127. * Gets the value of the property at the provided time.
  128. *
  129. * @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
  130. * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  131. * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
  132. */
  133. GridMaterialProperty.prototype.getValue = function (time, result) {
  134. if (!defined(time)) {
  135. time = JulianDate.now(timeScratch);
  136. }
  137. if (!defined(result)) {
  138. result = {};
  139. }
  140. result.color = Property.getValueOrClonedDefault(
  141. this._color,
  142. time,
  143. defaultColor,
  144. result.color,
  145. );
  146. result.cellAlpha = Property.getValueOrDefault(
  147. this._cellAlpha,
  148. time,
  149. defaultCellAlpha,
  150. );
  151. result.lineCount = Property.getValueOrClonedDefault(
  152. this._lineCount,
  153. time,
  154. defaultLineCount,
  155. result.lineCount,
  156. );
  157. result.lineThickness = Property.getValueOrClonedDefault(
  158. this._lineThickness,
  159. time,
  160. defaultLineThickness,
  161. result.lineThickness,
  162. );
  163. result.lineOffset = Property.getValueOrClonedDefault(
  164. this._lineOffset,
  165. time,
  166. defaultLineOffset,
  167. result.lineOffset,
  168. );
  169. return result;
  170. };
  171. /**
  172. * Compares this property to the provided property and returns
  173. * <code>true</code> if they are equal, <code>false</code> otherwise.
  174. *
  175. * @param {Property} [other] The other property.
  176. * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  177. */
  178. GridMaterialProperty.prototype.equals = function (other) {
  179. return (
  180. this === other || //
  181. (other instanceof GridMaterialProperty && //
  182. Property.equals(this._color, other._color) && //
  183. Property.equals(this._cellAlpha, other._cellAlpha) && //
  184. Property.equals(this._lineCount, other._lineCount) && //
  185. Property.equals(this._lineThickness, other._lineThickness) && //
  186. Property.equals(this._lineOffset, other._lineOffset))
  187. );
  188. };
  189. export default GridMaterialProperty;