Cesium3DTileFeatureTable.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. var cachedTypedArrays = featureTable._cachedTypedArrays;
  22. var 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. var cachedTypedArrays = featureTable._cachedTypedArrays;
  36. var 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. var 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.getPropertyArray = function (
  67. semantic,
  68. componentType,
  69. componentLength
  70. ) {
  71. var jsonValue = this.json[semantic];
  72. if (!defined(jsonValue)) {
  73. return undefined;
  74. }
  75. if (defined(jsonValue.byteOffset)) {
  76. if (defined(jsonValue.componentType)) {
  77. componentType = ComponentDatatype.fromName(jsonValue.componentType);
  78. }
  79. return getTypedArrayFromBinary(
  80. this,
  81. semantic,
  82. componentType,
  83. componentLength,
  84. this.featuresLength,
  85. jsonValue.byteOffset
  86. );
  87. }
  88. return getTypedArrayFromArray(this, semantic, componentType, jsonValue);
  89. };
  90. Cesium3DTileFeatureTable.prototype.getProperty = function (
  91. semantic,
  92. componentType,
  93. componentLength,
  94. featureId,
  95. result
  96. ) {
  97. var jsonValue = this.json[semantic];
  98. if (!defined(jsonValue)) {
  99. return undefined;
  100. }
  101. var typedArray = this.getPropertyArray(
  102. semantic,
  103. componentType,
  104. componentLength
  105. );
  106. if (componentLength === 1) {
  107. return typedArray[featureId];
  108. }
  109. for (var i = 0; i < componentLength; ++i) {
  110. result[i] = typedArray[componentLength * featureId + i];
  111. }
  112. return result;
  113. };
  114. export default Cesium3DTileFeatureTable;