PolylineGlowMaterialProperty.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 defaultGlowPower = 0.25;
  9. const defaultTaperPower = 1.0;
  10. /**
  11. * A {@link MaterialProperty} that maps to polyline glow {@link Material} uniforms.
  12. * @alias PolylineGlowMaterialProperty
  13. * @constructor
  14. *
  15. * @param {object} [options] Object with the following properties:
  16. * @param {Property|Color} [options.color=Color.WHITE] A Property specifying the {@link Color} of the line.
  17. * @param {Property|number} [options.glowPower=0.25] A numeric Property specifying the strength of the glow, as a percentage of the total line width.
  18. * @param {Property|number} [options.taperPower=1.0] A numeric Property specifying the strength of the tapering effect, as a percentage of the total line length. If 1.0 or higher, no taper effect is used.
  19. */
  20. function PolylineGlowMaterialProperty(options) {
  21. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  22. this._definitionChanged = new Event();
  23. this._color = undefined;
  24. this._colorSubscription = undefined;
  25. this._glowPower = undefined;
  26. this._glowPowerSubscription = undefined;
  27. this._taperPower = undefined;
  28. this._taperPowerSubscription = undefined;
  29. this.color = options.color;
  30. this.glowPower = options.glowPower;
  31. this.taperPower = options.taperPower;
  32. }
  33. Object.defineProperties(PolylineGlowMaterialProperty.prototype, {
  34. /**
  35. * Gets a value indicating if this property is constant. A property is considered
  36. * constant if getValue always returns the same result for the current definition.
  37. * @memberof PolylineGlowMaterialProperty.prototype
  38. * @type {boolean}
  39. * @readonly
  40. */
  41. isConstant: {
  42. get: function () {
  43. return (
  44. Property.isConstant(this._color) && Property.isConstant(this._glow)
  45. );
  46. },
  47. },
  48. /**
  49. * Gets the event that is raised whenever the definition of this property changes.
  50. * The definition is considered to have changed if a call to getValue would return
  51. * a different result for the same time.
  52. * @memberof PolylineGlowMaterialProperty.prototype
  53. * @type {Event}
  54. * @readonly
  55. */
  56. definitionChanged: {
  57. get: function () {
  58. return this._definitionChanged;
  59. },
  60. },
  61. /**
  62. * Gets or sets the Property specifying the {@link Color} of the line.
  63. * @memberof PolylineGlowMaterialProperty.prototype
  64. * @type {Property|undefined}
  65. */
  66. color: createPropertyDescriptor("color"),
  67. /**
  68. * Gets or sets the numeric Property specifying the strength of the glow, as a percentage of the total line width (less than 1.0).
  69. * @memberof PolylineGlowMaterialProperty.prototype
  70. * @type {Property|undefined}
  71. */
  72. glowPower: createPropertyDescriptor("glowPower"),
  73. /**
  74. * Gets or sets the numeric Property specifying the strength of the tapering effect, as a percentage of the total line length. If 1.0 or higher, no taper effect is used.
  75. * @memberof PolylineGlowMaterialProperty.prototype
  76. * @type {Property|undefined}
  77. */
  78. taperPower: createPropertyDescriptor("taperPower"),
  79. });
  80. /**
  81. * Gets the {@link Material} type at the provided time.
  82. *
  83. * @param {JulianDate} time The time for which to retrieve the type.
  84. * @returns {string} The type of material.
  85. */
  86. PolylineGlowMaterialProperty.prototype.getType = function (time) {
  87. return "PolylineGlow";
  88. };
  89. /**
  90. * Gets the value of the property at the provided time.
  91. *
  92. * @param {JulianDate} time The time for which to retrieve the value.
  93. * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  94. * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
  95. */
  96. PolylineGlowMaterialProperty.prototype.getValue = function (time, result) {
  97. if (!defined(result)) {
  98. result = {};
  99. }
  100. result.color = Property.getValueOrClonedDefault(
  101. this._color,
  102. time,
  103. defaultColor,
  104. result.color
  105. );
  106. result.glowPower = Property.getValueOrDefault(
  107. this._glowPower,
  108. time,
  109. defaultGlowPower,
  110. result.glowPower
  111. );
  112. result.taperPower = Property.getValueOrDefault(
  113. this._taperPower,
  114. time,
  115. defaultTaperPower,
  116. result.taperPower
  117. );
  118. return result;
  119. };
  120. /**
  121. * Compares this property to the provided property and returns
  122. * <code>true</code> if they are equal, <code>false</code> otherwise.
  123. *
  124. * @param {Property} [other] The other property.
  125. * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  126. */
  127. PolylineGlowMaterialProperty.prototype.equals = function (other) {
  128. return (
  129. this === other ||
  130. (other instanceof PolylineGlowMaterialProperty &&
  131. Property.equals(this._color, other._color) &&
  132. Property.equals(this._glowPower, other._glowPower) &&
  133. Property.equals(this._taperPower, other._taperPower))
  134. );
  135. };
  136. export default PolylineGlowMaterialProperty;