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

PolylineGlowMaterialProperty.js 5.2KB

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