PolylineDashMaterialProperty.js 5.5 KB

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