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

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/dist.dev.js CHANGED
@@ -4270,6 +4270,7 @@ var __exports__ = (() => {
4270
4270
  I3SLoader: () => I3SLoader,
4271
4271
  I3SNodePageLoader: () => I3SNodePageLoader,
4272
4272
  SLPKLoader: () => SLPKLoader,
4273
+ customizeColors: () => customizeColors,
4273
4274
  loadFeatureAttributes: () => loadFeatureAttributes,
4274
4275
  parseSLPKArchive: () => parseSLPKArchive
4275
4276
  });
@@ -8747,10 +8748,10 @@ var __exports__ = (() => {
8747
8748
  }({});
8748
8749
 
8749
8750
  // src/i3s-loader.ts
8750
- var import_core20 = __toESM(require_core(), 1);
8751
+ var import_core18 = __toESM(require_core(), 1);
8751
8752
 
8752
8753
  // src/lib/parsers/parse-i3s-tile-content.ts
8753
- var import_core7 = __toESM(require_core(), 1);
8754
+ var import_core5 = __toESM(require_core(), 1);
8754
8755
 
8755
8756
  // ../../node_modules/@math.gl/geospatial/dist/constants.js
8756
8757
  var WGS84_RADIUS_X = 6378137;
@@ -11052,267 +11053,6 @@ var __exports__ = (() => {
11052
11053
  return attributeUrls;
11053
11054
  }
11054
11055
 
11055
- // src/lib/utils/customize-сolors.ts
11056
- var import_core6 = __toESM(require_core(), 1);
11057
-
11058
- // src/i3s-attribute-loader.ts
11059
- var import_core5 = __toESM(require_core(), 1);
11060
-
11061
- // src/lib/parsers/parse-i3s-attribute.ts
11062
- function parseI3STileAttribute(arrayBuffer, options) {
11063
- const {
11064
- attributeName,
11065
- attributeType
11066
- } = options;
11067
- if (!attributeName) {
11068
- return {};
11069
- }
11070
- return {
11071
- [attributeName]: attributeType ? parseAttribute(attributeType, arrayBuffer) : null
11072
- };
11073
- }
11074
- function parseAttribute(attributeType, arrayBuffer) {
11075
- switch (attributeType) {
11076
- case STRING_ATTRIBUTE_TYPE:
11077
- return parseStringsAttribute(arrayBuffer);
11078
- case OBJECT_ID_ATTRIBUTE_TYPE:
11079
- return parseShortNumberAttribute(arrayBuffer);
11080
- case FLOAT_64_TYPE:
11081
- return parseFloatAttribute(arrayBuffer);
11082
- case INT_16_ATTRIBUTE_TYPE:
11083
- return parseInt16ShortNumberAttribute(arrayBuffer);
11084
- default:
11085
- return parseShortNumberAttribute(arrayBuffer);
11086
- }
11087
- }
11088
- function parseShortNumberAttribute(arrayBuffer) {
11089
- const countOffset = 4;
11090
- return new Uint32Array(arrayBuffer, countOffset);
11091
- }
11092
- function parseInt16ShortNumberAttribute(arrayBuffer) {
11093
- const countOffset = 4;
11094
- return new Int16Array(arrayBuffer, countOffset);
11095
- }
11096
- function parseFloatAttribute(arrayBuffer) {
11097
- const countOffset = 8;
11098
- return new Float64Array(arrayBuffer, countOffset);
11099
- }
11100
- function parseStringsAttribute(arrayBuffer) {
11101
- const stringsCountOffset = 0;
11102
- const dataOffset = 8;
11103
- const bytesPerStringSize = 4;
11104
- const stringsArray = [];
11105
- try {
11106
- const stringsCount = new DataView(arrayBuffer, stringsCountOffset, bytesPerStringSize).getUint32(stringsCountOffset, true);
11107
- const stringSizes = new Uint32Array(arrayBuffer, dataOffset, stringsCount);
11108
- let stringOffset = dataOffset + stringsCount * bytesPerStringSize;
11109
- for (const stringByteSize of stringSizes) {
11110
- const textDecoder = new TextDecoder("utf-8");
11111
- const stringAttribute = new Uint8Array(arrayBuffer, stringOffset, stringByteSize);
11112
- stringsArray.push(textDecoder.decode(stringAttribute));
11113
- stringOffset += stringByteSize;
11114
- }
11115
- } catch (error) {
11116
- console.error("Parse string attribute error: ", error.message);
11117
- }
11118
- return stringsArray;
11119
- }
11120
-
11121
- // src/i3s-attribute-loader.ts
11122
- var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
11123
- var EMPTY_VALUE = "";
11124
- var REJECTED_STATUS = "rejected";
11125
- var I3SAttributeLoader = {
11126
- name: "I3S Attribute",
11127
- id: "i3s-attribute",
11128
- module: "i3s",
11129
- version: VERSION5,
11130
- mimeTypes: ["application/binary"],
11131
- parse: async (arrayBuffer, options) => parseI3STileAttribute(arrayBuffer, options),
11132
- extensions: ["bin"],
11133
- options: {},
11134
- binary: true
11135
- };
11136
- async function loadFeatureAttributes(tile, featureId, options = {}) {
11137
- const {
11138
- attributeStorageInfo,
11139
- attributeUrls,
11140
- tilesetFields
11141
- } = getAttributesData(tile);
11142
- if (!attributeStorageInfo || !attributeUrls || featureId < 0) {
11143
- return null;
11144
- }
11145
- let attributes = [];
11146
- const attributeLoadPromises = [];
11147
- for (let index = 0; index < attributeStorageInfo.length; index++) {
11148
- const url = getUrlWithToken(attributeUrls[index], options.i3s?.token);
11149
- const attributeName = attributeStorageInfo[index].name;
11150
- const attributeType = getAttributeValueType(attributeStorageInfo[index]);
11151
- const loadOptions = {
11152
- ...options,
11153
- attributeName,
11154
- attributeType
11155
- };
11156
- const promise = (0, import_core5.load)(url, I3SAttributeLoader, loadOptions);
11157
- attributeLoadPromises.push(promise);
11158
- }
11159
- try {
11160
- attributes = await Promise.allSettled(attributeLoadPromises);
11161
- } catch (error) {
11162
- }
11163
- if (!attributes.length) {
11164
- return null;
11165
- }
11166
- return generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields);
11167
- }
11168
- function getAttributesData(tile) {
11169
- const attributeStorageInfo = tile.tileset?.tileset?.attributeStorageInfo;
11170
- const attributeUrls = tile.header?.attributeUrls;
11171
- const tilesetFields = tile.tileset?.tileset?.fields || [];
11172
- return {
11173
- attributeStorageInfo,
11174
- attributeUrls,
11175
- tilesetFields
11176
- };
11177
- }
11178
- function getAttributeValueType(attribute) {
11179
- if (attribute.hasOwnProperty("objectIds")) {
11180
- return "Oid32";
11181
- } else if (attribute.hasOwnProperty("attributeValues")) {
11182
- return attribute.attributeValues.valueType;
11183
- }
11184
- return "";
11185
- }
11186
- function getFeatureIdsAttributeName(attributeStorageInfo) {
11187
- const objectIdsAttribute = attributeStorageInfo.find((attribute) => attribute.name.includes("OBJECTID"));
11188
- return objectIdsAttribute?.name;
11189
- }
11190
- function generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields) {
11191
- const objectIdsAttributeName = getFeatureIdsAttributeName(attributeStorageInfo);
11192
- const objectIds = attributes.find((attribute) => attribute.value[objectIdsAttributeName]);
11193
- if (!objectIds) {
11194
- return null;
11195
- }
11196
- const attributeIndex = objectIds.value[objectIdsAttributeName].indexOf(featureId);
11197
- if (attributeIndex < 0) {
11198
- return null;
11199
- }
11200
- return getFeatureAttributesByIndex(attributes, attributeIndex, attributeStorageInfo, tilesetFields);
11201
- }
11202
- function getFeatureAttributesByIndex(attributes, featureIdIndex, attributeStorageInfo, tilesetFields) {
11203
- const attributesObject = {};
11204
- for (let index = 0; index < attributeStorageInfo.length; index++) {
11205
- const attributeName = attributeStorageInfo[index].name;
11206
- const codedValues = getAttributeCodedValues(attributeName, tilesetFields);
11207
- const attribute = getAttributeByIndexAndAttributeName(attributes, index, attributeName);
11208
- attributesObject[attributeName] = formatAttributeValue(attribute, featureIdIndex, codedValues);
11209
- }
11210
- return attributesObject;
11211
- }
11212
- function getAttributeCodedValues(attributeName, tilesetFields) {
11213
- const attributeField = tilesetFields.find((field) => field.name === attributeName || field.alias === attributeName);
11214
- return attributeField?.domain?.codedValues || [];
11215
- }
11216
- function getAttributeByIndexAndAttributeName(attributes, index, attributesName) {
11217
- const attributeObject = attributes[index];
11218
- if (attributeObject.status === REJECTED_STATUS) {
11219
- return null;
11220
- }
11221
- return attributeObject.value[attributesName];
11222
- }
11223
- function formatAttributeValue(attribute, featureIdIndex, codedValues) {
11224
- let value = EMPTY_VALUE;
11225
- if (attribute && featureIdIndex in attribute) {
11226
- value = String(attribute[featureIdIndex]).replace(/\u0000|NaN/g, "").trim();
11227
- }
11228
- if (codedValues.length) {
11229
- const codeValue = codedValues.find((codedValue) => codedValue.code === Number(value));
11230
- value = codeValue?.name || EMPTY_VALUE;
11231
- }
11232
- return value;
11233
- }
11234
-
11235
- // src/lib/utils/customize-сolors.ts
11236
- async function customizeColors(colors, featureIds, tileOptions, tilesetOptions, options) {
11237
- if (!options?.i3s?.colorsByAttribute) {
11238
- return colors;
11239
- }
11240
- const colorizeAttributeField = tilesetOptions.fields.find(({
11241
- name
11242
- }) => name === options?.i3s?.colorsByAttribute?.attributeName);
11243
- if (!colorizeAttributeField || !["esriFieldTypeDouble", "esriFieldTypeInteger", "esriFieldTypeSmallInteger"].includes(colorizeAttributeField.type)) {
11244
- return colors;
11245
- }
11246
- const colorizeAttributeData = await loadFeatureAttributeData(colorizeAttributeField.name, tileOptions, tilesetOptions, options);
11247
- if (!colorizeAttributeData) {
11248
- return colors;
11249
- }
11250
- const objectIdField = tilesetOptions.fields.find(({
11251
- type
11252
- }) => type === "esriFieldTypeOID");
11253
- if (!objectIdField) {
11254
- return colors;
11255
- }
11256
- const objectIdAttributeData = await loadFeatureAttributeData(objectIdField.name, tileOptions, tilesetOptions, options);
11257
- if (!objectIdAttributeData) {
11258
- return colors;
11259
- }
11260
- const attributeValuesMap = {};
11261
- for (let i2 = 0; i2 < objectIdAttributeData[objectIdField.name].length; i2++) {
11262
- attributeValuesMap[objectIdAttributeData[objectIdField.name][i2]] = calculateColorForAttribute(colorizeAttributeData[colorizeAttributeField.name][i2], options);
11263
- }
11264
- for (let i2 = 0; i2 < featureIds.value.length; i2++) {
11265
- const color = attributeValuesMap[featureIds.value[i2]];
11266
- if (!color) {
11267
- continue;
11268
- }
11269
- if (options.i3s.colorsByAttribute.mode === "multiply") {
11270
- color.forEach((colorItem, index) => {
11271
- colors.value[i2 * 4 + index] = colors.value[i2 * 4 + index] * colorItem / 255;
11272
- });
11273
- } else {
11274
- colors.value.set(color, i2 * 4);
11275
- }
11276
- }
11277
- return colors;
11278
- }
11279
- function calculateColorForAttribute(attributeValue, options) {
11280
- if (!options?.i3s?.colorsByAttribute) {
11281
- return [255, 255, 255, 255];
11282
- }
11283
- const {
11284
- minValue,
11285
- maxValue,
11286
- minColor,
11287
- maxColor
11288
- } = options.i3s.colorsByAttribute;
11289
- const rate = (attributeValue - minValue) / (maxValue - minValue);
11290
- const color = [255, 255, 255, 255];
11291
- for (let i2 = 0; i2 < minColor.length; i2++) {
11292
- color[i2] = Math.round((maxColor[i2] - minColor[i2]) * rate + minColor[i2]);
11293
- }
11294
- return color;
11295
- }
11296
- async function loadFeatureAttributeData(attributeName, {
11297
- attributeUrls
11298
- }, {
11299
- attributeStorageInfo
11300
- }, options) {
11301
- const attributeIndex = attributeStorageInfo.findIndex(({
11302
- name
11303
- }) => attributeName === name);
11304
- if (attributeIndex === -1) {
11305
- return null;
11306
- }
11307
- const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], options?.i3s?.token);
11308
- const attributeType = getAttributeValueType(attributeStorageInfo[attributeIndex]);
11309
- const objectIdAttributeData = await (0, import_core6.load)(objectIdAttributeUrl, I3SAttributeLoader, {
11310
- attributeName,
11311
- attributeType
11312
- });
11313
- return objectIdAttributeData;
11314
- }
11315
-
11316
11056
  // src/lib/parsers/parse-i3s-tile-content.ts
11317
11057
  var scratchVector6 = new Vector3([0, 0, 0]);
11318
11058
  function getLoaderForTextureFormat(textureFormat) {
@@ -11358,11 +11098,11 @@ var __exports__ = (() => {
11358
11098
  const texture = await parseFromContext(arrayBuffer2, [], options2, context);
11359
11099
  content.texture = texture;
11360
11100
  } catch (e2) {
11361
- const texture = await (0, import_core7.parse)(arrayBuffer2, loader, options2, context);
11101
+ const texture = await (0, import_core5.parse)(arrayBuffer2, loader, options2, context);
11362
11102
  content.texture = texture;
11363
11103
  }
11364
11104
  } else if (loader === CompressedTextureLoader || loader === BasisLoader) {
11365
- let texture = await (0, import_core7.load)(arrayBuffer2, loader, tileOptions.textureLoaderOptions);
11105
+ let texture = await (0, import_core5.load)(arrayBuffer2, loader, tileOptions.textureLoaderOptions);
11366
11106
  if (loader === BasisLoader) {
11367
11107
  texture = texture[0];
11368
11108
  }
@@ -11392,7 +11132,7 @@ var __exports__ = (() => {
11392
11132
  let featureCount = 0;
11393
11133
  let indices;
11394
11134
  if (tileOptions.isDracoGeometry) {
11395
- const decompressedGeometry = await (0, import_core7.parse)(arrayBuffer, DracoLoader2, {
11135
+ const decompressedGeometry = await (0, import_core5.parse)(arrayBuffer, DracoLoader2, {
11396
11136
  draco: {
11397
11137
  attributeNameEntry: I3S_ATTRIBUTE_TYPE
11398
11138
  }
@@ -11449,7 +11189,6 @@ var __exports__ = (() => {
11449
11189
  content.modelMatrix = getModelMatrix(attributes.position);
11450
11190
  content.coordinateSystem = COORDINATE_SYSTEM.LNGLAT_OFFSETS;
11451
11191
  }
11452
- attributes.color = await customizeColors(attributes.color, attributes.id, tileOptions, tilesetOptions, options);
11453
11192
  content.attributes = {
11454
11193
  positions: attributes.position,
11455
11194
  normals: attributes.normal,
@@ -11736,13 +11475,13 @@ var __exports__ = (() => {
11736
11475
  }
11737
11476
 
11738
11477
  // src/i3s-content-loader.ts
11739
- var VERSION6 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
11478
+ var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
11740
11479
  var I3SContentLoader = {
11741
11480
  name: "I3S Content (Indexed Scene Layers)",
11742
11481
  id: "i3s-content",
11743
11482
  module: "i3s",
11744
11483
  worker: true,
11745
- version: VERSION6,
11484
+ version: VERSION5,
11746
11485
  mimeTypes: ["application/octet-stream"],
11747
11486
  parse: parse3,
11748
11487
  extensions: ["bin"],
@@ -12216,7 +11955,7 @@ var __exports__ = (() => {
12216
11955
  };
12217
11956
 
12218
11957
  // src/lib/parsers/parse-i3s.ts
12219
- var import_core19 = __toESM(require_core(), 1);
11958
+ var import_core17 = __toESM(require_core(), 1);
12220
11959
 
12221
11960
  // ../tiles/src/constants.ts
12222
11961
  var TILE_REFINEMENT = function(TILE_REFINEMENT2) {
@@ -12243,15 +11982,15 @@ var __exports__ = (() => {
12243
11982
  }({});
12244
11983
 
12245
11984
  // src/lib/helpers/i3s-nodepages-tiles.ts
12246
- var import_core18 = __toESM(require_core(), 1);
11985
+ var import_core16 = __toESM(require_core(), 1);
12247
11986
 
12248
11987
  // src/i3s-node-page-loader.ts
12249
- var VERSION7 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
11988
+ var VERSION6 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
12250
11989
  var I3SNodePageLoader = {
12251
11990
  name: "I3S Node Page",
12252
11991
  id: "i3s-node-page",
12253
11992
  module: "i3s",
12254
- version: VERSION7,
11993
+ version: VERSION6,
12255
11994
  mimeTypes: ["application/json"],
12256
11995
  parse: parseNodePage,
12257
11996
  extensions: ["json"],
@@ -12286,7 +12025,7 @@ var __exports__ = (() => {
12286
12025
  const nodePageUrl = getUrlWithToken(`${this.url}/nodepages/${pageIndex}`, this.options.i3s?.token);
12287
12026
  this.pendingNodePages[pageIndex] = {
12288
12027
  status: "Pending",
12289
- promise: (0, import_core18.load)(nodePageUrl, I3SNodePageLoader, this.options)
12028
+ promise: (0, import_core16.load)(nodePageUrl, I3SNodePageLoader, this.options)
12290
12029
  };
12291
12030
  this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;
12292
12031
  this.nodesInNodePages += this.nodePages[pageIndex].nodes.length;
@@ -12512,7 +12251,7 @@ var __exports__ = (() => {
12512
12251
  } else {
12513
12252
  const parseOptions = options.i3s;
12514
12253
  const rootNodeUrl = getUrlWithToken(`${url}/nodes/root`, parseOptions.token);
12515
- root = await (0, import_core19.load)(rootNodeUrl, I3SLoader, {
12254
+ root = await (0, import_core17.load)(rootNodeUrl, I3SLoader, {
12516
12255
  ...options,
12517
12256
  i3s: {
12518
12257
  ...options.i3s,
@@ -12536,7 +12275,7 @@ var __exports__ = (() => {
12536
12275
  }
12537
12276
 
12538
12277
  // src/i3s-loader.ts
12539
- var VERSION8 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
12278
+ var VERSION7 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
12540
12279
  var TILESET_REGEX = /layers\/[0-9]+$/;
12541
12280
  var TILE_HEADER_REGEX = /nodes\/([0-9-]+|root)$/;
12542
12281
  var SLPK_HEX = "504b0304";
@@ -12545,7 +12284,7 @@ var __exports__ = (() => {
12545
12284
  name: "I3S (Indexed Scene Layers)",
12546
12285
  id: "i3s",
12547
12286
  module: "i3s",
12548
- version: VERSION8,
12287
+ version: VERSION7,
12549
12288
  mimeTypes: ["application/octet-stream"],
12550
12289
  parse: parseI3S,
12551
12290
  extensions: ["bin"],
@@ -12561,8 +12300,7 @@ var __exports__ = (() => {
12561
12300
  useDracoGeometry: true,
12562
12301
  useCompressedTextures: true,
12563
12302
  decodeTextures: true,
12564
- coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS,
12565
- colorsByAttribute: null
12303
+ coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS
12566
12304
  }
12567
12305
  }
12568
12306
  };
@@ -12596,7 +12334,7 @@ var __exports__ = (() => {
12596
12334
  return data;
12597
12335
  }
12598
12336
  async function parseTileContent(arrayBuffer, options) {
12599
- return await (0, import_core20.parse)(arrayBuffer, I3SContentLoader, options);
12337
+ return await (0, import_core18.parse)(arrayBuffer, I3SContentLoader, options);
12600
12338
  }
12601
12339
  async function parseTileset(data, options, context) {
12602
12340
  const tilesetJson = JSON.parse(new TextDecoder().decode(data));
@@ -13590,12 +13328,12 @@ var __exports__ = (() => {
13590
13328
  }
13591
13329
 
13592
13330
  // src/i3s-slpk-loader.ts
13593
- var VERSION9 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
13331
+ var VERSION8 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
13594
13332
  var SLPKLoader = {
13595
13333
  name: "I3S SLPK (Scene Layer Package)",
13596
13334
  id: "slpk",
13597
13335
  module: "i3s",
13598
- version: VERSION9,
13336
+ version: VERSION8,
13599
13337
  mimeTypes: ["application/octet-stream"],
13600
13338
  extensions: ["slpk"],
13601
13339
  options: {},
@@ -13605,6 +13343,183 @@ var __exports__ = (() => {
13605
13343
  }
13606
13344
  };
13607
13345
 
13346
+ // src/i3s-attribute-loader.ts
13347
+ var import_core19 = __toESM(require_core(), 1);
13348
+
13349
+ // src/lib/parsers/parse-i3s-attribute.ts
13350
+ function parseI3STileAttribute(arrayBuffer, options) {
13351
+ const {
13352
+ attributeName,
13353
+ attributeType
13354
+ } = options;
13355
+ if (!attributeName) {
13356
+ return {};
13357
+ }
13358
+ return {
13359
+ [attributeName]: attributeType ? parseAttribute(attributeType, arrayBuffer) : null
13360
+ };
13361
+ }
13362
+ function parseAttribute(attributeType, arrayBuffer) {
13363
+ switch (attributeType) {
13364
+ case STRING_ATTRIBUTE_TYPE:
13365
+ return parseStringsAttribute(arrayBuffer);
13366
+ case OBJECT_ID_ATTRIBUTE_TYPE:
13367
+ return parseShortNumberAttribute(arrayBuffer);
13368
+ case FLOAT_64_TYPE:
13369
+ return parseFloatAttribute(arrayBuffer);
13370
+ case INT_16_ATTRIBUTE_TYPE:
13371
+ return parseInt16ShortNumberAttribute(arrayBuffer);
13372
+ default:
13373
+ return parseShortNumberAttribute(arrayBuffer);
13374
+ }
13375
+ }
13376
+ function parseShortNumberAttribute(arrayBuffer) {
13377
+ const countOffset = 4;
13378
+ return new Uint32Array(arrayBuffer, countOffset);
13379
+ }
13380
+ function parseInt16ShortNumberAttribute(arrayBuffer) {
13381
+ const countOffset = 4;
13382
+ return new Int16Array(arrayBuffer, countOffset);
13383
+ }
13384
+ function parseFloatAttribute(arrayBuffer) {
13385
+ const countOffset = 8;
13386
+ return new Float64Array(arrayBuffer, countOffset);
13387
+ }
13388
+ function parseStringsAttribute(arrayBuffer) {
13389
+ const stringsCountOffset = 0;
13390
+ const dataOffset = 8;
13391
+ const bytesPerStringSize = 4;
13392
+ const stringsArray = [];
13393
+ try {
13394
+ const stringsCount = new DataView(arrayBuffer, stringsCountOffset, bytesPerStringSize).getUint32(stringsCountOffset, true);
13395
+ const stringSizes = new Uint32Array(arrayBuffer, dataOffset, stringsCount);
13396
+ let stringOffset = dataOffset + stringsCount * bytesPerStringSize;
13397
+ for (const stringByteSize of stringSizes) {
13398
+ const textDecoder = new TextDecoder("utf-8");
13399
+ const stringAttribute = new Uint8Array(arrayBuffer, stringOffset, stringByteSize);
13400
+ stringsArray.push(textDecoder.decode(stringAttribute));
13401
+ stringOffset += stringByteSize;
13402
+ }
13403
+ } catch (error) {
13404
+ console.error("Parse string attribute error: ", error.message);
13405
+ }
13406
+ return stringsArray;
13407
+ }
13408
+
13409
+ // src/i3s-attribute-loader.ts
13410
+ var VERSION9 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
13411
+ var EMPTY_VALUE = "";
13412
+ var REJECTED_STATUS = "rejected";
13413
+ var I3SAttributeLoader = {
13414
+ name: "I3S Attribute",
13415
+ id: "i3s-attribute",
13416
+ module: "i3s",
13417
+ version: VERSION9,
13418
+ mimeTypes: ["application/binary"],
13419
+ parse: async (arrayBuffer, options) => parseI3STileAttribute(arrayBuffer, options),
13420
+ extensions: ["bin"],
13421
+ options: {},
13422
+ binary: true
13423
+ };
13424
+ async function loadFeatureAttributes(tile, featureId, options = {}) {
13425
+ const {
13426
+ attributeStorageInfo,
13427
+ attributeUrls,
13428
+ tilesetFields
13429
+ } = getAttributesData(tile);
13430
+ if (!attributeStorageInfo || !attributeUrls || featureId < 0) {
13431
+ return null;
13432
+ }
13433
+ let attributes = [];
13434
+ const attributeLoadPromises = [];
13435
+ for (let index = 0; index < attributeStorageInfo.length; index++) {
13436
+ const url = getUrlWithToken(attributeUrls[index], options.i3s?.token);
13437
+ const attributeName = attributeStorageInfo[index].name;
13438
+ const attributeType = getAttributeValueType(attributeStorageInfo[index]);
13439
+ const loadOptions = {
13440
+ ...options,
13441
+ attributeName,
13442
+ attributeType
13443
+ };
13444
+ const promise = (0, import_core19.load)(url, I3SAttributeLoader, loadOptions);
13445
+ attributeLoadPromises.push(promise);
13446
+ }
13447
+ try {
13448
+ attributes = await Promise.allSettled(attributeLoadPromises);
13449
+ } catch (error) {
13450
+ }
13451
+ if (!attributes.length) {
13452
+ return null;
13453
+ }
13454
+ return generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields);
13455
+ }
13456
+ function getAttributesData(tile) {
13457
+ const attributeStorageInfo = tile.tileset?.tileset?.attributeStorageInfo;
13458
+ const attributeUrls = tile.header?.attributeUrls;
13459
+ const tilesetFields = tile.tileset?.tileset?.fields || [];
13460
+ return {
13461
+ attributeStorageInfo,
13462
+ attributeUrls,
13463
+ tilesetFields
13464
+ };
13465
+ }
13466
+ function getAttributeValueType(attribute) {
13467
+ if (attribute.hasOwnProperty("objectIds")) {
13468
+ return "Oid32";
13469
+ } else if (attribute.hasOwnProperty("attributeValues")) {
13470
+ return attribute.attributeValues.valueType;
13471
+ }
13472
+ return "";
13473
+ }
13474
+ function getFeatureIdsAttributeName(attributeStorageInfo) {
13475
+ const objectIdsAttribute = attributeStorageInfo.find((attribute) => attribute.name.includes("OBJECTID"));
13476
+ return objectIdsAttribute?.name;
13477
+ }
13478
+ function generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields) {
13479
+ const objectIdsAttributeName = getFeatureIdsAttributeName(attributeStorageInfo);
13480
+ const objectIds = attributes.find((attribute) => attribute.value[objectIdsAttributeName]);
13481
+ if (!objectIds) {
13482
+ return null;
13483
+ }
13484
+ const attributeIndex = objectIds.value[objectIdsAttributeName].indexOf(featureId);
13485
+ if (attributeIndex < 0) {
13486
+ return null;
13487
+ }
13488
+ return getFeatureAttributesByIndex(attributes, attributeIndex, attributeStorageInfo, tilesetFields);
13489
+ }
13490
+ function getFeatureAttributesByIndex(attributes, featureIdIndex, attributeStorageInfo, tilesetFields) {
13491
+ const attributesObject = {};
13492
+ for (let index = 0; index < attributeStorageInfo.length; index++) {
13493
+ const attributeName = attributeStorageInfo[index].name;
13494
+ const codedValues = getAttributeCodedValues(attributeName, tilesetFields);
13495
+ const attribute = getAttributeByIndexAndAttributeName(attributes, index, attributeName);
13496
+ attributesObject[attributeName] = formatAttributeValue(attribute, featureIdIndex, codedValues);
13497
+ }
13498
+ return attributesObject;
13499
+ }
13500
+ function getAttributeCodedValues(attributeName, tilesetFields) {
13501
+ const attributeField = tilesetFields.find((field) => field.name === attributeName || field.alias === attributeName);
13502
+ return attributeField?.domain?.codedValues || [];
13503
+ }
13504
+ function getAttributeByIndexAndAttributeName(attributes, index, attributesName) {
13505
+ const attributeObject = attributes[index];
13506
+ if (attributeObject.status === REJECTED_STATUS) {
13507
+ return null;
13508
+ }
13509
+ return attributeObject.value[attributesName];
13510
+ }
13511
+ function formatAttributeValue(attribute, featureIdIndex, codedValues) {
13512
+ let value = EMPTY_VALUE;
13513
+ if (attribute && featureIdIndex in attribute) {
13514
+ value = String(attribute[featureIdIndex]).replace(/\u0000|NaN/g, "").trim();
13515
+ }
13516
+ if (codedValues.length) {
13517
+ const codeValue = codedValues.find((codedValue) => codedValue.code === Number(value));
13518
+ value = codeValue?.name || EMPTY_VALUE;
13519
+ }
13520
+ return value;
13521
+ }
13522
+
13608
13523
  // src/lib/parsers/parse-i3s-building-scene-layer.ts
13609
13524
  var OBJECT_3D_LAYER_TYPE = "3DObject";
13610
13525
  async function parseBuildingSceneLayer(data, url) {
@@ -13664,7 +13579,7 @@ var __exports__ = (() => {
13664
13579
  }
13665
13580
 
13666
13581
  // src/lib/parsers/parse-arcgis-webscene.ts
13667
- var import_core21 = __toESM(require_core(), 1);
13582
+ var import_core20 = __toESM(require_core(), 1);
13668
13583
  var SUPPORTED_WKID = 4326;
13669
13584
  var ARCGIS_SCENE_SERVER_LAYER_TYPE = "ArcGISSceneServiceLayer";
13670
13585
  var BUILDING_SCENE_LAYER = "BuildingSceneLayer";
@@ -13722,7 +13637,7 @@ var __exports__ = (() => {
13722
13637
  }
13723
13638
  async function checkSupportedIndexCRS(layer) {
13724
13639
  try {
13725
- const layerJson = await (0, import_core21.load)(layer.url, import_core21.JSONLoader);
13640
+ const layerJson = await (0, import_core20.load)(layer.url, import_core20.JSONLoader);
13726
13641
  const wkid = layerJson?.spatialReference?.wkid;
13727
13642
  if (wkid !== SUPPORTED_WKID) {
13728
13643
  throw new Error(NOT_SUPPORTED_CRS_ERROR);
@@ -13747,6 +13662,88 @@ var __exports__ = (() => {
13747
13662
  async function parse6(data) {
13748
13663
  return parseWebscene(data);
13749
13664
  }
13665
+
13666
+ // src/lib/utils/customize-colors.ts
13667
+ var import_core21 = __toESM(require_core(), 1);
13668
+ async function customizeColors(colors, featureIds, attributeUrls, fields, attributeStorageInfo, colorsByAttribute, token) {
13669
+ if (!colorsByAttribute) {
13670
+ return colors;
13671
+ }
13672
+ const resultColors = {
13673
+ ...colors,
13674
+ value: new Uint8Array(colors.value)
13675
+ };
13676
+ const colorizeAttributeField = fields.find(({
13677
+ name
13678
+ }) => name === colorsByAttribute?.attributeName);
13679
+ if (!colorizeAttributeField || !["esriFieldTypeDouble", "esriFieldTypeInteger", "esriFieldTypeSmallInteger"].includes(colorizeAttributeField.type)) {
13680
+ return colors;
13681
+ }
13682
+ const colorizeAttributeData = await loadFeatureAttributeData(colorizeAttributeField.name, attributeUrls, attributeStorageInfo, token);
13683
+ if (!colorizeAttributeData) {
13684
+ return colors;
13685
+ }
13686
+ const objectIdField = fields.find(({
13687
+ type
13688
+ }) => type === "esriFieldTypeOID");
13689
+ if (!objectIdField) {
13690
+ return colors;
13691
+ }
13692
+ const objectIdAttributeData = await loadFeatureAttributeData(objectIdField.name, attributeUrls, attributeStorageInfo, token);
13693
+ if (!objectIdAttributeData) {
13694
+ return colors;
13695
+ }
13696
+ const attributeValuesMap = {};
13697
+ for (let i2 = 0; i2 < objectIdAttributeData[objectIdField.name].length; i2++) {
13698
+ attributeValuesMap[objectIdAttributeData[objectIdField.name][i2]] = calculateColorForAttribute(colorizeAttributeData[colorizeAttributeField.name][i2], colorsByAttribute);
13699
+ }
13700
+ for (let i2 = 0; i2 < featureIds.length; i2++) {
13701
+ const color = attributeValuesMap[featureIds[i2]];
13702
+ if (!color) {
13703
+ continue;
13704
+ }
13705
+ if (colorsByAttribute.mode === "multiply") {
13706
+ color.forEach((colorItem, index) => {
13707
+ resultColors.value[i2 * 4 + index] = resultColors.value[i2 * 4 + index] * colorItem / 255;
13708
+ });
13709
+ } else {
13710
+ resultColors.value.set(color, i2 * 4);
13711
+ }
13712
+ }
13713
+ return resultColors;
13714
+ }
13715
+ function calculateColorForAttribute(attributeValue, colorsByAttribute) {
13716
+ if (!colorsByAttribute) {
13717
+ return [255, 255, 255, 255];
13718
+ }
13719
+ const {
13720
+ minValue,
13721
+ maxValue,
13722
+ minColor,
13723
+ maxColor
13724
+ } = colorsByAttribute;
13725
+ const rate = (attributeValue - minValue) / (maxValue - minValue);
13726
+ const color = [255, 255, 255, 255];
13727
+ for (let i2 = 0; i2 < minColor.length; i2++) {
13728
+ color[i2] = Math.round((maxColor[i2] - minColor[i2]) * rate + minColor[i2]);
13729
+ }
13730
+ return color;
13731
+ }
13732
+ async function loadFeatureAttributeData(attributeName, attributeUrls, attributeStorageInfo, token) {
13733
+ const attributeIndex = attributeStorageInfo.findIndex(({
13734
+ name
13735
+ }) => attributeName === name);
13736
+ if (attributeIndex === -1) {
13737
+ return null;
13738
+ }
13739
+ const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], token);
13740
+ const attributeType = getAttributeValueType(attributeStorageInfo[attributeIndex]);
13741
+ const objectIdAttributeData = await (0, import_core21.load)(objectIdAttributeUrl, I3SAttributeLoader, {
13742
+ attributeName,
13743
+ attributeType
13744
+ });
13745
+ return objectIdAttributeData;
13746
+ }
13750
13747
  return __toCommonJS(src_exports);
13751
13748
  })();
13752
13749
  return __exports__;