@@ -18,13 +18,13 @@ import C3DTilesTypes from './C3DTilesTypes';
18
18
*/
19
19
class C3DTBatchTable {
20
20
/**
21
- * @param {ArrayBuffer } buffer - batch table buffer to parse
22
- * @param {number } jsonLength - batch table json part length
23
- * @param {number } binaryLength - batch table binary part length
24
- * @param {number } batchLength - the length of the batch.
25
- * @param {Object } registeredExtensions - extensions registered to the layer
21
+ * @param {ArrayBuffer } [ buffer=new ArrayBuffer()] - batch table buffer to parse
22
+ * @param {number } [ jsonLength=0] - batch table json part length
23
+ * @param {number } [ binaryLength=0] - batch table binary part length
24
+ * @param {number } [ batchLength=0] - the length of the batch.
25
+ * @param {Object } [ registeredExtensions] - extensions registered to the layer
26
26
*/
27
- constructor ( buffer , jsonLength , binaryLength , batchLength , registeredExtensions ) {
27
+ constructor ( buffer = new ArrayBuffer ( ) , jsonLength = 0 , binaryLength = 0 , batchLength = 0 , registeredExtensions ) {
28
28
if ( arguments . length === 4 &&
29
29
typeof batchLength === 'object' &&
30
30
! Array . isArray ( batchLength ) &&
@@ -40,7 +40,8 @@ class C3DTBatchTable {
40
40
this . batchLength = batchLength ;
41
41
42
42
const jsonBuffer = buffer . slice ( 0 , jsonLength ) ;
43
- const jsonContent = JSON . parse ( utf8Decoder . decode ( new Uint8Array ( jsonBuffer ) ) ) ;
43
+ const decodedJsonBuffer = utf8Decoder . decode ( new Uint8Array ( jsonBuffer ) ) ;
44
+ const jsonContent = decodedJsonBuffer === '' ? null : JSON . parse ( decodedJsonBuffer ) ;
44
45
45
46
if ( binaryLength > 0 ) {
46
47
const binaryBuffer = buffer . slice ( jsonLength , jsonLength + binaryLength ) ;
@@ -71,7 +72,7 @@ class C3DTBatchTable {
71
72
// returned object to batchTable.extensions
72
73
// Extensions must be registered in the layer (see an example of this in
73
74
// 3dtiles_hierarchy.html)
74
- if ( jsonContent . extensions ) {
75
+ if ( jsonContent && jsonContent . extensions ) {
75
76
this . extensions =
76
77
registeredExtensions . parseExtensions ( jsonContent . extensions , this . type ) ;
77
78
delete jsonContent . extensions ;
0 commit comments