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

BufferPolylineCollection.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // @ts-check
  2. import defined from "../Core/defined.js";
  3. import BufferPrimitiveCollection from "./BufferPrimitiveCollection.js";
  4. import BufferPolyline from "./BufferPolyline.js";
  5. import renderPolylines from "./renderBufferPolylineCollection.js";
  6. import BufferPolylineMaterial from "./BufferPolylineMaterial.js";
  7. /** @import { TypedArray } from "../Core/globalTypes.js"; */
  8. /** @import Matrix4 from "../Core/Matrix4.js"; */
  9. /** @import FrameState from "./FrameState.js" */
  10. /**
  11. * @typedef {object} BufferPolylineOptions
  12. * @property {Matrix4} [modelMatrix=Matrix4.IDENTITY] Transforms geometry from model to world coordinates.
  13. * @property {boolean} [show=true]
  14. * @property {BufferPolylineMaterial} [material=BufferPolylineMaterial.DEFAULT_MATERIAL]
  15. * @property {number} [featureId]
  16. * @property {object} [pickObject]
  17. * @property {TypedArray} [positions]
  18. * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
  19. */
  20. /**
  21. * Collection of polylines held in ArrayBuffer storage for performance and memory optimization.
  22. *
  23. * <p>Default buffer memory allocation is arbitrary, and collections cannot be resized,
  24. * so specific per-buffer capacities should be provided in the collection
  25. * constructor when available.</p>
  26. *
  27. * @example
  28. * const collection = new BufferPolylineCollection({
  29. * primitiveCountMax: 1024,
  30. * vertexCountMax: 4096,
  31. * });
  32. *
  33. * const polyline = new BufferPolyline();
  34. * const material = new BufferPolylineMaterial({color: Color.WHITE});
  35. *
  36. * // Create a new polyline, temporarily bound to 'polyline' local variable.
  37. * collection.add({
  38. * positions: new Float64Array([ ... ]),
  39. * material,
  40. * }, polyline);
  41. *
  42. * // Iterate over all polylines in collection, temporarily binding 'polyline'
  43. * // local variable to each, and updating polyline material.
  44. * for (let i = 0; i < collection.primitiveCount; i++) {
  45. * collection.get(i, polyline);
  46. * polyline.setMaterial(material);
  47. * }
  48. *
  49. * @see BufferPolyline
  50. * @see BufferPolylineMaterial
  51. * @see BufferPrimitiveCollection
  52. * @extends BufferPrimitiveCollection<BufferPolyline>
  53. * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
  54. */
  55. class BufferPolylineCollection extends BufferPrimitiveCollection {
  56. _getCollectionClass() {
  57. return BufferPolylineCollection;
  58. }
  59. _getPrimitiveClass() {
  60. return BufferPolyline;
  61. }
  62. _getMaterialClass() {
  63. return BufferPolylineMaterial;
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // COLLECTION LIFECYCLE
  67. /**
  68. * @param {BufferPolylineCollection} collection
  69. * @returns {BufferPolylineCollection}
  70. * @override
  71. * @ignore
  72. */
  73. static _cloneEmpty(collection) {
  74. return new BufferPolylineCollection({
  75. primitiveCountMax: collection.primitiveCountMax,
  76. vertexCountMax: collection.vertexCountMax,
  77. positionDatatype: collection.positionDatatype,
  78. positionNormalized: collection.positionNormalized,
  79. });
  80. }
  81. /////////////////////////////////////////////////////////////////////////////
  82. // PRIMITIVE LIFECYCLE
  83. /**
  84. * Adds a new polyline to the collection, with the specified options. A
  85. * {@link BufferPolyline} instance is linked to the new polyline, using
  86. * the 'result' argument if given, or a new instance if not. For repeated
  87. * calls, prefer to reuse a single BufferPolyline instance rather than
  88. * allocating a new instance on each call.
  89. *
  90. * @param {BufferPolylineOptions} options
  91. * @param {BufferPolyline} result
  92. * @returns {BufferPolyline}
  93. * @override
  94. */
  95. add(options, result = new BufferPolyline()) {
  96. super.add(options, result);
  97. const vertexOffset = this._positionCount;
  98. result._setUint32(BufferPolyline.Layout.POSITION_OFFSET_U32, vertexOffset);
  99. result._setUint32(BufferPolyline.Layout.POSITION_COUNT_U32, 0);
  100. if (defined(options.positions)) {
  101. result.setPositions(options.positions);
  102. }
  103. return result;
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. // RENDER
  107. /**
  108. * @param {FrameState} frameState
  109. * @ignore
  110. */
  111. update(frameState) {
  112. super.update(frameState);
  113. const passes = frameState.passes;
  114. if (this.show && (passes.render || passes.pick)) {
  115. this._renderContext = renderPolylines(
  116. this,
  117. frameState,
  118. this._renderContext,
  119. );
  120. }
  121. }
  122. }
  123. export default BufferPolylineCollection;