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

Cesium3DTileFeatureTable.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import ComponentDatatype from "../Core/ComponentDatatype.js";
  2. import defined from "../Core/defined.js";
  3. /**
  4. * @private
  5. */
  6. function Cesium3DTileFeatureTable(featureTableJson, featureTableBinary) {
  7. this.json = featureTableJson;
  8. this.buffer = featureTableBinary;
  9. this._cachedTypedArrays = {};
  10. this.featuresLength = 0;
  11. }
  12. function getTypedArrayFromBinary(
  13. featureTable,
  14. semantic,
  15. componentType,
  16. componentLength,
  17. count,
  18. byteOffset,
  19. ) {
  20. const cachedTypedArrays = featureTable._cachedTypedArrays;
  21. let typedArray = cachedTypedArrays[semantic];
  22. if (!defined(typedArray)) {
  23. typedArray = ComponentDatatype.createArrayBufferView(
  24. componentType,
  25. featureTable.buffer.buffer,
  26. featureTable.buffer.byteOffset + byteOffset,
  27. count * componentLength,
  28. );
  29. cachedTypedArrays[semantic] = typedArray;
  30. }
  31. return typedArray;
  32. }
  33. function getTypedArrayFromArray(featureTable, semantic, componentType, array) {
  34. const cachedTypedArrays = featureTable._cachedTypedArrays;
  35. let typedArray = cachedTypedArrays[semantic];
  36. if (!defined(typedArray)) {
  37. typedArray = ComponentDatatype.createTypedArray(componentType, array);
  38. cachedTypedArrays[semantic] = typedArray;
  39. }
  40. return typedArray;
  41. }
  42. Cesium3DTileFeatureTable.prototype.getGlobalProperty = function (
  43. semantic,
  44. componentType,
  45. componentLength,
  46. ) {
  47. const jsonValue = this.json[semantic];
  48. if (!defined(jsonValue)) {
  49. return undefined;
  50. }
  51. if (defined(jsonValue.byteOffset)) {
  52. componentType = componentType ?? ComponentDatatype.UNSIGNED_INT;
  53. componentLength = componentLength ?? 1;
  54. return getTypedArrayFromBinary(
  55. this,
  56. semantic,
  57. componentType,
  58. componentLength,
  59. 1,
  60. jsonValue.byteOffset,
  61. );
  62. }
  63. return jsonValue;
  64. };
  65. Cesium3DTileFeatureTable.prototype.hasProperty = function (semantic) {
  66. return defined(this.json[semantic]);
  67. };
  68. Cesium3DTileFeatureTable.prototype.getPropertyArray = function (
  69. semantic,
  70. componentType,
  71. componentLength,
  72. ) {
  73. const jsonValue = this.json[semantic];
  74. if (!defined(jsonValue)) {
  75. return undefined;
  76. }
  77. if (defined(jsonValue.byteOffset)) {
  78. if (defined(jsonValue.componentType)) {
  79. componentType = ComponentDatatype.fromName(jsonValue.componentType);
  80. }
  81. return getTypedArrayFromBinary(
  82. this,
  83. semantic,
  84. componentType,
  85. componentLength,
  86. this.featuresLength,
  87. jsonValue.byteOffset,
  88. );
  89. }
  90. return getTypedArrayFromArray(this, semantic, componentType, jsonValue);
  91. };
  92. Cesium3DTileFeatureTable.prototype.getProperty = function (
  93. semantic,
  94. componentType,
  95. componentLength,
  96. featureId,
  97. result,
  98. ) {
  99. const jsonValue = this.json[semantic];
  100. if (!defined(jsonValue)) {
  101. return undefined;
  102. }
  103. const typedArray = this.getPropertyArray(
  104. semantic,
  105. componentType,
  106. componentLength,
  107. );
  108. if (componentLength === 1) {
  109. return typedArray[featureId];
  110. }
  111. for (let i = 0; i < componentLength; ++i) {
  112. result[i] = typedArray[componentLength * featureId + i];
  113. }
  114. return result;
  115. };
  116. export default Cesium3DTileFeatureTable;