PolylineOutlineMaterialProperty.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 defaultOutlineColor = Color.BLACK;
  10. var defaultOutlineWidth = 1.0;
  11. /**
  12. * A {@link MaterialProperty} that maps to polyline outline {@link Material} uniforms.
  13. * @alias PolylineOutlineMaterialProperty
  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.outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
  19. * @param {Property} [options.outlineWidth=1.0] A numeric Property specifying the width of the outline, in pixels.
  20. */
  21. function PolylineOutlineMaterialProperty(options) {
  22. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  23. this._definitionChanged = new Event();
  24. this._color = undefined;
  25. this._colorSubscription = undefined;
  26. this._outlineColor = undefined;
  27. this._outlineColorSubscription = undefined;
  28. this._outlineWidth = undefined;
  29. this._outlineWidthSubscription = undefined;
  30. this.color = options.color;
  31. this.outlineColor = options.outlineColor;
  32. this.outlineWidth = options.outlineWidth;
  33. }
  34. defineProperties(PolylineOutlineMaterialProperty.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 PolylineOutlineMaterialProperty.prototype
  39. *
  40. * @type {Boolean}
  41. * @readonly
  42. */
  43. isConstant : {
  44. get : function() {
  45. return Property.isConstant(this._color) && Property.isConstant(this._outlineColor) && Property.isConstant(this._outlineWidth);
  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 PolylineOutlineMaterialProperty.prototype
  53. *
  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 PolylineOutlineMaterialProperty.prototype
  65. * @type {Property}
  66. * @default Color.WHITE
  67. */
  68. color : createPropertyDescriptor('color'),
  69. /**
  70. * Gets or sets the Property specifying the {@link Color} of the outline.
  71. * @memberof PolylineOutlineMaterialProperty.prototype
  72. * @type {Property}
  73. * @default Color.BLACK
  74. */
  75. outlineColor : createPropertyDescriptor('outlineColor'),
  76. /**
  77. * Gets or sets the numeric Property specifying the width of the outline.
  78. * @memberof PolylineOutlineMaterialProperty.prototype
  79. * @type {Property}
  80. * @default 1.0
  81. */
  82. outlineWidth : createPropertyDescriptor('outlineWidth')
  83. });
  84. /**
  85. * Gets the {@link Material} type at the provided time.
  86. *
  87. * @param {JulianDate} time The time for which to retrieve the type.
  88. * @returns {String} The type of material.
  89. */
  90. PolylineOutlineMaterialProperty.prototype.getType = function(time) {
  91. return 'PolylineOutline';
  92. };
  93. /**
  94. * Gets the value of the property at the provided time.
  95. *
  96. * @param {JulianDate} time The time for which to retrieve the value.
  97. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  98. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  99. */
  100. PolylineOutlineMaterialProperty.prototype.getValue = function(time, result) {
  101. if (!defined(result)) {
  102. result = {};
  103. }
  104. result.color = Property.getValueOrClonedDefault(this._color, time, defaultColor, result.color);
  105. result.outlineColor = Property.getValueOrClonedDefault(this._outlineColor, time, defaultOutlineColor, result.outlineColor);
  106. result.outlineWidth = Property.getValueOrDefault(this._outlineWidth, time, defaultOutlineWidth);
  107. return result;
  108. };
  109. /**
  110. * Compares this property to the provided property and returns
  111. * <code>true</code> if they are equal, <code>false</code> otherwise.
  112. *
  113. * @param {Property} [other] The other property.
  114. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  115. */
  116. PolylineOutlineMaterialProperty.prototype.equals = function(other) {
  117. return this === other || //
  118. (other instanceof PolylineOutlineMaterialProperty && //
  119. Property.equals(this._color, other._color) && //
  120. Property.equals(this._outlineColor, other._outlineColor) && //
  121. Property.equals(this._outlineWidth, other._outlineWidth));
  122. };
  123. export default PolylineOutlineMaterialProperty;