Cesium3DTileFeatureTable.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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(featureTable, semantic, componentType, componentLength, count, byteOffset) {
  14. var cachedTypedArrays = featureTable._cachedTypedArrays;
  15. var typedArray = cachedTypedArrays[semantic];
  16. if (!defined(typedArray)) {
  17. typedArray = ComponentDatatype.createArrayBufferView(componentType, featureTable.buffer.buffer, featureTable.buffer.byteOffset + byteOffset, count * componentLength);
  18. cachedTypedArrays[semantic] = typedArray;
  19. }
  20. return typedArray;
  21. }
  22. function getTypedArrayFromArray(featureTable, semantic, componentType, array) {
  23. var cachedTypedArrays = featureTable._cachedTypedArrays;
  24. var typedArray = cachedTypedArrays[semantic];
  25. if (!defined(typedArray)) {
  26. typedArray = ComponentDatatype.createTypedArray(componentType, array);
  27. cachedTypedArrays[semantic] = typedArray;
  28. }
  29. return typedArray;
  30. }
  31. Cesium3DTileFeatureTable.prototype.getGlobalProperty = function(semantic, componentType, componentLength) {
  32. var jsonValue = this.json[semantic];
  33. if (!defined(jsonValue)) {
  34. return undefined;
  35. }
  36. if (defined(jsonValue.byteOffset)) {
  37. componentType = defaultValue(componentType, ComponentDatatype.UNSIGNED_INT);
  38. componentLength = defaultValue(componentLength, 1);
  39. return getTypedArrayFromBinary(this, semantic, componentType, componentLength, 1, jsonValue.byteOffset);
  40. }
  41. return jsonValue;
  42. };
  43. Cesium3DTileFeatureTable.prototype.getPropertyArray = function(semantic, componentType, componentLength) {
  44. var jsonValue = this.json[semantic];
  45. if (!defined(jsonValue)) {
  46. return undefined;
  47. }
  48. if (defined(jsonValue.byteOffset)) {
  49. if (defined(jsonValue.componentType)) {
  50. componentType = ComponentDatatype.fromName(jsonValue.componentType);
  51. }
  52. return getTypedArrayFromBinary(this, semantic, componentType, componentLength, this.featuresLength, jsonValue.byteOffset);
  53. }
  54. return getTypedArrayFromArray(this, semantic, componentType, jsonValue);
  55. };
  56. Cesium3DTileFeatureTable.prototype.getProperty = function(semantic, componentType, componentLength, featureId, result) {
  57. var jsonValue = this.json[semantic];
  58. if (!defined(jsonValue)) {
  59. return undefined;
  60. }
  61. var typedArray = this.getPropertyArray(semantic, componentType, componentLength);
  62. if (componentLength === 1) {
  63. return typedArray[featureId];
  64. }
  65. for (var i = 0; i < componentLength; ++i) {
  66. result[i] = typedArray[componentLength * featureId + i];
  67. }
  68. return result;
  69. };
  70. export default Cesium3DTileFeatureTable;