PolylineDashMaterialProperty.js 6.1 KB

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