PolylineOutlineMaterialProperty.js 5.0 KB

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