@loaders.gl/i3s 3.1.0-alpha.5 → 3.1.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/bundle.d.ts +1 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +10364 -0
  4. package/dist/es5/i3s-attribute-loader.js +1 -1
  5. package/dist/es5/i3s-attribute-loader.js.map +1 -1
  6. package/dist/es5/i3s-building-scene-layer-loader.js +1 -1
  7. package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -1
  8. package/dist/es5/i3s-content-loader.js +1 -1
  9. package/dist/es5/i3s-content-loader.js.map +1 -1
  10. package/dist/es5/i3s-loader.js +1 -1
  11. package/dist/es5/i3s-loader.js.map +1 -1
  12. package/dist/es5/i3s-node-page-loader.js +1 -1
  13. package/dist/es5/i3s-node-page-loader.js.map +1 -1
  14. package/dist/es5/lib/parsers/constants.js +61 -25
  15. package/dist/es5/lib/parsers/constants.js.map +1 -1
  16. package/dist/es5/lib/parsers/parse-i3s-tile-content.js +42 -36
  17. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  18. package/dist/es5/lib/utils/url-utils.js.map +1 -1
  19. package/dist/es5/types.js +19 -0
  20. package/dist/es5/types.js.map +1 -1
  21. package/dist/esm/i3s-attribute-loader.js +1 -1
  22. package/dist/esm/i3s-attribute-loader.js.map +1 -1
  23. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  24. package/dist/esm/i3s-building-scene-layer-loader.js.map +1 -1
  25. package/dist/esm/i3s-content-loader.js +1 -1
  26. package/dist/esm/i3s-content-loader.js.map +1 -1
  27. package/dist/esm/i3s-loader.js +1 -1
  28. package/dist/esm/i3s-loader.js.map +1 -1
  29. package/dist/esm/i3s-node-page-loader.js +1 -1
  30. package/dist/esm/i3s-node-page-loader.js.map +1 -1
  31. package/dist/esm/lib/parsers/constants.js +54 -22
  32. package/dist/esm/lib/parsers/constants.js.map +1 -1
  33. package/dist/esm/lib/parsers/parse-i3s-tile-content.js +41 -37
  34. package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  35. package/dist/esm/lib/utils/url-utils.js.map +1 -1
  36. package/dist/esm/types.js +13 -1
  37. package/dist/esm/types.js.map +1 -1
  38. package/dist/i3s-attribute-loader.d.ts +1 -0
  39. package/dist/i3s-attribute-loader.d.ts.map +1 -0
  40. package/dist/i3s-attribute-loader.js +177 -0
  41. package/dist/i3s-building-scene-layer-loader.d.ts +1 -0
  42. package/dist/i3s-building-scene-layer-loader.d.ts.map +1 -0
  43. package/dist/i3s-building-scene-layer-loader.js +26 -0
  44. package/dist/i3s-content-loader.d.ts +1 -0
  45. package/dist/i3s-content-loader.d.ts.map +1 -0
  46. package/dist/i3s-content-loader.js +28 -0
  47. package/dist/i3s-content-worker.js +7657 -2
  48. package/dist/i3s-loader.d.ts +1 -0
  49. package/dist/i3s-loader.d.ts.map +1 -0
  50. package/dist/i3s-loader.js +100 -0
  51. package/dist/i3s-node-page-loader.d.ts +1 -0
  52. package/dist/i3s-node-page-loader.d.ts.map +1 -0
  53. package/dist/i3s-node-page-loader.js +26 -0
  54. package/dist/index.d.ts +1 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +14 -0
  57. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts +1 -0
  58. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts.map +1 -0
  59. package/dist/lib/helpers/i3s-nodepages-tiles.js +231 -0
  60. package/dist/lib/parsers/constants.d.ts +34 -27
  61. package/dist/lib/parsers/constants.d.ts.map +1 -0
  62. package/dist/lib/parsers/constants.js +107 -0
  63. package/dist/lib/parsers/parse-i3s-attribute.d.ts +2 -1
  64. package/dist/lib/parsers/parse-i3s-attribute.d.ts.map +1 -0
  65. package/dist/lib/parsers/parse-i3s-attribute.js +98 -0
  66. package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts +1 -0
  67. package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts.map +1 -0
  68. package/dist/lib/parsers/parse-i3s-building-scene-layer.js +46 -0
  69. package/dist/lib/parsers/parse-i3s-tile-content.d.ts +2 -1
  70. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -0
  71. package/dist/lib/parsers/parse-i3s-tile-content.js +508 -0
  72. package/dist/lib/parsers/parse-i3s.d.ts +1 -0
  73. package/dist/lib/parsers/parse-i3s.d.ts.map +1 -0
  74. package/dist/lib/parsers/parse-i3s.js +84 -0
  75. package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts +1 -0
  76. package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts.map +1 -0
  77. package/dist/lib/utils/convert-i3s-obb-to-mbs.js +20 -0
  78. package/dist/lib/utils/url-utils.d.ts +2 -1
  79. package/dist/lib/utils/url-utils.d.ts.map +1 -0
  80. package/dist/lib/utils/url-utils.js +44 -0
  81. package/dist/types.d.ts +98 -13
  82. package/dist/types.d.ts.map +1 -0
  83. package/dist/types.js +15 -0
  84. package/dist/workers/i3s-content-worker.d.ts +1 -0
  85. package/dist/workers/i3s-content-worker.d.ts.map +1 -0
  86. package/dist/workers/i3s-content-worker.js +5 -0
  87. package/package.json +11 -12
  88. package/src/lib/parsers/constants.ts +69 -36
  89. package/src/lib/parsers/parse-i3s-tile-content.ts +110 -85
  90. package/src/lib/utils/url-utils.ts +1 -1
  91. package/src/types.ts +153 -22
  92. package/dist/dist.min.js +0 -2
  93. package/dist/dist.min.js.map +0 -1
  94. package/dist/i3s-content-worker.js.map +0 -1
@@ -3,18 +3,28 @@ import {load, parse} from '@loaders.gl/core';
3
3
  import {Vector3, Matrix4} from '@math.gl/core';
4
4
  import {Ellipsoid} from '@math.gl/geospatial';
5
5
 
6
+ import type {GLTFMaterial} from '@loaders.gl/gltf';
6
7
  import type {LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
7
8
  import {ImageLoader} from '@loaders.gl/images';
8
9
  import {DracoLoader} from '@loaders.gl/draco';
9
10
  import {BasisLoader, CompressedTextureLoader} from '@loaders.gl/textures';
10
11
 
11
- import {Tileset, Tile} from '../../types';
12
+ import type {
13
+ Tileset,
14
+ Tile,
15
+ FeatureAttribute,
16
+ TileContent,
17
+ VertexAttribute,
18
+ NormalizedAttribute,
19
+ NormalizedAttributes,
20
+ TileContentTexture
21
+ } from '../../types';
12
22
  import {getUrlWithToken} from '../utils/url-utils';
13
23
 
14
24
  import {
15
25
  GL_TYPE_MAP,
16
- TYPE_ARRAY_MAP,
17
- SIZEOF,
26
+ getConstructorForDataFormat,
27
+ sizeOf,
18
28
  I3S_NAMED_HEADER_ATTRIBUTES,
19
29
  I3S_NAMED_VERTEX_ATTRIBUTES,
20
30
  I3S_NAMED_GEOMETRY_ATTRIBUTES,
@@ -23,13 +33,20 @@ import {
23
33
 
24
34
  const scratchVector = new Vector3([0, 0, 0]);
25
35
 
26
- const FORMAT_LOADER_MAP = {
27
- jpeg: ImageLoader,
28
- png: ImageLoader,
29
- 'ktx-etc2': CompressedTextureLoader,
30
- dds: CompressedTextureLoader,
31
- ktx2: BasisLoader
32
- };
36
+ function getLoaderForTextureFormat(textureFormat: 'jpeg' | 'png' | 'ktx-etc2' | 'dds' | 'ktx2') {
37
+ switch (textureFormat) {
38
+ case 'jpeg':
39
+ case 'png':
40
+ return ImageLoader;
41
+ case 'ktx-etc2':
42
+ case 'dds':
43
+ return CompressedTextureLoader;
44
+ case 'ktx2':
45
+ return BasisLoader;
46
+ default:
47
+ return null;
48
+ }
49
+ }
33
50
 
34
51
  const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
35
52
 
@@ -44,12 +61,12 @@ export async function parseI3STileContent(
44
61
  tile.content.featureIds = tile.content.featureIds || null;
45
62
 
46
63
  // construct featureData from defaultGeometrySchema;
47
- tile.content.featureData = constructFeatureDataStruct(tile, tileset);
64
+ tile.content.featureData = constructFeatureDataStruct(tileset);
48
65
  tile.content.attributes = {};
49
66
 
50
67
  if (tile.textureUrl) {
51
68
  const url = getUrlWithToken(tile.textureUrl, options?.i3s?.token);
52
- const loader = FORMAT_LOADER_MAP[tile.textureFormat] || ImageLoader;
69
+ const loader = getLoaderForTextureFormat(tile.textureFormat) || ImageLoader;
53
70
  // @ts-ignore context must be defined
54
71
  const response = await fetch(url);
55
72
  const arrayBuffer = await response.arrayBuffer();
@@ -87,25 +104,20 @@ export async function parseI3STileContent(
87
104
  tile.content.texture = null;
88
105
  }
89
106
 
90
- return await parseI3SNodeGeometry(arrayBuffer, tile, options, context);
107
+ return await parseI3SNodeGeometry(arrayBuffer, tile, options);
91
108
  }
92
109
 
93
110
  /* eslint-disable max-statements */
94
- async function parseI3SNodeGeometry(
95
- arrayBuffer: ArrayBuffer,
96
- tile: Tile = {},
97
- options?: LoaderOptions,
98
- context?: LoaderContext
99
- ) {
111
+ async function parseI3SNodeGeometry(arrayBuffer: ArrayBuffer, tile: Tile, options?: LoaderOptions) {
100
112
  if (!tile.content) {
101
113
  return tile;
102
114
  }
103
115
 
104
116
  const content = tile.content;
105
- let attributes;
106
- let vertexCount;
107
- let byteOffset = 0;
108
- let featureCount = 0;
117
+ let attributes: NormalizedAttributes;
118
+ let vertexCount: number;
119
+ let byteOffset: number = 0;
120
+ let featureCount: number = 0;
109
121
 
110
122
  if (tile.isDracoGeometry) {
111
123
  const decompressedGeometry = await parse(arrayBuffer, DracoLoader, {
@@ -156,6 +168,7 @@ async function parseI3SNodeGeometry(
156
168
  byteOffset,
157
169
  vertexAttributes,
158
170
  vertexCount,
171
+ // @ts-expect-error
159
172
  attributesOrder
160
173
  );
161
174
 
@@ -176,7 +189,7 @@ async function parseI3SNodeGeometry(
176
189
  !options?.i3s?.coordinateSystem ||
177
190
  options.i3s.coordinateSystem === COORDINATE_SYSTEM.METER_OFFSETS
178
191
  ) {
179
- const {enuMatrix} = parsePositions(attributes.position, tile);
192
+ const enuMatrix = parsePositions(attributes.position, tile);
180
193
  content.modelMatrix = enuMatrix.invert();
181
194
  content.coordinateSystem = COORDINATE_SYSTEM.METER_OFFSETS;
182
195
  } else {
@@ -215,7 +228,7 @@ async function parseI3SNodeGeometry(
215
228
  * @param decompressedGeometry
216
229
  * @param attributes
217
230
  */
218
- function updateAttributesMetadata(attributes, decompressedGeometry) {
231
+ function updateAttributesMetadata(attributes: NormalizedAttributes, decompressedGeometry): void {
219
232
  for (const key in decompressedGeometry.loaderData.attributes) {
220
233
  const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
221
234
 
@@ -235,20 +248,23 @@ function updateAttributesMetadata(attributes, decompressedGeometry) {
235
248
  /**
236
249
  * Do concatenation of attribute objects.
237
250
  * Done as separate fucntion to avoid ts errors.
238
- * @param {Object} normalizedVertexAttributes
239
- * @param {Object} normalizedFeatureAttributes
240
- * @returns {object} - result of attributes concatenation.
251
+ * @param normalizedVertexAttributes
252
+ * @param normalizedFeatureAttributes
253
+ * @returns - result of attributes concatenation.
241
254
  */
242
- function concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes) {
255
+ function concatAttributes(
256
+ normalizedVertexAttributes: NormalizedAttributes,
257
+ normalizedFeatureAttributes: NormalizedAttributes
258
+ ): NormalizedAttributes {
243
259
  return {...normalizedVertexAttributes, ...normalizedFeatureAttributes};
244
260
  }
245
261
 
246
262
  /**
247
263
  * Normalize attribute to range [0..1] . Eg. convert colors buffer from [255,255,255,255] to [1,1,1,1]
248
- * @param {Object} attribute - geometry attribute
249
- * @returns {Object} - geometry attribute in right format
264
+ * @param attribute - geometry attribute
265
+ * @returns - geometry attribute in right format
250
266
  */
251
- function normalizeAttribute(attribute) {
267
+ function normalizeAttribute(attribute: NormalizedAttribute): NormalizedAttribute {
252
268
  if (!attribute) {
253
269
  return attribute;
254
270
  }
@@ -256,7 +272,7 @@ function normalizeAttribute(attribute) {
256
272
  return attribute;
257
273
  }
258
274
 
259
- function constructFeatureDataStruct(tile, tileset) {
275
+ function constructFeatureDataStruct(tileset: Tileset) {
260
276
  // seed featureData from defaultGeometrySchema
261
277
  const defaultGeometrySchema = tileset.store.defaultGeometrySchema;
262
278
  const featureData = defaultGeometrySchema;
@@ -281,24 +297,25 @@ function constructFeatureDataStruct(tile, tileset) {
281
297
  return featureData;
282
298
  }
283
299
 
284
- function parseHeaders(content, buffer) {
300
+ function parseHeaders(content: TileContent, arrayBuffer: ArrayBuffer) {
285
301
  let byteOffset = 0;
286
302
  // First 8 bytes reserved for header (vertexCount and featurecount)
287
303
  let vertexCount = 0;
288
304
  let featureCount = 0;
289
- const headers = content.featureData[I3S_NAMED_HEADER_ATTRIBUTES.header];
290
- for (const header in headers) {
291
- const {property, type} = headers[header];
292
- const TypedArrayTypeHeader = TYPE_ARRAY_MAP[type];
305
+ content.featureData.header.forEach(({property, type}) => {
306
+ const TypedArrayTypeHeader = getConstructorForDataFormat(type);
293
307
  if (property === I3S_NAMED_HEADER_ATTRIBUTES.vertexCount) {
294
- vertexCount = new TypedArrayTypeHeader(buffer, 0, 4)[0];
295
- byteOffset += SIZEOF[type];
308
+ // @ts-expect-error
309
+ vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
310
+ byteOffset += sizeOf(type);
296
311
  }
297
312
  if (property === I3S_NAMED_HEADER_ATTRIBUTES.featureCount) {
298
- featureCount = new TypedArrayTypeHeader(buffer, 4, 4)[0];
299
- byteOffset += SIZEOF[type];
313
+ // @ts-expect-error
314
+ featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
315
+ byteOffset += sizeOf(type);
300
316
  }
301
- }
317
+ });
318
+
302
319
  return {
303
320
  vertexCount,
304
321
  featureCount,
@@ -309,18 +326,19 @@ function parseHeaders(content, buffer) {
309
326
  /* eslint-enable max-statements */
310
327
 
311
328
  function normalizeAttributes(
312
- arrayBuffer,
313
- byteOffset,
314
- vertexAttributes,
315
- vertexCount,
316
- attributesOrder
329
+ arrayBuffer: ArrayBuffer,
330
+ byteOffset: number,
331
+ vertexAttributes: VertexAttribute | FeatureAttribute,
332
+ vertexCount: number,
333
+ attributesOrder: string[]
317
334
  ) {
318
- const attributes = {};
335
+ const attributes: NormalizedAttributes = {};
319
336
 
320
337
  // the order of attributes depend on the order being added to the vertexAttributes object
321
338
  for (const attribute of attributesOrder) {
322
339
  if (vertexAttributes[attribute]) {
323
- const {valueType, valuesPerElement} = vertexAttributes[attribute];
340
+ const {valueType, valuesPerElement}: {valueType: string; valuesPerElement: number} =
341
+ vertexAttributes[attribute];
324
342
  // update count and byteOffset count by calculating from defaultGeometrySchema + binnary content
325
343
  const count = vertexCount;
326
344
  // protect from arrayBuffer read overunns by NOT assuming node has regions always even though its declared in defaultGeometrySchema.
@@ -336,9 +354,10 @@ function normalizeAttributes(
336
354
  let value: number[] | TypedArray = [];
337
355
 
338
356
  if (valueType === 'UInt64') {
339
- value = parseUint64Values(buffer, count * valuesPerElement, SIZEOF[valueType]);
357
+ value = parseUint64Values(buffer, count * valuesPerElement, sizeOf(valueType));
340
358
  } else {
341
- const TypedArrayType = TYPE_ARRAY_MAP[valueType];
359
+ const TypedArrayType = getConstructorForDataFormat(valueType);
360
+ // @ts-expect-error
342
361
  value = new TypedArrayType(buffer, 0, count * valuesPerElement);
343
362
  }
344
363
 
@@ -350,7 +369,6 @@ function normalizeAttributes(
350
369
 
351
370
  switch (attribute) {
352
371
  case 'color':
353
- // @ts-ignore
354
372
  attributes.color.normalized = true;
355
373
  break;
356
374
  case 'position':
@@ -359,7 +377,7 @@ function normalizeAttributes(
359
377
  default:
360
378
  }
361
379
 
362
- byteOffset = byteOffset + count * valuesPerElement * SIZEOF[valueType];
380
+ byteOffset = byteOffset + count * valuesPerElement * sizeOf(valueType);
363
381
  }
364
382
  }
365
383
 
@@ -396,7 +414,7 @@ function parseUint64Values(
396
414
  return values;
397
415
  }
398
416
 
399
- function parsePositions(attribute, tile) {
417
+ function parsePositions(attribute: NormalizedAttribute, tile: Tile): Matrix4 {
400
418
  const mbs = tile.mbs;
401
419
  const value = attribute.value;
402
420
  const metadata = attribute.metadata;
@@ -407,20 +425,22 @@ function parsePositions(attribute, tile) {
407
425
  Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
408
426
  attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
409
427
 
410
- return {
411
- enuMatrix
412
- };
428
+ return enuMatrix;
413
429
  }
414
430
 
415
431
  /**
416
432
  * Converts position coordinates to absolute cartesian coordinates
417
- * @param {Float32Array} vertices - "position" attribute data
418
- * @param {Object} metadata - When the geometry is DRACO compressed, contain position attribute's metadata
433
+ * @param vertices - "position" attribute data
434
+ * @param metadata - When the geometry is DRACO compressed, contain position attribute's metadata
419
435
  * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/compressedAttributes.cmn.md
420
- * @param {Vector3} cartographicOrigin - Cartographic origin coordinates
421
- * @returns {Float64Array} - converted "position" data
436
+ * @param cartographicOrigin - Cartographic origin coordinates
437
+ * @returns - converted "position" data
422
438
  */
423
- function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
439
+ function offsetsToCartesians(
440
+ vertices: number[] | TypedArray,
441
+ metadata: any = {},
442
+ cartographicOrigin: Vector3
443
+ ): Float64Array {
424
444
  const positions = new Float64Array(vertices.length);
425
445
  const scaleX = (metadata['i3s-scale_x'] && metadata['i3s-scale_x'].double) || 1;
426
446
  const scaleY = (metadata['i3s-scale_y'] && metadata['i3s-scale_y'].double) || 1;
@@ -446,10 +466,10 @@ function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
446
466
  * @param positions positions attribute
447
467
  * @returns Matrix4 - model matrix for geometry transformation
448
468
  */
449
- function getModelMatrix(positions) {
469
+ function getModelMatrix(positions: NormalizedAttribute): Matrix4 {
450
470
  const metadata = positions.metadata;
451
- const scaleX = metadata?.['i3s-scale_x']?.double || 1;
452
- const scaleY = metadata?.['i3s-scale_y']?.double || 1;
471
+ const scaleX: number = metadata?.['i3s-scale_x']?.double || 1;
472
+ const scaleY: number = metadata?.['i3s-scale_y']?.double || 1;
453
473
  const modelMatrix = new Matrix4();
454
474
  modelMatrix[0] = scaleX;
455
475
  modelMatrix[5] = scaleY;
@@ -458,12 +478,12 @@ function getModelMatrix(positions) {
458
478
 
459
479
  /**
460
480
  * Makes a glTF-compatible PBR material from an I3S material definition
461
- * @param {object} materialDefinition - i3s material definition
481
+ * @param materialDefinition - i3s material definition
462
482
  * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
463
- * @param {object} texture - texture image
483
+ * @param texture - texture image
464
484
  * @returns {object}
465
485
  */
466
- function makePbrMaterial(materialDefinition, texture) {
486
+ function makePbrMaterial(materialDefinition: GLTFMaterial, texture: TileContentTexture) {
467
487
  let pbrMaterial;
468
488
  if (materialDefinition) {
469
489
  pbrMaterial = {
@@ -508,10 +528,10 @@ function makePbrMaterial(materialDefinition, texture) {
508
528
 
509
529
  /**
510
530
  * Convert color from [255,255,255,255] to [1,1,1,1]
511
- * @param {Array} colorFactor - color array
512
- * @returns {Array} - new color array
531
+ * @param colorFactor - color array
532
+ * @returns - new color array
513
533
  */
514
- function convertColorFormat(colorFactor) {
534
+ function convertColorFormat(colorFactor: number[]): number[] {
515
535
  const normalizedColor = [...colorFactor];
516
536
  for (let index = 0; index < colorFactor.length; index++) {
517
537
  normalizedColor[index] = colorFactor[index] / 255;
@@ -522,10 +542,10 @@ function convertColorFormat(colorFactor) {
522
542
  /**
523
543
  * Set texture in PBR material
524
544
  * @param {object} material - i3s material definition
525
- * @param {object} image - texture image
526
- * @returns {void}
545
+ * @param image - texture image
546
+ * @returns
527
547
  */
528
- function setMaterialTexture(material, image) {
548
+ function setMaterialTexture(material, image: TileContentTexture): void {
529
549
  const texture = {source: {image}};
530
550
  // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
531
551
  // properties defined in materialDefinition
@@ -553,10 +573,10 @@ function setMaterialTexture(material, image) {
553
573
 
554
574
  /**
555
575
  * Flatten feature ids using face ranges
556
- * @param {object} normalizedFeatureAttributes
557
- * @returns {void}
576
+ * @param normalizedFeatureAttributes
577
+ * @returns
558
578
  */
559
- function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
579
+ function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes: NormalizedAttributes): void {
560
580
  const {id, faceRange} = normalizedFeatureAttributes;
561
581
 
562
582
  if (!id || !faceRange) {
@@ -589,11 +609,14 @@ function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
589
609
 
590
610
  /**
591
611
  * Flatten feature ids using featureIndices
592
- * @param {object} attributes
593
- * @param {any} featureIds
594
- * @returns {void}
612
+ * @param attributes
613
+ * @param featureIds
614
+ * @returns
595
615
  */
596
- function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
616
+ function flattenFeatureIdsByFeatureIndices(
617
+ attributes: NormalizedAttributes,
618
+ featureIds: Int32Array
619
+ ): void {
597
620
  const featureIndices = attributes.id.value;
598
621
  const result = new Float32Array(featureIndices.length);
599
622
 
@@ -606,10 +629,12 @@ function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
606
629
 
607
630
  /**
608
631
  * Flatten feature ids using featureIndices
609
- * @param {object} featureIndex
610
- * @returns {Int32Array}
632
+ * @param featureIndex
633
+ * @returns
611
634
  */
612
- function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
635
+ function getFeatureIdsFromFeatureIndexMetadata(
636
+ featureIndex: NormalizedAttribute
637
+ ): Int32Array | undefined {
613
638
  return (
614
639
  featureIndex &&
615
640
  featureIndex.metadata &&
@@ -6,7 +6,7 @@ import {Tile} from '../../types';
6
6
  * @param {any} token
7
7
  * @returns {string}
8
8
  */
9
- export function getUrlWithToken(url, token = null) {
9
+ export function getUrlWithToken(url: string, token = null): string {
10
10
  return token ? `${url}?token=${token}` : url;
11
11
  }
12
12
 
package/src/types.ts CHANGED
@@ -1,10 +1,71 @@
1
1
  import type {GLTFMaterial} from '@loaders.gl/gltf';
2
- import type {Quaternion, Vector3} from '@math.gl/core';
2
+ import type {Matrix4, Quaternion, Vector3} from '@math.gl/core';
3
3
  import type {Mesh} from '@loaders.gl/gltf';
4
-
5
- export type Tileset = {[key: string]: any};
4
+ import type {TypedArray} from '@loaders.gl/schema';
5
+
6
+ export enum DATA_TYPE {
7
+ UInt8 = 'UInt8',
8
+ UInt16 = 'UInt16',
9
+ UInt32 = 'UInt32',
10
+ UInt64 = 'UInt64',
11
+ Int16 = 'Int16',
12
+ Int32 = 'Int32',
13
+ Int64 = 'Int64',
14
+ Float32 = 'Float32',
15
+ Float64 = 'Float64'
16
+ }
17
+ /**
18
+ * spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.8/3DSceneLayer.cmn.md
19
+ */
20
+ // TODO Replace "[key: string]: any" with actual defenition
21
+ export type Tileset = {
22
+ /**
23
+ * The store object describes the exact physical storage of a layer and enables the client to detect when multiple layers are served from the same store.
24
+ */
25
+ store: Store;
26
+ [key: string]: any;
27
+ };
28
+ // TODO Replace "[key: string]: any" with actual defenition
6
29
  export type NodePage = {[key: string]: any};
7
- export type Tile = {[key: string]: any};
30
+ // TODO Replace "[key: string]: any" with actual defenition
31
+ export type Tile = {
32
+ content: TileContent;
33
+ isDracoGeometry: boolean;
34
+ textureUrl: string;
35
+ url: string;
36
+ /**
37
+ * Resource reference describing a featureData document.
38
+ */
39
+ attributeData: Resource[];
40
+ textureFormat: 'jpeg' | 'png' | 'ktx-etc2' | 'dds' | 'ktx2';
41
+ textureLoaderOptions: any;
42
+ materialDefinition: GLTFMaterial;
43
+ mbs: Mbs;
44
+ };
45
+ // TODO Replace "[key: string]: any" with actual defenition
46
+ export type TileContent = {
47
+ featureData: DefaultGeometrySchema;
48
+ attributes: NormalizedAttributes;
49
+ indices: NormalizedAttribute | null;
50
+ featureIds: number[] | TypedArray;
51
+ vertexCount: number;
52
+ modelMatrix: Matrix4;
53
+ coordinateSystem: number;
54
+ byteLength: number;
55
+ texture: TileContentTexture;
56
+ [key: string]: any;
57
+ };
58
+
59
+ export type TileContentTexture =
60
+ | ArrayBuffer
61
+ | {
62
+ compressed: boolean;
63
+ mipmaps: boolean;
64
+ width: number;
65
+ height: number;
66
+ data: any;
67
+ }
68
+ | null;
8
69
 
9
70
  export type BoundingVolumes = {
10
71
  mbs: Mbs;
@@ -78,7 +139,9 @@ export type PopupInfo = {
78
139
  popupElements?: {text?: string; type?: string; fieldInfos?: FieldInfo[]}[];
79
140
  };
80
141
 
81
- // Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md
142
+ /**
143
+ * Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md
144
+ */
82
145
  export type Node3DIndexDocument = {
83
146
  id: string;
84
147
  version?: string;
@@ -173,7 +236,10 @@ export type Attribute = 'OBJECTID' | 'string' | 'double' | 'Int32' | string;
173
236
 
174
237
  export type Extent = [number, number, number, number];
175
238
 
176
- export type FeatureAttribute = {[key: string]: any};
239
+ export type FeatureAttribute = {
240
+ id: AttributeValue;
241
+ faceRange: AttributeValue;
242
+ };
177
243
 
178
244
  export type BuildingSceneLayerTileset = {
179
245
  header: BuildingSceneLayer;
@@ -294,7 +360,9 @@ type Domain = {
294
360
  mergePolicy?: string;
295
361
  splitPolicy?: string;
296
362
  };
297
-
363
+ /**
364
+ * spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.8/store.cmn.md
365
+ */
298
366
  type Store = {
299
367
  id: string | number;
300
368
  profile: string;
@@ -311,24 +379,87 @@ type Store = {
311
379
  lodModel: string;
312
380
  defaultGeometrySchema: DefaultGeometrySchema;
313
381
  };
314
-
382
+ /**
383
+ * Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.8/defaultGeometrySchema.cmn.md
384
+ */
315
385
  type DefaultGeometrySchema = {
316
- vartexCount: number;
317
- featureCount: number;
318
- position: Float32Array;
319
- normal: Float32Array;
320
- uv0: Float32Array;
321
- color: Uint8Array;
322
- id: Float32Array;
323
- faceRange: Uint32Array;
324
- region: Uint16Array;
325
- };
326
-
327
- // TODO change string to possible values from https://github.com/Esri/i3s-spec/blob/master/docs/1.8/heightModelInfo.cmn.md
386
+ geometryType?: 'triangles';
387
+ topology: 'PerAttributeArray' | 'Indexed';
388
+ header: {
389
+ property: 'vertexCount' | 'featureCount' | string;
390
+ type:
391
+ | DATA_TYPE.UInt8
392
+ | DATA_TYPE.UInt16
393
+ | DATA_TYPE.UInt32
394
+ | DATA_TYPE.UInt64
395
+ | DATA_TYPE.Int16
396
+ | DATA_TYPE.Int32
397
+ | DATA_TYPE.Int64
398
+ | DATA_TYPE.Float32
399
+ | DATA_TYPE.Float64;
400
+ }[];
401
+ ordering: string[];
402
+ vertexAttributes: VertexAttribute;
403
+ faces?: VertexAttribute;
404
+ featureAttributeOrder: string[];
405
+ featureAttributes: FeatureAttribute;
406
+ // TODO Do we realy need this Property?
407
+ attributesOrder?: string[];
408
+ };
409
+ export type VertexAttribute = {
410
+ position: GeometryAttribute;
411
+ normal: GeometryAttribute;
412
+ uv0: GeometryAttribute;
413
+ color: GeometryAttribute;
414
+ region?: GeometryAttribute;
415
+ };
416
+ export type GeometryAttribute = {
417
+ byteOffset?: number;
418
+ valueType:
419
+ | DATA_TYPE.UInt8
420
+ | DATA_TYPE.UInt16
421
+ | DATA_TYPE.Int16
422
+ | DATA_TYPE.Int32
423
+ | DATA_TYPE.Int64
424
+ | DATA_TYPE.Float32
425
+ | DATA_TYPE.Float64;
426
+ valuesPerElement: number;
427
+ };
428
+ export type NormalizedAttributes = {
429
+ [key: string]: NormalizedAttribute;
430
+ };
431
+ export type NormalizedAttribute = {
432
+ value: number[] | TypedArray;
433
+ type: number;
434
+ size: number;
435
+ normalized?: boolean;
436
+ metadata?: any;
437
+ };
328
438
  type HeightModelInfo = {
329
- heightModel: string;
439
+ heightModel: 'gravity_related_height' | 'ellipsoidal';
330
440
  vertCRS: string;
331
- heightUnit: string;
441
+ heightUnit:
442
+ | 'meter'
443
+ | 'us-foot'
444
+ | 'foot'
445
+ | 'clarke-foot'
446
+ | 'clarke-yard'
447
+ | 'clarke-link'
448
+ | 'sears-yard'
449
+ | 'sears-foot'
450
+ | 'sears-chain'
451
+ | 'benoit-1895-b-chain'
452
+ | 'indian-yard'
453
+ | 'indian-1937-yard'
454
+ | 'gold-coast-foot'
455
+ | 'sears-1922-truncated-chain'
456
+ | 'us-inch'
457
+ | 'us-mile'
458
+ | 'us-yard'
459
+ | 'millimeter'
460
+ | 'decimeter'
461
+ | 'centimeter'
462
+ | 'kilometer';
332
463
  };
333
464
 
334
465
  type NodePages = {