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

PolylineOutlineMaterialProperty.js 5.2KB

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