@loaders.gl/i3s 4.0.0-beta.7 → 4.0.0-beta.8

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 (35) hide show
  1. package/LICENSE +7 -7
  2. package/dist/dist.dev.js +281 -284
  3. package/dist/i3s-content-worker-node.js +48 -48
  4. package/dist/i3s-content-worker-node.js.map +4 -4
  5. package/dist/i3s-content-worker.js +7 -185
  6. package/dist/i3s-loader.d.ts.map +1 -1
  7. package/dist/i3s-loader.js +1 -2
  8. package/dist/i3s-loader.js.map +1 -1
  9. package/dist/index.cjs +285 -298
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/lib/parsers/constants.d.ts.map +1 -1
  15. package/dist/lib/parsers/constants.js.map +1 -1
  16. package/dist/lib/parsers/parse-i3s-attribute.d.ts.map +1 -1
  17. package/dist/lib/parsers/parse-i3s-attribute.js.map +1 -1
  18. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -1
  19. package/dist/lib/parsers/parse-i3s-tile-content.js +0 -2
  20. package/dist/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  21. package/dist/lib/utils/customize-colors.d.ts +30 -0
  22. package/dist/lib/utils/customize-colors.d.ts.map +1 -0
  23. package/dist/lib/utils/customize-colors.js +92 -0
  24. package/dist/lib/utils/customize-colors.js.map +1 -0
  25. package/package.json +10 -10
  26. package/src/i3s-loader.ts +1 -2
  27. package/src/index.ts +2 -0
  28. package/src/lib/parsers/constants.ts +1 -0
  29. package/src/lib/parsers/parse-i3s-attribute.ts +1 -0
  30. package/src/lib/parsers/parse-i3s-tile-content.ts +0 -9
  31. package/src/lib/utils/{customize-/321/201olors.ts → customize-colors.ts} +66 -41
  32. package/dist/lib/utils/customize-/321/201olors.d.ts +0 -14
  33. package/dist/lib/utils/customize-/321/201olors.d.ts.map +0 -1
  34. package/dist/lib/utils/customize-/321/201olors.js +0 -98
  35. package/dist/lib/utils/customize-/321/201olors.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -28,6 +28,7 @@ __export(src_exports, {
28
28
  I3SLoader: () => I3SLoader,
29
29
  I3SNodePageLoader: () => I3SNodePageLoader,
30
30
  SLPKLoader: () => SLPKLoader,
31
+ customizeColors: () => customizeColors,
31
32
  loadFeatureAttributes: () => loadFeatureAttributes,
32
33
  parseSLPKArchive: () => parseSLPKArchive
33
34
  });
@@ -91,11 +92,11 @@ var COORDINATE_SYSTEM = /* @__PURE__ */ ((COORDINATE_SYSTEM2) => {
91
92
  })(COORDINATE_SYSTEM || {});
92
93
 
93
94
  // src/i3s-loader.ts
94
- var import_core7 = require("@loaders.gl/core");
95
+ var import_core5 = require("@loaders.gl/core");
95
96
 
96
97
  // src/lib/parsers/parse-i3s-tile-content.ts
97
- var import_core3 = require("@loaders.gl/core");
98
- var import_core4 = require("@math.gl/core");
98
+ var import_core = require("@loaders.gl/core");
99
+ var import_core2 = require("@math.gl/core");
99
100
  var import_geospatial = require("@math.gl/geospatial");
100
101
  var import_loader_utils = require("@loaders.gl/loader-utils");
101
102
  var import_images = require("@loaders.gl/images");
@@ -134,270 +135,8 @@ function generateTilesetAttributeUrls(tileset, url, resource) {
134
135
  return attributeUrls;
135
136
  }
136
137
 
137
- // src/lib/utils/customize-сolors.ts
138
- var import_core2 = require("@loaders.gl/core");
139
-
140
- // src/i3s-attribute-loader.ts
141
- var import_core = require("@loaders.gl/core");
142
-
143
- // src/lib/parsers/parse-i3s-attribute.ts
144
- function parseI3STileAttribute(arrayBuffer, options) {
145
- const { attributeName, attributeType } = options;
146
- if (!attributeName) {
147
- return {};
148
- }
149
- return {
150
- [attributeName]: attributeType ? parseAttribute(attributeType, arrayBuffer) : null
151
- };
152
- }
153
- function parseAttribute(attributeType, arrayBuffer) {
154
- switch (attributeType) {
155
- case STRING_ATTRIBUTE_TYPE:
156
- return parseStringsAttribute(arrayBuffer);
157
- case OBJECT_ID_ATTRIBUTE_TYPE:
158
- return parseShortNumberAttribute(arrayBuffer);
159
- case FLOAT_64_TYPE:
160
- return parseFloatAttribute(arrayBuffer);
161
- case INT_16_ATTRIBUTE_TYPE:
162
- return parseInt16ShortNumberAttribute(arrayBuffer);
163
- default:
164
- return parseShortNumberAttribute(arrayBuffer);
165
- }
166
- }
167
- function parseShortNumberAttribute(arrayBuffer) {
168
- const countOffset = 4;
169
- return new Uint32Array(arrayBuffer, countOffset);
170
- }
171
- function parseInt16ShortNumberAttribute(arrayBuffer) {
172
- const countOffset = 4;
173
- return new Int16Array(arrayBuffer, countOffset);
174
- }
175
- function parseFloatAttribute(arrayBuffer) {
176
- const countOffset = 8;
177
- return new Float64Array(arrayBuffer, countOffset);
178
- }
179
- function parseStringsAttribute(arrayBuffer) {
180
- const stringsCountOffset = 0;
181
- const dataOffset = 8;
182
- const bytesPerStringSize = 4;
183
- const stringsArray = [];
184
- try {
185
- const stringsCount = new DataView(
186
- arrayBuffer,
187
- stringsCountOffset,
188
- bytesPerStringSize
189
- ).getUint32(stringsCountOffset, true);
190
- const stringSizes = new Uint32Array(arrayBuffer, dataOffset, stringsCount);
191
- let stringOffset = dataOffset + stringsCount * bytesPerStringSize;
192
- for (const stringByteSize of stringSizes) {
193
- const textDecoder = new TextDecoder("utf-8");
194
- const stringAttribute = new Uint8Array(arrayBuffer, stringOffset, stringByteSize);
195
- stringsArray.push(textDecoder.decode(stringAttribute));
196
- stringOffset += stringByteSize;
197
- }
198
- } catch (error) {
199
- console.error("Parse string attribute error: ", error.message);
200
- }
201
- return stringsArray;
202
- }
203
-
204
- // src/i3s-attribute-loader.ts
205
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
206
- var EMPTY_VALUE = "";
207
- var REJECTED_STATUS = "rejected";
208
- var I3SAttributeLoader = {
209
- name: "I3S Attribute",
210
- id: "i3s-attribute",
211
- module: "i3s",
212
- version: VERSION,
213
- mimeTypes: ["application/binary"],
214
- parse: async (arrayBuffer, options) => parseI3STileAttribute(arrayBuffer, options),
215
- extensions: ["bin"],
216
- options: {},
217
- binary: true
218
- };
219
- async function loadFeatureAttributes(tile, featureId, options = {}) {
220
- var _a;
221
- const { attributeStorageInfo, attributeUrls, tilesetFields } = getAttributesData(tile);
222
- if (!attributeStorageInfo || !attributeUrls || featureId < 0) {
223
- return null;
224
- }
225
- let attributes = [];
226
- const attributeLoadPromises = [];
227
- for (let index = 0; index < attributeStorageInfo.length; index++) {
228
- const url = getUrlWithToken(attributeUrls[index], (_a = options.i3s) == null ? void 0 : _a.token);
229
- const attributeName = attributeStorageInfo[index].name;
230
- const attributeType = getAttributeValueType(attributeStorageInfo[index]);
231
- const loadOptions = { ...options, attributeName, attributeType };
232
- const promise = (0, import_core.load)(url, I3SAttributeLoader, loadOptions);
233
- attributeLoadPromises.push(promise);
234
- }
235
- try {
236
- attributes = await Promise.allSettled(attributeLoadPromises);
237
- } catch (error) {
238
- }
239
- if (!attributes.length) {
240
- return null;
241
- }
242
- return generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields);
243
- }
244
- function getAttributesData(tile) {
245
- var _a, _b, _c, _d, _e;
246
- const attributeStorageInfo = (_b = (_a = tile.tileset) == null ? void 0 : _a.tileset) == null ? void 0 : _b.attributeStorageInfo;
247
- const attributeUrls = (_c = tile.header) == null ? void 0 : _c.attributeUrls;
248
- const tilesetFields = ((_e = (_d = tile.tileset) == null ? void 0 : _d.tileset) == null ? void 0 : _e.fields) || [];
249
- return { attributeStorageInfo, attributeUrls, tilesetFields };
250
- }
251
- function getAttributeValueType(attribute) {
252
- if (attribute.hasOwnProperty("objectIds")) {
253
- return "Oid32";
254
- } else if (attribute.hasOwnProperty("attributeValues")) {
255
- return attribute.attributeValues.valueType;
256
- }
257
- return "";
258
- }
259
- function getFeatureIdsAttributeName(attributeStorageInfo) {
260
- const objectIdsAttribute = attributeStorageInfo.find((attribute) => attribute.name.includes("OBJECTID"));
261
- return objectIdsAttribute == null ? void 0 : objectIdsAttribute.name;
262
- }
263
- function generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields) {
264
- const objectIdsAttributeName = getFeatureIdsAttributeName(attributeStorageInfo);
265
- const objectIds = attributes.find((attribute) => attribute.value[objectIdsAttributeName]);
266
- if (!objectIds) {
267
- return null;
268
- }
269
- const attributeIndex = objectIds.value[objectIdsAttributeName].indexOf(featureId);
270
- if (attributeIndex < 0) {
271
- return null;
272
- }
273
- return getFeatureAttributesByIndex(attributes, attributeIndex, attributeStorageInfo, tilesetFields);
274
- }
275
- function getFeatureAttributesByIndex(attributes, featureIdIndex, attributeStorageInfo, tilesetFields) {
276
- const attributesObject = {};
277
- for (let index = 0; index < attributeStorageInfo.length; index++) {
278
- const attributeName = attributeStorageInfo[index].name;
279
- const codedValues = getAttributeCodedValues(attributeName, tilesetFields);
280
- const attribute = getAttributeByIndexAndAttributeName(attributes, index, attributeName);
281
- attributesObject[attributeName] = formatAttributeValue(attribute, featureIdIndex, codedValues);
282
- }
283
- return attributesObject;
284
- }
285
- function getAttributeCodedValues(attributeName, tilesetFields) {
286
- var _a;
287
- const attributeField = tilesetFields.find((field) => field.name === attributeName || field.alias === attributeName);
288
- return ((_a = attributeField == null ? void 0 : attributeField.domain) == null ? void 0 : _a.codedValues) || [];
289
- }
290
- function getAttributeByIndexAndAttributeName(attributes, index, attributesName) {
291
- const attributeObject = attributes[index];
292
- if (attributeObject.status === REJECTED_STATUS) {
293
- return null;
294
- }
295
- return attributeObject.value[attributesName];
296
- }
297
- function formatAttributeValue(attribute, featureIdIndex, codedValues) {
298
- let value = EMPTY_VALUE;
299
- if (attribute && featureIdIndex in attribute) {
300
- value = String(attribute[featureIdIndex]).replace(/\u0000|NaN/g, "").trim();
301
- }
302
- if (codedValues.length) {
303
- const codeValue = codedValues.find((codedValue) => codedValue.code === Number(value));
304
- value = (codeValue == null ? void 0 : codeValue.name) || EMPTY_VALUE;
305
- }
306
- return value;
307
- }
308
-
309
- // src/lib/utils/customize-сolors.ts
310
- async function customizeColors(colors, featureIds, tileOptions, tilesetOptions, options) {
311
- var _a;
312
- if (!((_a = options == null ? void 0 : options.i3s) == null ? void 0 : _a.colorsByAttribute)) {
313
- return colors;
314
- }
315
- const colorizeAttributeField = tilesetOptions.fields.find(
316
- ({ name }) => {
317
- var _a2, _b;
318
- return name === ((_b = (_a2 = options == null ? void 0 : options.i3s) == null ? void 0 : _a2.colorsByAttribute) == null ? void 0 : _b.attributeName);
319
- }
320
- );
321
- if (!colorizeAttributeField || !["esriFieldTypeDouble", "esriFieldTypeInteger", "esriFieldTypeSmallInteger"].includes(
322
- colorizeAttributeField.type
323
- )) {
324
- return colors;
325
- }
326
- const colorizeAttributeData = await loadFeatureAttributeData(
327
- colorizeAttributeField.name,
328
- tileOptions,
329
- tilesetOptions,
330
- options
331
- );
332
- if (!colorizeAttributeData) {
333
- return colors;
334
- }
335
- const objectIdField = tilesetOptions.fields.find(({ type }) => type === "esriFieldTypeOID");
336
- if (!objectIdField) {
337
- return colors;
338
- }
339
- const objectIdAttributeData = await loadFeatureAttributeData(
340
- objectIdField.name,
341
- tileOptions,
342
- tilesetOptions,
343
- options
344
- );
345
- if (!objectIdAttributeData) {
346
- return colors;
347
- }
348
- const attributeValuesMap = {};
349
- for (let i = 0; i < objectIdAttributeData[objectIdField.name].length; i++) {
350
- attributeValuesMap[objectIdAttributeData[objectIdField.name][i]] = calculateColorForAttribute(
351
- // @ts-expect-error
352
- colorizeAttributeData[colorizeAttributeField.name][i],
353
- options
354
- );
355
- }
356
- for (let i = 0; i < featureIds.value.length; i++) {
357
- const color = attributeValuesMap[featureIds.value[i]];
358
- if (!color) {
359
- continue;
360
- }
361
- if (options.i3s.colorsByAttribute.mode === "multiply") {
362
- color.forEach((colorItem, index) => {
363
- colors.value[i * 4 + index] = colors.value[i * 4 + index] * colorItem / 255;
364
- });
365
- } else {
366
- colors.value.set(color, i * 4);
367
- }
368
- }
369
- return colors;
370
- }
371
- function calculateColorForAttribute(attributeValue, options) {
372
- var _a;
373
- if (!((_a = options == null ? void 0 : options.i3s) == null ? void 0 : _a.colorsByAttribute)) {
374
- return [255, 255, 255, 255];
375
- }
376
- const { minValue, maxValue, minColor, maxColor } = options.i3s.colorsByAttribute;
377
- const rate = (attributeValue - minValue) / (maxValue - minValue);
378
- const color = [255, 255, 255, 255];
379
- for (let i = 0; i < minColor.length; i++) {
380
- color[i] = Math.round((maxColor[i] - minColor[i]) * rate + minColor[i]);
381
- }
382
- return color;
383
- }
384
- async function loadFeatureAttributeData(attributeName, { attributeUrls }, { attributeStorageInfo }, options) {
385
- var _a;
386
- const attributeIndex = attributeStorageInfo.findIndex(({ name }) => attributeName === name);
387
- if (attributeIndex === -1) {
388
- return null;
389
- }
390
- const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], (_a = options == null ? void 0 : options.i3s) == null ? void 0 : _a.token);
391
- const attributeType = getAttributeValueType(attributeStorageInfo[attributeIndex]);
392
- const objectIdAttributeData = await (0, import_core2.load)(objectIdAttributeUrl, I3SAttributeLoader, {
393
- attributeName,
394
- attributeType
395
- });
396
- return objectIdAttributeData;
397
- }
398
-
399
138
  // src/lib/parsers/parse-i3s-tile-content.ts
400
- var scratchVector = new import_core4.Vector3([0, 0, 0]);
139
+ var scratchVector = new import_core2.Vector3([0, 0, 0]);
401
140
  function getLoaderForTextureFormat(textureFormat) {
402
141
  switch (textureFormat) {
403
142
  case "ktx-etc2":
@@ -419,7 +158,7 @@ async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, opt
419
158
  indices: null,
420
159
  featureIds: [],
421
160
  vertexCount: 0,
422
- modelMatrix: new import_core4.Matrix4(),
161
+ modelMatrix: new import_core2.Matrix4(),
423
162
  coordinateSystem: 0,
424
163
  byteLength: 0,
425
164
  texture: null
@@ -437,11 +176,11 @@ async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, opt
437
176
  const texture = await (0, import_loader_utils.parseFromContext)(arrayBuffer2, [], options2, context);
438
177
  content.texture = texture;
439
178
  } catch (e) {
440
- const texture = await (0, import_core3.parse)(arrayBuffer2, loader, options2, context);
179
+ const texture = await (0, import_core.parse)(arrayBuffer2, loader, options2, context);
441
180
  content.texture = texture;
442
181
  }
443
182
  } else if (loader === import_textures.CompressedTextureLoader || loader === import_textures.BasisLoader) {
444
- let texture = await (0, import_core3.load)(arrayBuffer2, loader, tileOptions.textureLoaderOptions);
183
+ let texture = await (0, import_core.load)(arrayBuffer2, loader, tileOptions.textureLoaderOptions);
445
184
  if (loader === import_textures.BasisLoader) {
446
185
  texture = texture[0];
447
186
  }
@@ -472,7 +211,7 @@ async function parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOp
472
211
  let featureCount = 0;
473
212
  let indices;
474
213
  if (tileOptions.isDracoGeometry) {
475
- const decompressedGeometry = await (0, import_core3.parse)(arrayBuffer, import_draco.DracoLoader, {
214
+ const decompressedGeometry = await (0, import_core.parse)(arrayBuffer, import_draco.DracoLoader, {
476
215
  draco: {
477
216
  attributeNameEntry: I3S_ATTRIBUTE_TYPE
478
217
  }
@@ -536,13 +275,6 @@ async function parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOp
536
275
  content.modelMatrix = getModelMatrix(attributes.position);
537
276
  content.coordinateSystem = 3 /* LNGLAT_OFFSETS */;
538
277
  }
539
- attributes.color = await customizeColors(
540
- attributes.color,
541
- attributes.id,
542
- tileOptions,
543
- tilesetOptions,
544
- options
545
- );
546
278
  content.attributes = {
547
279
  positions: attributes.position,
548
280
  normals: attributes.normal,
@@ -668,9 +400,9 @@ function parsePositions(attribute, options) {
668
400
  const mbs = options.mbs;
669
401
  const value = attribute.value;
670
402
  const metadata = attribute.metadata;
671
- const enuMatrix = new import_core4.Matrix4();
672
- const cartographicOrigin = new import_core4.Vector3(mbs[0], mbs[1], mbs[2]);
673
- const cartesianOrigin = new import_core4.Vector3();
403
+ const enuMatrix = new import_core2.Matrix4();
404
+ const cartographicOrigin = new import_core2.Vector3(mbs[0], mbs[1], mbs[2]);
405
+ const cartesianOrigin = new import_core2.Vector3();
674
406
  import_geospatial.Ellipsoid.WGS84.cartographicToCartesian(cartographicOrigin, cartesianOrigin);
675
407
  import_geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
676
408
  attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
@@ -698,7 +430,7 @@ function getModelMatrix(positions) {
698
430
  const metadata = positions.metadata;
699
431
  const scaleX = ((_a = metadata == null ? void 0 : metadata["i3s-scale_x"]) == null ? void 0 : _a.double) || 1;
700
432
  const scaleY = ((_b = metadata == null ? void 0 : metadata["i3s-scale_y"]) == null ? void 0 : _b.double) || 1;
701
- const modelMatrix = new import_core4.Matrix4();
433
+ const modelMatrix = new import_core2.Matrix4();
702
434
  modelMatrix[0] = scaleX;
703
435
  modelMatrix[5] = scaleY;
704
436
  return modelMatrix;
@@ -801,13 +533,13 @@ function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
801
533
  }
802
534
 
803
535
  // src/i3s-content-loader.ts
804
- var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
536
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
805
537
  var I3SContentLoader = {
806
538
  name: "I3S Content (Indexed Scene Layers)",
807
539
  id: "i3s-content",
808
540
  module: "i3s",
809
541
  worker: true,
810
- version: VERSION2,
542
+ version: VERSION,
811
543
  mimeTypes: ["application/octet-stream"],
812
544
  parse: parse2,
813
545
  extensions: ["bin"],
@@ -834,20 +566,20 @@ async function parse2(data, options, context) {
834
566
  // src/lib/parsers/parse-i3s.ts
835
567
  var import_culling = require("@math.gl/culling");
836
568
  var import_geospatial2 = require("@math.gl/geospatial");
837
- var import_core6 = require("@loaders.gl/core");
569
+ var import_core4 = require("@loaders.gl/core");
838
570
  var import_tiles = require("@loaders.gl/tiles");
839
571
 
840
572
  // src/lib/helpers/i3s-nodepages-tiles.ts
841
- var import_core5 = require("@loaders.gl/core");
573
+ var import_core3 = require("@loaders.gl/core");
842
574
  var import_textures2 = require("@loaders.gl/textures");
843
575
 
844
576
  // src/i3s-node-page-loader.ts
845
- var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
577
+ var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
846
578
  var I3SNodePageLoader = {
847
579
  name: "I3S Node Page",
848
580
  id: "i3s-node-page",
849
581
  module: "i3s",
850
- version: VERSION3,
582
+ version: VERSION2,
851
583
  mimeTypes: ["application/json"],
852
584
  parse: parseNodePage,
853
585
  extensions: ["json"],
@@ -897,7 +629,7 @@ var I3SNodePagesTiles = class {
897
629
  );
898
630
  this.pendingNodePages[pageIndex] = {
899
631
  status: "Pending",
900
- promise: (0, import_core5.load)(nodePageUrl, I3SNodePageLoader, this.options)
632
+ promise: (0, import_core3.load)(nodePageUrl, I3SNodePageLoader, this.options)
901
633
  };
902
634
  this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;
903
635
  this.nodesInNodePages += this.nodePages[pageIndex].nodes.length;
@@ -1168,7 +900,7 @@ async function normalizeTilesetData(tileset, options, context) {
1168
900
  } else {
1169
901
  const parseOptions = options.i3s;
1170
902
  const rootNodeUrl = getUrlWithToken(`${url}/nodes/root`, parseOptions.token);
1171
- root = await (0, import_core6.load)(rootNodeUrl, I3SLoader, {
903
+ root = await (0, import_core4.load)(rootNodeUrl, I3SLoader, {
1172
904
  ...options,
1173
905
  i3s: {
1174
906
  // @ts-expect-error options is not properly typed
@@ -1194,7 +926,7 @@ async function normalizeTilesetData(tileset, options, context) {
1194
926
  }
1195
927
 
1196
928
  // src/i3s-loader.ts
1197
- var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
929
+ var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1198
930
  var TILESET_REGEX = /layers\/[0-9]+$/;
1199
931
  var TILE_HEADER_REGEX = /nodes\/([0-9-]+|root)$/;
1200
932
  var SLPK_HEX = "504b0304";
@@ -1203,7 +935,7 @@ var I3SLoader = {
1203
935
  name: "I3S (Indexed Scene Layers)",
1204
936
  id: "i3s",
1205
937
  module: "i3s",
1206
- version: VERSION4,
938
+ version: VERSION3,
1207
939
  mimeTypes: ["application/octet-stream"],
1208
940
  parse: parseI3S,
1209
941
  extensions: ["bin"],
@@ -1219,8 +951,7 @@ var I3SLoader = {
1219
951
  useDracoGeometry: true,
1220
952
  useCompressedTextures: true,
1221
953
  decodeTextures: true,
1222
- coordinateSystem: 2 /* METER_OFFSETS */,
1223
- colorsByAttribute: null
954
+ coordinateSystem: 2 /* METER_OFFSETS */
1224
955
  }
1225
956
  }
1226
957
  };
@@ -1254,7 +985,7 @@ async function parseI3S(data, options = {}, context) {
1254
985
  return data;
1255
986
  }
1256
987
  async function parseTileContent(arrayBuffer, options) {
1257
- return await (0, import_core7.parse)(arrayBuffer, I3SContentLoader, options);
988
+ return await (0, import_core5.parse)(arrayBuffer, I3SContentLoader, options);
1258
989
  }
1259
990
  async function parseTileset(data, options, context) {
1260
991
  const tilesetJson = JSON.parse(new TextDecoder().decode(data));
@@ -1437,12 +1168,12 @@ async function parseSLPKArchive(fileProvider, cb) {
1437
1168
  }
1438
1169
 
1439
1170
  // src/i3s-slpk-loader.ts
1440
- var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1171
+ var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1441
1172
  var SLPKLoader = {
1442
1173
  name: "I3S SLPK (Scene Layer Package)",
1443
1174
  id: "slpk",
1444
1175
  module: "i3s",
1445
- version: VERSION5,
1176
+ version: VERSION4,
1446
1177
  mimeTypes: ["application/octet-stream"],
1447
1178
  extensions: ["slpk"],
1448
1179
  options: {},
@@ -1453,6 +1184,175 @@ var SLPKLoader = {
1453
1184
  }
1454
1185
  };
1455
1186
 
1187
+ // src/i3s-attribute-loader.ts
1188
+ var import_core6 = require("@loaders.gl/core");
1189
+
1190
+ // src/lib/parsers/parse-i3s-attribute.ts
1191
+ function parseI3STileAttribute(arrayBuffer, options) {
1192
+ const { attributeName, attributeType } = options;
1193
+ if (!attributeName) {
1194
+ return {};
1195
+ }
1196
+ return {
1197
+ [attributeName]: attributeType ? parseAttribute(attributeType, arrayBuffer) : null
1198
+ };
1199
+ }
1200
+ function parseAttribute(attributeType, arrayBuffer) {
1201
+ switch (attributeType) {
1202
+ case STRING_ATTRIBUTE_TYPE:
1203
+ return parseStringsAttribute(arrayBuffer);
1204
+ case OBJECT_ID_ATTRIBUTE_TYPE:
1205
+ return parseShortNumberAttribute(arrayBuffer);
1206
+ case FLOAT_64_TYPE:
1207
+ return parseFloatAttribute(arrayBuffer);
1208
+ case INT_16_ATTRIBUTE_TYPE:
1209
+ return parseInt16ShortNumberAttribute(arrayBuffer);
1210
+ default:
1211
+ return parseShortNumberAttribute(arrayBuffer);
1212
+ }
1213
+ }
1214
+ function parseShortNumberAttribute(arrayBuffer) {
1215
+ const countOffset = 4;
1216
+ return new Uint32Array(arrayBuffer, countOffset);
1217
+ }
1218
+ function parseInt16ShortNumberAttribute(arrayBuffer) {
1219
+ const countOffset = 4;
1220
+ return new Int16Array(arrayBuffer, countOffset);
1221
+ }
1222
+ function parseFloatAttribute(arrayBuffer) {
1223
+ const countOffset = 8;
1224
+ return new Float64Array(arrayBuffer, countOffset);
1225
+ }
1226
+ function parseStringsAttribute(arrayBuffer) {
1227
+ const stringsCountOffset = 0;
1228
+ const dataOffset = 8;
1229
+ const bytesPerStringSize = 4;
1230
+ const stringsArray = [];
1231
+ try {
1232
+ const stringsCount = new DataView(
1233
+ arrayBuffer,
1234
+ stringsCountOffset,
1235
+ bytesPerStringSize
1236
+ ).getUint32(stringsCountOffset, true);
1237
+ const stringSizes = new Uint32Array(arrayBuffer, dataOffset, stringsCount);
1238
+ let stringOffset = dataOffset + stringsCount * bytesPerStringSize;
1239
+ for (const stringByteSize of stringSizes) {
1240
+ const textDecoder = new TextDecoder("utf-8");
1241
+ const stringAttribute = new Uint8Array(arrayBuffer, stringOffset, stringByteSize);
1242
+ stringsArray.push(textDecoder.decode(stringAttribute));
1243
+ stringOffset += stringByteSize;
1244
+ }
1245
+ } catch (error) {
1246
+ console.error("Parse string attribute error: ", error.message);
1247
+ }
1248
+ return stringsArray;
1249
+ }
1250
+
1251
+ // src/i3s-attribute-loader.ts
1252
+ var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1253
+ var EMPTY_VALUE = "";
1254
+ var REJECTED_STATUS = "rejected";
1255
+ var I3SAttributeLoader = {
1256
+ name: "I3S Attribute",
1257
+ id: "i3s-attribute",
1258
+ module: "i3s",
1259
+ version: VERSION5,
1260
+ mimeTypes: ["application/binary"],
1261
+ parse: async (arrayBuffer, options) => parseI3STileAttribute(arrayBuffer, options),
1262
+ extensions: ["bin"],
1263
+ options: {},
1264
+ binary: true
1265
+ };
1266
+ async function loadFeatureAttributes(tile, featureId, options = {}) {
1267
+ var _a;
1268
+ const { attributeStorageInfo, attributeUrls, tilesetFields } = getAttributesData(tile);
1269
+ if (!attributeStorageInfo || !attributeUrls || featureId < 0) {
1270
+ return null;
1271
+ }
1272
+ let attributes = [];
1273
+ const attributeLoadPromises = [];
1274
+ for (let index = 0; index < attributeStorageInfo.length; index++) {
1275
+ const url = getUrlWithToken(attributeUrls[index], (_a = options.i3s) == null ? void 0 : _a.token);
1276
+ const attributeName = attributeStorageInfo[index].name;
1277
+ const attributeType = getAttributeValueType(attributeStorageInfo[index]);
1278
+ const loadOptions = { ...options, attributeName, attributeType };
1279
+ const promise = (0, import_core6.load)(url, I3SAttributeLoader, loadOptions);
1280
+ attributeLoadPromises.push(promise);
1281
+ }
1282
+ try {
1283
+ attributes = await Promise.allSettled(attributeLoadPromises);
1284
+ } catch (error) {
1285
+ }
1286
+ if (!attributes.length) {
1287
+ return null;
1288
+ }
1289
+ return generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields);
1290
+ }
1291
+ function getAttributesData(tile) {
1292
+ var _a, _b, _c, _d, _e;
1293
+ const attributeStorageInfo = (_b = (_a = tile.tileset) == null ? void 0 : _a.tileset) == null ? void 0 : _b.attributeStorageInfo;
1294
+ const attributeUrls = (_c = tile.header) == null ? void 0 : _c.attributeUrls;
1295
+ const tilesetFields = ((_e = (_d = tile.tileset) == null ? void 0 : _d.tileset) == null ? void 0 : _e.fields) || [];
1296
+ return { attributeStorageInfo, attributeUrls, tilesetFields };
1297
+ }
1298
+ function getAttributeValueType(attribute) {
1299
+ if (attribute.hasOwnProperty("objectIds")) {
1300
+ return "Oid32";
1301
+ } else if (attribute.hasOwnProperty("attributeValues")) {
1302
+ return attribute.attributeValues.valueType;
1303
+ }
1304
+ return "";
1305
+ }
1306
+ function getFeatureIdsAttributeName(attributeStorageInfo) {
1307
+ const objectIdsAttribute = attributeStorageInfo.find((attribute) => attribute.name.includes("OBJECTID"));
1308
+ return objectIdsAttribute == null ? void 0 : objectIdsAttribute.name;
1309
+ }
1310
+ function generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields) {
1311
+ const objectIdsAttributeName = getFeatureIdsAttributeName(attributeStorageInfo);
1312
+ const objectIds = attributes.find((attribute) => attribute.value[objectIdsAttributeName]);
1313
+ if (!objectIds) {
1314
+ return null;
1315
+ }
1316
+ const attributeIndex = objectIds.value[objectIdsAttributeName].indexOf(featureId);
1317
+ if (attributeIndex < 0) {
1318
+ return null;
1319
+ }
1320
+ return getFeatureAttributesByIndex(attributes, attributeIndex, attributeStorageInfo, tilesetFields);
1321
+ }
1322
+ function getFeatureAttributesByIndex(attributes, featureIdIndex, attributeStorageInfo, tilesetFields) {
1323
+ const attributesObject = {};
1324
+ for (let index = 0; index < attributeStorageInfo.length; index++) {
1325
+ const attributeName = attributeStorageInfo[index].name;
1326
+ const codedValues = getAttributeCodedValues(attributeName, tilesetFields);
1327
+ const attribute = getAttributeByIndexAndAttributeName(attributes, index, attributeName);
1328
+ attributesObject[attributeName] = formatAttributeValue(attribute, featureIdIndex, codedValues);
1329
+ }
1330
+ return attributesObject;
1331
+ }
1332
+ function getAttributeCodedValues(attributeName, tilesetFields) {
1333
+ var _a;
1334
+ const attributeField = tilesetFields.find((field) => field.name === attributeName || field.alias === attributeName);
1335
+ return ((_a = attributeField == null ? void 0 : attributeField.domain) == null ? void 0 : _a.codedValues) || [];
1336
+ }
1337
+ function getAttributeByIndexAndAttributeName(attributes, index, attributesName) {
1338
+ const attributeObject = attributes[index];
1339
+ if (attributeObject.status === REJECTED_STATUS) {
1340
+ return null;
1341
+ }
1342
+ return attributeObject.value[attributesName];
1343
+ }
1344
+ function formatAttributeValue(attribute, featureIdIndex, codedValues) {
1345
+ let value = EMPTY_VALUE;
1346
+ if (attribute && featureIdIndex in attribute) {
1347
+ value = String(attribute[featureIdIndex]).replace(/\u0000|NaN/g, "").trim();
1348
+ }
1349
+ if (codedValues.length) {
1350
+ const codeValue = codedValues.find((codedValue) => codedValue.code === Number(value));
1351
+ value = (codeValue == null ? void 0 : codeValue.name) || EMPTY_VALUE;
1352
+ }
1353
+ return value;
1354
+ }
1355
+
1456
1356
  // src/lib/parsers/parse-i3s-building-scene-layer.ts
1457
1357
  var OBJECT_3D_LAYER_TYPE = "3DObject";
1458
1358
  async function parseBuildingSceneLayer(data, url) {
@@ -1506,7 +1406,7 @@ async function parse4(data, options, context) {
1506
1406
  }
1507
1407
 
1508
1408
  // src/lib/parsers/parse-arcgis-webscene.ts
1509
- var import_core8 = require("@loaders.gl/core");
1409
+ var import_core7 = require("@loaders.gl/core");
1510
1410
  var SUPPORTED_WKID = 4326;
1511
1411
  var ARCGIS_SCENE_SERVER_LAYER_TYPE = "ArcGISSceneServiceLayer";
1512
1412
  var BUILDING_SCENE_LAYER = "BuildingSceneLayer";
@@ -1560,7 +1460,7 @@ async function parseOperationalLayers(layersList, needToCheckCRS) {
1560
1460
  async function checkSupportedIndexCRS(layer) {
1561
1461
  var _a;
1562
1462
  try {
1563
- const layerJson = await (0, import_core8.load)(layer.url, import_core8.JSONLoader);
1463
+ const layerJson = await (0, import_core7.load)(layer.url, import_core7.JSONLoader);
1564
1464
  const wkid = (_a = layerJson == null ? void 0 : layerJson.spatialReference) == null ? void 0 : _a.wkid;
1565
1465
  if (wkid !== SUPPORTED_WKID) {
1566
1466
  throw new Error(NOT_SUPPORTED_CRS_ERROR);
@@ -1585,3 +1485,90 @@ var ArcGISWebSceneLoader = {
1585
1485
  async function parse5(data) {
1586
1486
  return parseWebscene(data);
1587
1487
  }
1488
+
1489
+ // src/lib/utils/customize-colors.ts
1490
+ var import_core8 = require("@loaders.gl/core");
1491
+ async function customizeColors(colors, featureIds, attributeUrls, fields, attributeStorageInfo, colorsByAttribute, token) {
1492
+ if (!colorsByAttribute) {
1493
+ return colors;
1494
+ }
1495
+ const resultColors = {
1496
+ ...colors,
1497
+ value: new Uint8Array(colors.value)
1498
+ };
1499
+ const colorizeAttributeField = fields.find(({ name }) => name === (colorsByAttribute == null ? void 0 : colorsByAttribute.attributeName));
1500
+ if (!colorizeAttributeField || !["esriFieldTypeDouble", "esriFieldTypeInteger", "esriFieldTypeSmallInteger"].includes(
1501
+ colorizeAttributeField.type
1502
+ )) {
1503
+ return colors;
1504
+ }
1505
+ const colorizeAttributeData = await loadFeatureAttributeData(
1506
+ colorizeAttributeField.name,
1507
+ attributeUrls,
1508
+ attributeStorageInfo,
1509
+ token
1510
+ );
1511
+ if (!colorizeAttributeData) {
1512
+ return colors;
1513
+ }
1514
+ const objectIdField = fields.find(({ type }) => type === "esriFieldTypeOID");
1515
+ if (!objectIdField) {
1516
+ return colors;
1517
+ }
1518
+ const objectIdAttributeData = await loadFeatureAttributeData(
1519
+ objectIdField.name,
1520
+ attributeUrls,
1521
+ attributeStorageInfo,
1522
+ token
1523
+ );
1524
+ if (!objectIdAttributeData) {
1525
+ return colors;
1526
+ }
1527
+ const attributeValuesMap = {};
1528
+ for (let i = 0; i < objectIdAttributeData[objectIdField.name].length; i++) {
1529
+ attributeValuesMap[objectIdAttributeData[objectIdField.name][i]] = calculateColorForAttribute(
1530
+ // @ts-expect-error
1531
+ colorizeAttributeData[colorizeAttributeField.name][i],
1532
+ colorsByAttribute
1533
+ );
1534
+ }
1535
+ for (let i = 0; i < featureIds.length; i++) {
1536
+ const color = attributeValuesMap[featureIds[i]];
1537
+ if (!color) {
1538
+ continue;
1539
+ }
1540
+ if (colorsByAttribute.mode === "multiply") {
1541
+ color.forEach((colorItem, index) => {
1542
+ resultColors.value[i * 4 + index] = resultColors.value[i * 4 + index] * colorItem / 255;
1543
+ });
1544
+ } else {
1545
+ resultColors.value.set(color, i * 4);
1546
+ }
1547
+ }
1548
+ return resultColors;
1549
+ }
1550
+ function calculateColorForAttribute(attributeValue, colorsByAttribute) {
1551
+ if (!colorsByAttribute) {
1552
+ return [255, 255, 255, 255];
1553
+ }
1554
+ const { minValue, maxValue, minColor, maxColor } = colorsByAttribute;
1555
+ const rate = (attributeValue - minValue) / (maxValue - minValue);
1556
+ const color = [255, 255, 255, 255];
1557
+ for (let i = 0; i < minColor.length; i++) {
1558
+ color[i] = Math.round((maxColor[i] - minColor[i]) * rate + minColor[i]);
1559
+ }
1560
+ return color;
1561
+ }
1562
+ async function loadFeatureAttributeData(attributeName, attributeUrls, attributeStorageInfo, token) {
1563
+ const attributeIndex = attributeStorageInfo.findIndex(({ name }) => attributeName === name);
1564
+ if (attributeIndex === -1) {
1565
+ return null;
1566
+ }
1567
+ const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], token);
1568
+ const attributeType = getAttributeValueType(attributeStorageInfo[attributeIndex]);
1569
+ const objectIdAttributeData = await (0, import_core8.load)(objectIdAttributeUrl, I3SAttributeLoader, {
1570
+ attributeName,
1571
+ attributeType
1572
+ });
1573
+ return objectIdAttributeData;
1574
+ }