Cesium3DTileFeatureTable.js 3.1 KB

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