@loaders.gl/i3s 4.0.0-beta.6 → 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 (36) hide show
  1. package/LICENSE +7 -7
  2. package/dist/dist.dev.js +864 -1460
  3. package/dist/i3s-content-worker-node.js +55 -55
  4. package/dist/i3s-content-worker-node.js.map +4 -4
  5. package/dist/i3s-content-worker.js +33 -796
  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 +293 -316
  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 +1 -1
  16. package/dist/lib/parsers/constants.js.map +1 -1
  17. package/dist/lib/parsers/parse-i3s-attribute.d.ts.map +1 -1
  18. package/dist/lib/parsers/parse-i3s-attribute.js.map +1 -1
  19. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -1
  20. package/dist/lib/parsers/parse-i3s-tile-content.js +2 -4
  21. package/dist/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  22. package/dist/lib/utils/customize-colors.d.ts +30 -0
  23. package/dist/lib/utils/customize-colors.d.ts.map +1 -0
  24. package/dist/lib/utils/customize-colors.js +92 -0
  25. package/dist/lib/utils/customize-colors.js.map +1 -0
  26. package/package.json +11 -12
  27. package/src/i3s-loader.ts +1 -2
  28. package/src/index.ts +2 -0
  29. package/src/lib/parsers/constants.ts +4 -1
  30. package/src/lib/parsers/parse-i3s-attribute.ts +1 -0
  31. package/src/lib/parsers/parse-i3s-tile-content.ts +2 -11
  32. package/src/lib/utils/{customize-/321/201olors.ts → customize-colors.ts} +66 -41
  33. package/dist/lib/utils/customize-/321/201olors.d.ts +0 -14
  34. package/dist/lib/utils/customize-/321/201olors.d.ts.map +0 -1
  35. package/dist/lib/utils/customize-/321/201olors.js +0 -98
  36. package/dist/lib/utils/customize-/321/201olors.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -38,13 +28,14 @@ __export(src_exports, {
38
28
  I3SLoader: () => I3SLoader,
39
29
  I3SNodePageLoader: () => I3SNodePageLoader,
40
30
  SLPKLoader: () => SLPKLoader,
31
+ customizeColors: () => customizeColors,
41
32
  loadFeatureAttributes: () => loadFeatureAttributes,
42
33
  parseSLPKArchive: () => parseSLPKArchive
43
34
  });
44
35
  module.exports = __toCommonJS(src_exports);
45
36
 
46
37
  // src/lib/parsers/constants.ts
47
- var import_constants = __toESM(require("@luma.gl/constants"), 1);
38
+ var import_math = require("@loaders.gl/math");
48
39
  function getConstructorForDataFormat(dataType) {
49
40
  switch (dataType) {
50
41
  case "UInt8":
@@ -62,11 +53,11 @@ function getConstructorForDataFormat(dataType) {
62
53
  }
63
54
  }
64
55
  var GL_TYPE_MAP = {
65
- UInt8: import_constants.default.UNSIGNED_BYTE,
66
- UInt16: import_constants.default.UNSIGNED_SHORT,
67
- Float32: import_constants.default.FLOAT,
68
- UInt32: import_constants.default.UNSIGNED_INT,
69
- UInt64: import_constants.default.DOUBLE
56
+ UInt8: import_math.GL.UNSIGNED_BYTE,
57
+ UInt16: import_math.GL.UNSIGNED_SHORT,
58
+ Float32: import_math.GL.FLOAT,
59
+ UInt32: import_math.GL.UNSIGNED_INT,
60
+ UInt64: import_math.GL.DOUBLE
70
61
  };
71
62
  function sizeOf(dataType) {
72
63
  switch (dataType) {
@@ -101,11 +92,11 @@ var COORDINATE_SYSTEM = /* @__PURE__ */ ((COORDINATE_SYSTEM2) => {
101
92
  })(COORDINATE_SYSTEM || {});
102
93
 
103
94
  // src/i3s-loader.ts
104
- var import_core7 = require("@loaders.gl/core");
95
+ var import_core5 = require("@loaders.gl/core");
105
96
 
106
97
  // src/lib/parsers/parse-i3s-tile-content.ts
107
- var import_core3 = require("@loaders.gl/core");
108
- var import_core4 = require("@math.gl/core");
98
+ var import_core = require("@loaders.gl/core");
99
+ var import_core2 = require("@math.gl/core");
109
100
  var import_geospatial = require("@math.gl/geospatial");
110
101
  var import_loader_utils = require("@loaders.gl/loader-utils");
111
102
  var import_images = require("@loaders.gl/images");
@@ -144,270 +135,8 @@ function generateTilesetAttributeUrls(tileset, url, resource) {
144
135
  return attributeUrls;
145
136
  }
146
137
 
147
- // src/lib/utils/customize-сolors.ts
148
- var import_core2 = require("@loaders.gl/core");
149
-
150
- // src/i3s-attribute-loader.ts
151
- var import_core = require("@loaders.gl/core");
152
-
153
- // src/lib/parsers/parse-i3s-attribute.ts
154
- function parseI3STileAttribute(arrayBuffer, options) {
155
- const { attributeName, attributeType } = options;
156
- if (!attributeName) {
157
- return {};
158
- }
159
- return {
160
- [attributeName]: attributeType ? parseAttribute(attributeType, arrayBuffer) : null
161
- };
162
- }
163
- function parseAttribute(attributeType, arrayBuffer) {
164
- switch (attributeType) {
165
- case STRING_ATTRIBUTE_TYPE:
166
- return parseStringsAttribute(arrayBuffer);
167
- case OBJECT_ID_ATTRIBUTE_TYPE:
168
- return parseShortNumberAttribute(arrayBuffer);
169
- case FLOAT_64_TYPE:
170
- return parseFloatAttribute(arrayBuffer);
171
- case INT_16_ATTRIBUTE_TYPE:
172
- return parseInt16ShortNumberAttribute(arrayBuffer);
173
- default:
174
- return parseShortNumberAttribute(arrayBuffer);
175
- }
176
- }
177
- function parseShortNumberAttribute(arrayBuffer) {
178
- const countOffset = 4;
179
- return new Uint32Array(arrayBuffer, countOffset);
180
- }
181
- function parseInt16ShortNumberAttribute(arrayBuffer) {
182
- const countOffset = 4;
183
- return new Int16Array(arrayBuffer, countOffset);
184
- }
185
- function parseFloatAttribute(arrayBuffer) {
186
- const countOffset = 8;
187
- return new Float64Array(arrayBuffer, countOffset);
188
- }
189
- function parseStringsAttribute(arrayBuffer) {
190
- const stringsCountOffset = 0;
191
- const dataOffset = 8;
192
- const bytesPerStringSize = 4;
193
- const stringsArray = [];
194
- try {
195
- const stringsCount = new DataView(
196
- arrayBuffer,
197
- stringsCountOffset,
198
- bytesPerStringSize
199
- ).getUint32(stringsCountOffset, true);
200
- const stringSizes = new Uint32Array(arrayBuffer, dataOffset, stringsCount);
201
- let stringOffset = dataOffset + stringsCount * bytesPerStringSize;
202
- for (const stringByteSize of stringSizes) {
203
- const textDecoder = new TextDecoder("utf-8");
204
- const stringAttribute = new Uint8Array(arrayBuffer, stringOffset, stringByteSize);
205
- stringsArray.push(textDecoder.decode(stringAttribute));
206
- stringOffset += stringByteSize;
207
- }
208
- } catch (error) {
209
- console.error("Parse string attribute error: ", error.message);
210
- }
211
- return stringsArray;
212
- }
213
-
214
- // src/i3s-attribute-loader.ts
215
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
216
- var EMPTY_VALUE = "";
217
- var REJECTED_STATUS = "rejected";
218
- var I3SAttributeLoader = {
219
- name: "I3S Attribute",
220
- id: "i3s-attribute",
221
- module: "i3s",
222
- version: VERSION,
223
- mimeTypes: ["application/binary"],
224
- parse: async (arrayBuffer, options) => parseI3STileAttribute(arrayBuffer, options),
225
- extensions: ["bin"],
226
- options: {},
227
- binary: true
228
- };
229
- async function loadFeatureAttributes(tile, featureId, options = {}) {
230
- var _a;
231
- const { attributeStorageInfo, attributeUrls, tilesetFields } = getAttributesData(tile);
232
- if (!attributeStorageInfo || !attributeUrls || featureId < 0) {
233
- return null;
234
- }
235
- let attributes = [];
236
- const attributeLoadPromises = [];
237
- for (let index = 0; index < attributeStorageInfo.length; index++) {
238
- const url = getUrlWithToken(attributeUrls[index], (_a = options.i3s) == null ? void 0 : _a.token);
239
- const attributeName = attributeStorageInfo[index].name;
240
- const attributeType = getAttributeValueType(attributeStorageInfo[index]);
241
- const loadOptions = { ...options, attributeName, attributeType };
242
- const promise = (0, import_core.load)(url, I3SAttributeLoader, loadOptions);
243
- attributeLoadPromises.push(promise);
244
- }
245
- try {
246
- attributes = await Promise.allSettled(attributeLoadPromises);
247
- } catch (error) {
248
- }
249
- if (!attributes.length) {
250
- return null;
251
- }
252
- return generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields);
253
- }
254
- function getAttributesData(tile) {
255
- var _a, _b, _c, _d, _e;
256
- const attributeStorageInfo = (_b = (_a = tile.tileset) == null ? void 0 : _a.tileset) == null ? void 0 : _b.attributeStorageInfo;
257
- const attributeUrls = (_c = tile.header) == null ? void 0 : _c.attributeUrls;
258
- const tilesetFields = ((_e = (_d = tile.tileset) == null ? void 0 : _d.tileset) == null ? void 0 : _e.fields) || [];
259
- return { attributeStorageInfo, attributeUrls, tilesetFields };
260
- }
261
- function getAttributeValueType(attribute) {
262
- if (attribute.hasOwnProperty("objectIds")) {
263
- return "Oid32";
264
- } else if (attribute.hasOwnProperty("attributeValues")) {
265
- return attribute.attributeValues.valueType;
266
- }
267
- return "";
268
- }
269
- function getFeatureIdsAttributeName(attributeStorageInfo) {
270
- const objectIdsAttribute = attributeStorageInfo.find((attribute) => attribute.name.includes("OBJECTID"));
271
- return objectIdsAttribute == null ? void 0 : objectIdsAttribute.name;
272
- }
273
- function generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields) {
274
- const objectIdsAttributeName = getFeatureIdsAttributeName(attributeStorageInfo);
275
- const objectIds = attributes.find((attribute) => attribute.value[objectIdsAttributeName]);
276
- if (!objectIds) {
277
- return null;
278
- }
279
- const attributeIndex = objectIds.value[objectIdsAttributeName].indexOf(featureId);
280
- if (attributeIndex < 0) {
281
- return null;
282
- }
283
- return getFeatureAttributesByIndex(attributes, attributeIndex, attributeStorageInfo, tilesetFields);
284
- }
285
- function getFeatureAttributesByIndex(attributes, featureIdIndex, attributeStorageInfo, tilesetFields) {
286
- const attributesObject = {};
287
- for (let index = 0; index < attributeStorageInfo.length; index++) {
288
- const attributeName = attributeStorageInfo[index].name;
289
- const codedValues = getAttributeCodedValues(attributeName, tilesetFields);
290
- const attribute = getAttributeByIndexAndAttributeName(attributes, index, attributeName);
291
- attributesObject[attributeName] = formatAttributeValue(attribute, featureIdIndex, codedValues);
292
- }
293
- return attributesObject;
294
- }
295
- function getAttributeCodedValues(attributeName, tilesetFields) {
296
- var _a;
297
- const attributeField = tilesetFields.find((field) => field.name === attributeName || field.alias === attributeName);
298
- return ((_a = attributeField == null ? void 0 : attributeField.domain) == null ? void 0 : _a.codedValues) || [];
299
- }
300
- function getAttributeByIndexAndAttributeName(attributes, index, attributesName) {
301
- const attributeObject = attributes[index];
302
- if (attributeObject.status === REJECTED_STATUS) {
303
- return null;
304
- }
305
- return attributeObject.value[attributesName];
306
- }
307
- function formatAttributeValue(attribute, featureIdIndex, codedValues) {
308
- let value = EMPTY_VALUE;
309
- if (attribute && featureIdIndex in attribute) {
310
- value = String(attribute[featureIdIndex]).replace(/\u0000|NaN/g, "").trim();
311
- }
312
- if (codedValues.length) {
313
- const codeValue = codedValues.find((codedValue) => codedValue.code === Number(value));
314
- value = (codeValue == null ? void 0 : codeValue.name) || EMPTY_VALUE;
315
- }
316
- return value;
317
- }
318
-
319
- // src/lib/utils/customize-сolors.ts
320
- async function customizeColors(colors, featureIds, tileOptions, tilesetOptions, options) {
321
- var _a;
322
- if (!((_a = options == null ? void 0 : options.i3s) == null ? void 0 : _a.colorsByAttribute)) {
323
- return colors;
324
- }
325
- const colorizeAttributeField = tilesetOptions.fields.find(
326
- ({ name }) => {
327
- var _a2, _b;
328
- return name === ((_b = (_a2 = options == null ? void 0 : options.i3s) == null ? void 0 : _a2.colorsByAttribute) == null ? void 0 : _b.attributeName);
329
- }
330
- );
331
- if (!colorizeAttributeField || !["esriFieldTypeDouble", "esriFieldTypeInteger", "esriFieldTypeSmallInteger"].includes(
332
- colorizeAttributeField.type
333
- )) {
334
- return colors;
335
- }
336
- const colorizeAttributeData = await loadFeatureAttributeData(
337
- colorizeAttributeField.name,
338
- tileOptions,
339
- tilesetOptions,
340
- options
341
- );
342
- if (!colorizeAttributeData) {
343
- return colors;
344
- }
345
- const objectIdField = tilesetOptions.fields.find(({ type }) => type === "esriFieldTypeOID");
346
- if (!objectIdField) {
347
- return colors;
348
- }
349
- const objectIdAttributeData = await loadFeatureAttributeData(
350
- objectIdField.name,
351
- tileOptions,
352
- tilesetOptions,
353
- options
354
- );
355
- if (!objectIdAttributeData) {
356
- return colors;
357
- }
358
- const attributeValuesMap = {};
359
- for (let i = 0; i < objectIdAttributeData[objectIdField.name].length; i++) {
360
- attributeValuesMap[objectIdAttributeData[objectIdField.name][i]] = calculateColorForAttribute(
361
- // @ts-expect-error
362
- colorizeAttributeData[colorizeAttributeField.name][i],
363
- options
364
- );
365
- }
366
- for (let i = 0; i < featureIds.value.length; i++) {
367
- const color = attributeValuesMap[featureIds.value[i]];
368
- if (!color) {
369
- continue;
370
- }
371
- if (options.i3s.colorsByAttribute.mode === "multiply") {
372
- color.forEach((colorItem, index) => {
373
- colors.value[i * 4 + index] = colors.value[i * 4 + index] * colorItem / 255;
374
- });
375
- } else {
376
- colors.value.set(color, i * 4);
377
- }
378
- }
379
- return colors;
380
- }
381
- function calculateColorForAttribute(attributeValue, options) {
382
- var _a;
383
- if (!((_a = options == null ? void 0 : options.i3s) == null ? void 0 : _a.colorsByAttribute)) {
384
- return [255, 255, 255, 255];
385
- }
386
- const { minValue, maxValue, minColor, maxColor } = options.i3s.colorsByAttribute;
387
- const rate = (attributeValue - minValue) / (maxValue - minValue);
388
- const color = [255, 255, 255, 255];
389
- for (let i = 0; i < minColor.length; i++) {
390
- color[i] = Math.round((maxColor[i] - minColor[i]) * rate + minColor[i]);
391
- }
392
- return color;
393
- }
394
- async function loadFeatureAttributeData(attributeName, { attributeUrls }, { attributeStorageInfo }, options) {
395
- var _a;
396
- const attributeIndex = attributeStorageInfo.findIndex(({ name }) => attributeName === name);
397
- if (attributeIndex === -1) {
398
- return null;
399
- }
400
- const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], (_a = options == null ? void 0 : options.i3s) == null ? void 0 : _a.token);
401
- const attributeType = getAttributeValueType(attributeStorageInfo[attributeIndex]);
402
- const objectIdAttributeData = await (0, import_core2.load)(objectIdAttributeUrl, I3SAttributeLoader, {
403
- attributeName,
404
- attributeType
405
- });
406
- return objectIdAttributeData;
407
- }
408
-
409
138
  // src/lib/parsers/parse-i3s-tile-content.ts
410
- var scratchVector = new import_core4.Vector3([0, 0, 0]);
139
+ var scratchVector = new import_core2.Vector3([0, 0, 0]);
411
140
  function getLoaderForTextureFormat(textureFormat) {
412
141
  switch (textureFormat) {
413
142
  case "ktx-etc2":
@@ -429,7 +158,7 @@ async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, opt
429
158
  indices: null,
430
159
  featureIds: [],
431
160
  vertexCount: 0,
432
- modelMatrix: new import_core4.Matrix4(),
161
+ modelMatrix: new import_core2.Matrix4(),
433
162
  coordinateSystem: 0,
434
163
  byteLength: 0,
435
164
  texture: null
@@ -437,8 +166,8 @@ async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, opt
437
166
  if (tileOptions.textureUrl) {
438
167
  const url = getUrlWithToken(tileOptions.textureUrl, (_a = options == null ? void 0 : options.i3s) == null ? void 0 : _a.token);
439
168
  const loader = getLoaderForTextureFormat(tileOptions.textureFormat);
440
- const fetch = context == null ? void 0 : context.fetch;
441
- const response = await fetch(url);
169
+ const fetchFunc = (context == null ? void 0 : context.fetch) || fetch;
170
+ const response = await fetchFunc(url);
442
171
  const arrayBuffer2 = await response.arrayBuffer();
443
172
  if (options == null ? void 0 : options.i3s.decodeTextures) {
444
173
  if (loader === import_images.ImageLoader) {
@@ -447,11 +176,11 @@ async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, opt
447
176
  const texture = await (0, import_loader_utils.parseFromContext)(arrayBuffer2, [], options2, context);
448
177
  content.texture = texture;
449
178
  } catch (e) {
450
- const texture = await (0, import_core3.parse)(arrayBuffer2, loader, options2, context);
179
+ const texture = await (0, import_core.parse)(arrayBuffer2, loader, options2, context);
451
180
  content.texture = texture;
452
181
  }
453
182
  } else if (loader === import_textures.CompressedTextureLoader || loader === import_textures.BasisLoader) {
454
- let texture = await (0, import_core3.load)(arrayBuffer2, loader, tileOptions.textureLoaderOptions);
183
+ let texture = await (0, import_core.load)(arrayBuffer2, loader, tileOptions.textureLoaderOptions);
455
184
  if (loader === import_textures.BasisLoader) {
456
185
  texture = texture[0];
457
186
  }
@@ -482,7 +211,7 @@ async function parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOp
482
211
  let featureCount = 0;
483
212
  let indices;
484
213
  if (tileOptions.isDracoGeometry) {
485
- const decompressedGeometry = await (0, import_core3.parse)(arrayBuffer, import_draco.DracoLoader, {
214
+ const decompressedGeometry = await (0, import_core.parse)(arrayBuffer, import_draco.DracoLoader, {
486
215
  draco: {
487
216
  attributeNameEntry: I3S_ATTRIBUTE_TYPE
488
217
  }
@@ -546,13 +275,6 @@ async function parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOp
546
275
  content.modelMatrix = getModelMatrix(attributes.position);
547
276
  content.coordinateSystem = 3 /* LNGLAT_OFFSETS */;
548
277
  }
549
- attributes.color = await customizeColors(
550
- attributes.color,
551
- attributes.id,
552
- tileOptions,
553
- tilesetOptions,
554
- options
555
- );
556
278
  content.attributes = {
557
279
  positions: attributes.position,
558
280
  normals: attributes.normal,
@@ -678,9 +400,9 @@ function parsePositions(attribute, options) {
678
400
  const mbs = options.mbs;
679
401
  const value = attribute.value;
680
402
  const metadata = attribute.metadata;
681
- const enuMatrix = new import_core4.Matrix4();
682
- const cartographicOrigin = new import_core4.Vector3(mbs[0], mbs[1], mbs[2]);
683
- 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();
684
406
  import_geospatial.Ellipsoid.WGS84.cartographicToCartesian(cartographicOrigin, cartesianOrigin);
685
407
  import_geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
686
408
  attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
@@ -708,7 +430,7 @@ function getModelMatrix(positions) {
708
430
  const metadata = positions.metadata;
709
431
  const scaleX = ((_a = metadata == null ? void 0 : metadata["i3s-scale_x"]) == null ? void 0 : _a.double) || 1;
710
432
  const scaleY = ((_b = metadata == null ? void 0 : metadata["i3s-scale_y"]) == null ? void 0 : _b.double) || 1;
711
- const modelMatrix = new import_core4.Matrix4();
433
+ const modelMatrix = new import_core2.Matrix4();
712
434
  modelMatrix[0] = scaleX;
713
435
  modelMatrix[5] = scaleY;
714
436
  return modelMatrix;
@@ -811,13 +533,13 @@ function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
811
533
  }
812
534
 
813
535
  // src/i3s-content-loader.ts
814
- var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
536
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
815
537
  var I3SContentLoader = {
816
538
  name: "I3S Content (Indexed Scene Layers)",
817
539
  id: "i3s-content",
818
540
  module: "i3s",
819
541
  worker: true,
820
- version: VERSION2,
542
+ version: VERSION,
821
543
  mimeTypes: ["application/octet-stream"],
822
544
  parse: parse2,
823
545
  extensions: ["bin"],
@@ -844,20 +566,20 @@ async function parse2(data, options, context) {
844
566
  // src/lib/parsers/parse-i3s.ts
845
567
  var import_culling = require("@math.gl/culling");
846
568
  var import_geospatial2 = require("@math.gl/geospatial");
847
- var import_core6 = require("@loaders.gl/core");
569
+ var import_core4 = require("@loaders.gl/core");
848
570
  var import_tiles = require("@loaders.gl/tiles");
849
571
 
850
572
  // src/lib/helpers/i3s-nodepages-tiles.ts
851
- var import_core5 = require("@loaders.gl/core");
573
+ var import_core3 = require("@loaders.gl/core");
852
574
  var import_textures2 = require("@loaders.gl/textures");
853
575
 
854
576
  // src/i3s-node-page-loader.ts
855
- var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
577
+ var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
856
578
  var I3SNodePageLoader = {
857
579
  name: "I3S Node Page",
858
580
  id: "i3s-node-page",
859
581
  module: "i3s",
860
- version: VERSION3,
582
+ version: VERSION2,
861
583
  mimeTypes: ["application/json"],
862
584
  parse: parseNodePage,
863
585
  extensions: ["json"],
@@ -907,7 +629,7 @@ var I3SNodePagesTiles = class {
907
629
  );
908
630
  this.pendingNodePages[pageIndex] = {
909
631
  status: "Pending",
910
- promise: (0, import_core5.load)(nodePageUrl, I3SNodePageLoader, this.options)
632
+ promise: (0, import_core3.load)(nodePageUrl, I3SNodePageLoader, this.options)
911
633
  };
912
634
  this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;
913
635
  this.nodesInNodePages += this.nodePages[pageIndex].nodes.length;
@@ -1178,7 +900,7 @@ async function normalizeTilesetData(tileset, options, context) {
1178
900
  } else {
1179
901
  const parseOptions = options.i3s;
1180
902
  const rootNodeUrl = getUrlWithToken(`${url}/nodes/root`, parseOptions.token);
1181
- root = await (0, import_core6.load)(rootNodeUrl, I3SLoader, {
903
+ root = await (0, import_core4.load)(rootNodeUrl, I3SLoader, {
1182
904
  ...options,
1183
905
  i3s: {
1184
906
  // @ts-expect-error options is not properly typed
@@ -1204,7 +926,7 @@ async function normalizeTilesetData(tileset, options, context) {
1204
926
  }
1205
927
 
1206
928
  // src/i3s-loader.ts
1207
- var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
929
+ var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1208
930
  var TILESET_REGEX = /layers\/[0-9]+$/;
1209
931
  var TILE_HEADER_REGEX = /nodes\/([0-9-]+|root)$/;
1210
932
  var SLPK_HEX = "504b0304";
@@ -1213,7 +935,7 @@ var I3SLoader = {
1213
935
  name: "I3S (Indexed Scene Layers)",
1214
936
  id: "i3s",
1215
937
  module: "i3s",
1216
- version: VERSION4,
938
+ version: VERSION3,
1217
939
  mimeTypes: ["application/octet-stream"],
1218
940
  parse: parseI3S,
1219
941
  extensions: ["bin"],
@@ -1229,8 +951,7 @@ var I3SLoader = {
1229
951
  useDracoGeometry: true,
1230
952
  useCompressedTextures: true,
1231
953
  decodeTextures: true,
1232
- coordinateSystem: 2 /* METER_OFFSETS */,
1233
- colorsByAttribute: null
954
+ coordinateSystem: 2 /* METER_OFFSETS */
1234
955
  }
1235
956
  }
1236
957
  };
@@ -1264,7 +985,7 @@ async function parseI3S(data, options = {}, context) {
1264
985
  return data;
1265
986
  }
1266
987
  async function parseTileContent(arrayBuffer, options) {
1267
- return await (0, import_core7.parse)(arrayBuffer, I3SContentLoader, options);
988
+ return await (0, import_core5.parse)(arrayBuffer, I3SContentLoader, options);
1268
989
  }
1269
990
  async function parseTileset(data, options, context) {
1270
991
  const tilesetJson = JSON.parse(new TextDecoder().decode(data));
@@ -1447,12 +1168,12 @@ async function parseSLPKArchive(fileProvider, cb) {
1447
1168
  }
1448
1169
 
1449
1170
  // src/i3s-slpk-loader.ts
1450
- var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1171
+ var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1451
1172
  var SLPKLoader = {
1452
1173
  name: "I3S SLPK (Scene Layer Package)",
1453
1174
  id: "slpk",
1454
1175
  module: "i3s",
1455
- version: VERSION5,
1176
+ version: VERSION4,
1456
1177
  mimeTypes: ["application/octet-stream"],
1457
1178
  extensions: ["slpk"],
1458
1179
  options: {},
@@ -1463,6 +1184,175 @@ var SLPKLoader = {
1463
1184
  }
1464
1185
  };
1465
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
+
1466
1356
  // src/lib/parsers/parse-i3s-building-scene-layer.ts
1467
1357
  var OBJECT_3D_LAYER_TYPE = "3DObject";
1468
1358
  async function parseBuildingSceneLayer(data, url) {
@@ -1516,7 +1406,7 @@ async function parse4(data, options, context) {
1516
1406
  }
1517
1407
 
1518
1408
  // src/lib/parsers/parse-arcgis-webscene.ts
1519
- var import_core8 = require("@loaders.gl/core");
1409
+ var import_core7 = require("@loaders.gl/core");
1520
1410
  var SUPPORTED_WKID = 4326;
1521
1411
  var ARCGIS_SCENE_SERVER_LAYER_TYPE = "ArcGISSceneServiceLayer";
1522
1412
  var BUILDING_SCENE_LAYER = "BuildingSceneLayer";
@@ -1570,7 +1460,7 @@ async function parseOperationalLayers(layersList, needToCheckCRS) {
1570
1460
  async function checkSupportedIndexCRS(layer) {
1571
1461
  var _a;
1572
1462
  try {
1573
- 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);
1574
1464
  const wkid = (_a = layerJson == null ? void 0 : layerJson.spatialReference) == null ? void 0 : _a.wkid;
1575
1465
  if (wkid !== SUPPORTED_WKID) {
1576
1466
  throw new Error(NOT_SUPPORTED_CRS_ERROR);
@@ -1595,3 +1485,90 @@ var ArcGISWebSceneLoader = {
1595
1485
  async function parse5(data) {
1596
1486
  return parseWebscene(data);
1597
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
+ }