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

BufferPrimitiveMaterial.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // @ts-check
  2. import Color from "../Core/Color.js";
  3. import Frozen from "../Core/Frozen.js";
  4. /** @import Packable from "../Core/Packable.js"; */
  5. /** @import BufferPrimitive from "./BufferPrimitive.js"; */
  6. /**
  7. * @typedef {object} BufferPrimitiveMaterialOptions
  8. * @property {Color} [color=Color.WHITE] Color of fill.
  9. * @property {Color} [outlineColor=Color.WHITE] Color of outline.
  10. * @property {number} [outlineWidth=0.0] Width of outline, 0-255px.
  11. */
  12. /**
  13. * Material description for a {@link BufferPrimitive}. Abstract.
  14. *
  15. * <p>BufferPrimitiveMaterial objects are {@link Packable|packable}, stored
  16. * when calling {@link BufferPrimitive#setMaterial}. Subsequent changes to the
  17. * material will not affect the primitive until setMaterial() is called again.</p>
  18. *
  19. * @see BufferPointMaterial
  20. * @see BufferPolylineMaterial
  21. * @see BufferPolygonMaterial
  22. * @see Packable
  23. *
  24. * @abstract
  25. * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
  26. */
  27. class BufferPrimitiveMaterial {
  28. /** @ignore */
  29. static Layout = {
  30. COLOR_U32: 0,
  31. OUTLINE_COLOR_U32: 4,
  32. OUTLINE_WIDTH_U8: 8,
  33. __BYTE_LENGTH: 12,
  34. };
  35. /**
  36. * @type {BufferPrimitiveMaterial}
  37. * @ignore
  38. */
  39. static DEFAULT_MATERIAL;
  40. /**
  41. * @param {BufferPrimitiveMaterialOptions} [options]
  42. */
  43. constructor(options = Frozen.EMPTY_OBJECT) {
  44. /**
  45. * Color of fill.
  46. * @type {Color}
  47. */
  48. this.color = Color.clone(options.color ?? Color.WHITE);
  49. /**
  50. * Color of outline.
  51. * @type {Color}
  52. */
  53. this.outlineColor = Color.clone(options.outlineColor ?? Color.WHITE);
  54. /**
  55. * Width of outline, 0-255px.
  56. * @type {number}
  57. */
  58. this.outlineWidth = options.outlineWidth ?? 0;
  59. }
  60. /** @type {number} */
  61. static get packedLength() {
  62. return this.Layout.__BYTE_LENGTH;
  63. }
  64. /**
  65. * Stores the provided material into the provided array.
  66. *
  67. * @param {BufferPrimitiveMaterial} material
  68. * @param {DataView} view
  69. * @param {number} byteOffset
  70. */
  71. static pack(material, view, byteOffset) {
  72. view.setUint32(
  73. this.Layout.COLOR_U32 + byteOffset,
  74. material.color.toRgba(),
  75. true,
  76. );
  77. view.setUint32(
  78. this.Layout.OUTLINE_COLOR_U32 + byteOffset,
  79. material.outlineColor.toRgba(),
  80. true,
  81. );
  82. view.setUint8(
  83. this.Layout.OUTLINE_WIDTH_U8 + byteOffset,
  84. material.outlineWidth,
  85. );
  86. }
  87. /**
  88. * Retrieves a material from a packed array.
  89. *
  90. * @param {DataView} view The packed array.
  91. * @param {number} byteOffset Starting index of the element to be unpacked.
  92. * @param {BufferPrimitiveMaterial} result Material into which results are unpacked.
  93. * @returns {BufferPrimitiveMaterial} Modified result material, with results unpacked.
  94. */
  95. static unpack(view, byteOffset, result) {
  96. Color.fromRgba(
  97. view.getUint32(this.Layout.COLOR_U32 + byteOffset, true),
  98. result.color,
  99. );
  100. Color.fromRgba(
  101. view.getUint32(this.Layout.OUTLINE_COLOR_U32 + byteOffset, true),
  102. result.outlineColor,
  103. );
  104. result.outlineWidth = view.getUint8(
  105. this.Layout.OUTLINE_WIDTH_U8 + byteOffset,
  106. );
  107. return result;
  108. }
  109. /////////////////////////////////////////////////////////////////////////////
  110. // DEBUG
  111. /**
  112. * Returns a JSON-serializable object representing the material. This encoding
  113. * is not memory-efficient, and should generally be used for debugging and
  114. * testing.
  115. *
  116. * @returns {Object} JSON-serializable object.
  117. */
  118. toJSON() {
  119. return {
  120. color: this.color.toCssHexString(),
  121. outlineColor: this.outlineColor.toCssHexString(),
  122. outlineWidth: this.outlineWidth,
  123. };
  124. }
  125. }
  126. export default BufferPrimitiveMaterial;