PolylineGlowMaterialProperty.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import Color from '../Core/Color.js';
  2. import defaultValue from '../Core/defaultValue.js';
  3. import defined from '../Core/defined.js';
  4. import defineProperties from '../Core/defineProperties.js';
  5. import Event from '../Core/Event.js';
  6. import createPropertyDescriptor from './createPropertyDescriptor.js';
  7. import Property from './Property.js';
  8. var defaultColor = Color.WHITE;
  9. var defaultGlowPower = 0.25;
  10. var 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} [options.color=Color.WHITE] A Property specifying the {@link Color} of the line.
  18. * @param {Property} [options.glowPower=0.25] A numeric Property specifying the strength of the glow, as a percentage of the total line width.
  19. * @param {Property} [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 = defaultValue(options, defaultValue.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. 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 Property.isConstant(this._color) && Property.isConstant(this._glow);
  45. }
  46. },
  47. /**
  48. * Gets the event that is raised whenever the definition of this property changes.
  49. * The definition is considered to have changed if a call to getValue would return
  50. * a different result for the same time.
  51. * @memberof PolylineGlowMaterialProperty.prototype
  52. * @type {Event}
  53. * @readonly
  54. */
  55. definitionChanged : {
  56. get : function() {
  57. return this._definitionChanged;
  58. }
  59. },
  60. /**
  61. * Gets or sets the Property specifying the {@link Color} of the line.
  62. * @memberof PolylineGlowMaterialProperty.prototype
  63. * @type {Property}
  64. */
  65. color : createPropertyDescriptor('color'),
  66. /**
  67. * Gets or sets the numeric Property specifying the strength of the glow, as a percentage of the total line width (less than 1.0).
  68. * @memberof PolylineGlowMaterialProperty.prototype
  69. * @type {Property}
  70. */
  71. glowPower : createPropertyDescriptor('glowPower'),
  72. /**
  73. * 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.
  74. * @memberof PolylineGlowMaterialProperty.prototype
  75. * @type {Property}
  76. */
  77. taperPower : createPropertyDescriptor('taperPower')
  78. });
  79. /**
  80. * Gets the {@link Material} type at the provided time.
  81. *
  82. * @param {JulianDate} time The time for which to retrieve the type.
  83. * @returns {String} The type of material.
  84. */
  85. PolylineGlowMaterialProperty.prototype.getType = function(time) {
  86. return 'PolylineGlow';
  87. };
  88. /**
  89. * Gets the value of the property at the provided time.
  90. *
  91. * @param {JulianDate} time The time for which to retrieve the value.
  92. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  93. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  94. */
  95. PolylineGlowMaterialProperty.prototype.getValue = function(time, result) {
  96. if (!defined(result)) {
  97. result = {};
  98. }
  99. result.color = Property.getValueOrClonedDefault(this._color, time, defaultColor, result.color);
  100. result.glowPower = Property.getValueOrDefault(this._glowPower, time, defaultGlowPower, result.glowPower);
  101. result.taperPower = Property.getValueOrDefault(this._taperPower, time, defaultTaperPower, result.taperPower);
  102. return result;
  103. };
  104. /**
  105. * Compares this property to the provided property and returns
  106. * <code>true</code> if they are equal, <code>false</code> otherwise.
  107. *
  108. * @param {Property} [other] The other property.
  109. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  110. */
  111. PolylineGlowMaterialProperty.prototype.equals = function(other) {
  112. return this === other ||
  113. (other instanceof PolylineGlowMaterialProperty &&
  114. Property.equals(this._color, other._color) &&
  115. Property.equals(this._glowPower, other._glowPower) &&
  116. Property.equals(this._taperPower, other._taperPower));
  117. };
  118. export default PolylineGlowMaterialProperty;