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

PolylineDashMaterialProperty.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import Color from "../Core/Color.js";
  2. import Frozen from "../Core/Frozen.js";
  3. import defined from "../Core/defined.js";
  4. import Event from "../Core/Event.js";
  5. import JulianDate from "../Core/JulianDate.js";
  6. import createPropertyDescriptor from "./createPropertyDescriptor.js";
  7. import Property from "./Property.js";
  8. const defaultColor = Color.WHITE;
  9. const defaultGapColor = Color.TRANSPARENT;
  10. const defaultDashLength = 16.0;
  11. const defaultDashPattern = 255.0;
  12. /**
  13. * A {@link MaterialProperty} that maps to polyline dash {@link Material} uniforms.
  14. * @alias PolylineDashMaterialProperty
  15. * @constructor
  16. *
  17. * @param {object} [options] Object with the following properties:
  18. * @param {Property|Color} [options.color=Color.WHITE] A Property specifying the {@link Color} of the line.
  19. * @param {Property|Color} [options.gapColor=Color.TRANSPARENT] A Property specifying the {@link Color} of the gaps in the line.
  20. * @param {Property|number} [options.dashLength=16.0] A numeric Property specifying the length of the dash pattern in pixels.
  21. * @param {Property|number} [options.dashPattern=255.0] A numeric Property specifying a 16 bit pattern for the dash
  22. */
  23. function PolylineDashMaterialProperty(options) {
  24. options = options ?? Frozen.EMPTY_OBJECT;
  25. this._definitionChanged = new Event();
  26. this._color = undefined;
  27. this._colorSubscription = undefined;
  28. this._gapColor = undefined;
  29. this._gapColorSubscription = undefined;
  30. this._dashLength = undefined;
  31. this._dashLengthSubscription = undefined;
  32. this._dashPattern = undefined;
  33. this._dashPatternSubscription = undefined;
  34. this.color = options.color;
  35. this.gapColor = options.gapColor;
  36. this.dashLength = options.dashLength;
  37. this.dashPattern = options.dashPattern;
  38. }
  39. Object.defineProperties(PolylineDashMaterialProperty.prototype, {
  40. /**
  41. * Gets a value indicating if this property is constant. A property is considered
  42. * constant if getValue always returns the same result for the current definition.
  43. * @memberof PolylineDashMaterialProperty.prototype
  44. * @type {boolean}
  45. * @readonly
  46. */
  47. isConstant: {
  48. get: function () {
  49. return (
  50. Property.isConstant(this._color) &&
  51. Property.isConstant(this._gapColor) &&
  52. Property.isConstant(this._dashLength) &&
  53. Property.isConstant(this._dashPattern)
  54. );
  55. },
  56. },
  57. /**
  58. * Gets the event that is raised whenever the definition of this property changes.
  59. * The definition is considered to have changed if a call to getValue would return
  60. * a different result for the same time.
  61. * @memberof PolylineDashMaterialProperty.prototype
  62. * @type {Event}
  63. * @readonly
  64. */
  65. definitionChanged: {
  66. get: function () {
  67. return this._definitionChanged;
  68. },
  69. },
  70. /**
  71. * Gets or sets the Property specifying the {@link Color} of the line.
  72. * @memberof PolylineDashMaterialProperty.prototype
  73. * @type {Property|undefined}
  74. */
  75. color: createPropertyDescriptor("color"),
  76. /**
  77. * Gets or sets the Property specifying the {@link Color} of the gaps in the line.
  78. * @memberof PolylineDashMaterialProperty.prototype
  79. * @type {Property|undefined}
  80. */
  81. gapColor: createPropertyDescriptor("gapColor"),
  82. /**
  83. * Gets or sets the numeric Property specifying the length of a dash cycle
  84. * @memberof PolylineDashMaterialProperty.prototype
  85. * @type {Property|undefined}
  86. */
  87. dashLength: createPropertyDescriptor("dashLength"),
  88. /**
  89. * Gets or sets the numeric Property specifying a dash pattern
  90. * @memberof PolylineDashMaterialProperty.prototype
  91. * @type {Property|undefined}
  92. */
  93. dashPattern: createPropertyDescriptor("dashPattern"),
  94. });
  95. /**
  96. * Gets the {@link Material} type at the provided time.
  97. *
  98. * @param {JulianDate} time The time for which to retrieve the type.
  99. * @returns {string} The type of material.
  100. */
  101. PolylineDashMaterialProperty.prototype.getType = function (time) {
  102. return "PolylineDash";
  103. };
  104. const timeScratch = new JulianDate();
  105. /**
  106. * Gets the value of the property at the provided time.
  107. *
  108. * @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
  109. * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  110. * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
  111. */
  112. PolylineDashMaterialProperty.prototype.getValue = function (time, result) {
  113. if (!defined(time)) {
  114. time = JulianDate.now(timeScratch);
  115. }
  116. if (!defined(result)) {
  117. result = {};
  118. }
  119. result.color = Property.getValueOrClonedDefault(
  120. this._color,
  121. time,
  122. defaultColor,
  123. result.color,
  124. );
  125. result.gapColor = Property.getValueOrClonedDefault(
  126. this._gapColor,
  127. time,
  128. defaultGapColor,
  129. result.gapColor,
  130. );
  131. result.dashLength = Property.getValueOrDefault(
  132. this._dashLength,
  133. time,
  134. defaultDashLength,
  135. result.dashLength,
  136. );
  137. result.dashPattern = Property.getValueOrDefault(
  138. this._dashPattern,
  139. time,
  140. defaultDashPattern,
  141. result.dashPattern,
  142. );
  143. return result;
  144. };
  145. /**
  146. * Compares this property to the provided property and returns
  147. * <code>true</code> if they are equal, <code>false</code> otherwise.
  148. *
  149. * @param {Property} [other] The other property.
  150. * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  151. */
  152. PolylineDashMaterialProperty.prototype.equals = function (other) {
  153. return (
  154. this === other || //
  155. (other instanceof PolylineDashMaterialProperty &&
  156. Property.equals(this._color, other._color) &&
  157. Property.equals(this._gapColor, other._gapColor) &&
  158. Property.equals(this._dashLength, other._dashLength) &&
  159. Property.equals(this._dashPattern, other._dashPattern))
  160. );
  161. };
  162. export default PolylineDashMaterialProperty;