@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.
- package/LICENSE +7 -7
- package/dist/dist.dev.js +864 -1460
- package/dist/i3s-content-worker-node.js +55 -55
- package/dist/i3s-content-worker-node.js.map +4 -4
- package/dist/i3s-content-worker.js +33 -796
- package/dist/i3s-loader.d.ts.map +1 -1
- package/dist/i3s-loader.js +1 -2
- package/dist/i3s-loader.js.map +1 -1
- package/dist/index.cjs +293 -316
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/parsers/constants.d.ts.map +1 -1
- package/dist/lib/parsers/constants.js +1 -1
- package/dist/lib/parsers/constants.js.map +1 -1
- package/dist/lib/parsers/parse-i3s-attribute.d.ts.map +1 -1
- package/dist/lib/parsers/parse-i3s-attribute.js.map +1 -1
- package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -1
- package/dist/lib/parsers/parse-i3s-tile-content.js +2 -4
- package/dist/lib/parsers/parse-i3s-tile-content.js.map +1 -1
- package/dist/lib/utils/customize-colors.d.ts +30 -0
- package/dist/lib/utils/customize-colors.d.ts.map +1 -0
- package/dist/lib/utils/customize-colors.js +92 -0
- package/dist/lib/utils/customize-colors.js.map +1 -0
- package/package.json +11 -12
- package/src/i3s-loader.ts +1 -2
- package/src/index.ts +2 -0
- package/src/lib/parsers/constants.ts +4 -1
- package/src/lib/parsers/parse-i3s-attribute.ts +1 -0
- package/src/lib/parsers/parse-i3s-tile-content.ts +2 -11
- package/src/lib/utils/{customize-/321/201olors.ts → customize-colors.ts} +66 -41
- package/dist/lib/utils/customize-/321/201olors.d.ts +0 -14
- package/dist/lib/utils/customize-/321/201olors.d.ts.map +0 -1
- package/dist/lib/utils/customize-/321/201olors.js +0 -98
- package/dist/lib/utils/customize-/321/201olors.js.map +0 -1
|
@@ -23,7 +23,6 @@ import {getUrlWithToken} from '../utils/url-utils';
|
|
|
23
23
|
|
|
24
24
|
import {GL_TYPE_MAP, getConstructorForDataFormat, sizeOf, COORDINATE_SYSTEM} from './constants';
|
|
25
25
|
import {I3SLoaderOptions} from '../../i3s-loader';
|
|
26
|
-
import {customizeColors} from '../utils/customize-сolors';
|
|
27
26
|
|
|
28
27
|
const scratchVector = new Vector3([0, 0, 0]);
|
|
29
28
|
|
|
@@ -65,8 +64,8 @@ export async function parseI3STileContent(
|
|
|
65
64
|
// @ts-expect-error options is not properly typed
|
|
66
65
|
const url = getUrlWithToken(tileOptions.textureUrl, options?.i3s?.token);
|
|
67
66
|
const loader = getLoaderForTextureFormat(tileOptions.textureFormat);
|
|
68
|
-
const
|
|
69
|
-
const response = await
|
|
67
|
+
const fetchFunc = context?.fetch || fetch;
|
|
68
|
+
const response = await fetchFunc(url); // options?.fetch
|
|
70
69
|
const arrayBuffer = await response.arrayBuffer();
|
|
71
70
|
|
|
72
71
|
// @ts-expect-error options is not properly typed
|
|
@@ -207,14 +206,6 @@ async function parseI3SNodeGeometry(
|
|
|
207
206
|
content.coordinateSystem = COORDINATE_SYSTEM.LNGLAT_OFFSETS;
|
|
208
207
|
}
|
|
209
208
|
|
|
210
|
-
attributes.color = await customizeColors(
|
|
211
|
-
attributes.color,
|
|
212
|
-
attributes.id,
|
|
213
|
-
tileOptions,
|
|
214
|
-
tilesetOptions,
|
|
215
|
-
options
|
|
216
|
-
);
|
|
217
|
-
|
|
218
209
|
content.attributes = {
|
|
219
210
|
positions: attributes.position,
|
|
220
211
|
normals: attributes.normal,
|
|
@@ -1,35 +1,57 @@
|
|
|
1
|
-
import type {MeshAttribute} from '@loaders.gl/schema';
|
|
2
|
-
import type {
|
|
1
|
+
import type {MeshAttribute, TypedArray} from '@loaders.gl/schema';
|
|
2
|
+
import type {AttributeStorageInfo, COLOR, Field} from '../../types';
|
|
3
3
|
|
|
4
4
|
import {load} from '@loaders.gl/core';
|
|
5
5
|
import {getAttributeValueType, I3SAttributeLoader} from '../../i3s-attribute-loader';
|
|
6
|
-
import {I3SLoaderOptions} from '../../i3s-loader';
|
|
7
6
|
import {getUrlWithToken} from './url-utils';
|
|
8
7
|
import {I3STileAttributes} from '../parsers/parse-i3s-attribute';
|
|
9
8
|
|
|
9
|
+
type ColorsByAttribute = {
|
|
10
|
+
/** Feature attribute name */
|
|
11
|
+
attributeName: string;
|
|
12
|
+
/** Minimum attribute value */
|
|
13
|
+
minValue: number;
|
|
14
|
+
/** Maximum attribute value */
|
|
15
|
+
maxValue: number;
|
|
16
|
+
/** Minimum color. 3DObject will be colorized with gradient from `minColor to `maxColor` */
|
|
17
|
+
minColor: [number, number, number, number];
|
|
18
|
+
/** Maximum color. 3DObject will be colorized with gradient from `minColor to `maxColor` */
|
|
19
|
+
maxColor: [number, number, number, number];
|
|
20
|
+
/** Colorization mode. `replace` - replace vertex colors with a new colors, `multiply` - multiply vertex colors with new colors */
|
|
21
|
+
mode: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
10
24
|
/**
|
|
11
|
-
*
|
|
25
|
+
* Calculate new vertex colors array to visualize 3D objects in a attribute driven way
|
|
12
26
|
* @param colors - vertex colors attribute
|
|
13
27
|
* @param featureIds - feature Ids attribute
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @
|
|
28
|
+
* @param attributeUrls - array of attribute's urls
|
|
29
|
+
* @param fields - array of attribute's fileds
|
|
30
|
+
* @param attributeStorageInfo - array of attributeStorageInfo
|
|
31
|
+
* @param colorsByAttribute - attribute color options
|
|
32
|
+
* @param token - access token
|
|
33
|
+
* @returns new colors attribute
|
|
18
34
|
*/
|
|
35
|
+
// eslint-disable-next-line max-params
|
|
19
36
|
export async function customizeColors(
|
|
20
37
|
colors: MeshAttribute,
|
|
21
|
-
featureIds:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
38
|
+
featureIds: number[] | TypedArray,
|
|
39
|
+
attributeUrls: string[],
|
|
40
|
+
fields: Field[],
|
|
41
|
+
attributeStorageInfo: AttributeStorageInfo[],
|
|
42
|
+
colorsByAttribute: ColorsByAttribute | null,
|
|
43
|
+
token?: string
|
|
25
44
|
): Promise<MeshAttribute> {
|
|
26
|
-
if (!
|
|
45
|
+
if (!colorsByAttribute) {
|
|
27
46
|
return colors;
|
|
28
47
|
}
|
|
29
48
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
49
|
+
const resultColors = {
|
|
50
|
+
...colors,
|
|
51
|
+
value: new Uint8Array(colors.value)
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const colorizeAttributeField = fields.find(({name}) => name === colorsByAttribute?.attributeName);
|
|
33
55
|
if (
|
|
34
56
|
!colorizeAttributeField ||
|
|
35
57
|
!['esriFieldTypeDouble', 'esriFieldTypeInteger', 'esriFieldTypeSmallInteger'].includes(
|
|
@@ -41,24 +63,24 @@ export async function customizeColors(
|
|
|
41
63
|
|
|
42
64
|
const colorizeAttributeData = await loadFeatureAttributeData(
|
|
43
65
|
colorizeAttributeField.name,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
66
|
+
attributeUrls,
|
|
67
|
+
attributeStorageInfo,
|
|
68
|
+
token
|
|
47
69
|
);
|
|
48
70
|
if (!colorizeAttributeData) {
|
|
49
71
|
return colors;
|
|
50
72
|
}
|
|
51
73
|
|
|
52
|
-
const objectIdField =
|
|
74
|
+
const objectIdField = fields.find(({type}) => type === 'esriFieldTypeOID');
|
|
53
75
|
if (!objectIdField) {
|
|
54
76
|
return colors;
|
|
55
77
|
}
|
|
56
78
|
|
|
57
79
|
const objectIdAttributeData = await loadFeatureAttributeData(
|
|
58
80
|
objectIdField.name,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
attributeUrls,
|
|
82
|
+
attributeStorageInfo,
|
|
83
|
+
token
|
|
62
84
|
);
|
|
63
85
|
if (!objectIdAttributeData) {
|
|
64
86
|
return colors;
|
|
@@ -71,42 +93,45 @@ export async function customizeColors(
|
|
|
71
93
|
attributeValuesMap[objectIdAttributeData[objectIdField.name][i]] = calculateColorForAttribute(
|
|
72
94
|
// @ts-expect-error
|
|
73
95
|
colorizeAttributeData[colorizeAttributeField.name][i] as number,
|
|
74
|
-
|
|
96
|
+
colorsByAttribute
|
|
75
97
|
);
|
|
76
98
|
}
|
|
77
99
|
|
|
78
|
-
for (let i = 0; i < featureIds.
|
|
79
|
-
const color = attributeValuesMap[featureIds
|
|
100
|
+
for (let i = 0; i < featureIds.length; i++) {
|
|
101
|
+
const color = attributeValuesMap[featureIds[i]];
|
|
80
102
|
if (!color) {
|
|
81
103
|
continue; // eslint-disable-line no-continue
|
|
82
104
|
}
|
|
83
105
|
|
|
84
106
|
/* eslint max-statements: ["error", 30] */
|
|
85
107
|
/* eslint complexity: ["error", 12] */
|
|
86
|
-
if (
|
|
108
|
+
if (colorsByAttribute.mode === 'multiply') {
|
|
87
109
|
// multiplying original mesh and calculated for attribute rgba colors in range 0-255
|
|
88
110
|
color.forEach((colorItem, index) => {
|
|
89
|
-
|
|
111
|
+
resultColors.value[i * 4 + index] = (resultColors.value[i * 4 + index] * colorItem) / 255;
|
|
90
112
|
});
|
|
91
113
|
} else {
|
|
92
|
-
|
|
114
|
+
resultColors.value.set(color, i * 4);
|
|
93
115
|
}
|
|
94
116
|
}
|
|
95
117
|
|
|
96
|
-
return
|
|
118
|
+
return resultColors;
|
|
97
119
|
}
|
|
98
120
|
|
|
99
121
|
/**
|
|
100
122
|
* Calculate rgba color from the attribute value
|
|
101
123
|
* @param attributeValue - value of the attribute
|
|
102
|
-
* @param
|
|
124
|
+
* @param colorsByAttribute - attribute color options
|
|
103
125
|
* @returns - color array for a specific attribute value
|
|
104
126
|
*/
|
|
105
|
-
function calculateColorForAttribute(
|
|
106
|
-
|
|
127
|
+
function calculateColorForAttribute(
|
|
128
|
+
attributeValue: number,
|
|
129
|
+
colorsByAttribute: ColorsByAttribute
|
|
130
|
+
): COLOR {
|
|
131
|
+
if (!colorsByAttribute) {
|
|
107
132
|
return [255, 255, 255, 255];
|
|
108
133
|
}
|
|
109
|
-
const {minValue, maxValue, minColor, maxColor} =
|
|
134
|
+
const {minValue, maxValue, minColor, maxColor} = colorsByAttribute;
|
|
110
135
|
const rate = (attributeValue - minValue) / (maxValue - minValue);
|
|
111
136
|
const color: COLOR = [255, 255, 255, 255];
|
|
112
137
|
for (let i = 0; i < minColor.length; i++) {
|
|
@@ -118,22 +143,22 @@ function calculateColorForAttribute(attributeValue: number, options?: I3SLoaderO
|
|
|
118
143
|
/**
|
|
119
144
|
* Load feature attribute data from the ArcGIS rest service
|
|
120
145
|
* @param attributeName - attribute name
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
123
|
-
* @param
|
|
146
|
+
* @param attributeUrls - array of attribute's urls
|
|
147
|
+
* @param attributeStorageInfo - array of attributeStorageInfo
|
|
148
|
+
* @param token - access token
|
|
124
149
|
* @returns - Array-like list of the attribute values
|
|
125
150
|
*/
|
|
126
151
|
async function loadFeatureAttributeData(
|
|
127
152
|
attributeName: string,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
153
|
+
attributeUrls: string[],
|
|
154
|
+
attributeStorageInfo: AttributeStorageInfo[],
|
|
155
|
+
token?: string
|
|
131
156
|
): Promise<I3STileAttributes | null> {
|
|
132
157
|
const attributeIndex = attributeStorageInfo.findIndex(({name}) => attributeName === name);
|
|
133
158
|
if (attributeIndex === -1) {
|
|
134
159
|
return null;
|
|
135
160
|
}
|
|
136
|
-
const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex],
|
|
161
|
+
const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], token);
|
|
137
162
|
const attributeType = getAttributeValueType(attributeStorageInfo[attributeIndex]);
|
|
138
163
|
const objectIdAttributeData = await load(objectIdAttributeUrl, I3SAttributeLoader, {
|
|
139
164
|
attributeName,
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { MeshAttribute } from '@loaders.gl/schema';
|
|
2
|
-
import type { I3STileOptions, I3STilesetOptions } from '../../types';
|
|
3
|
-
import { I3SLoaderOptions } from '../../i3s-loader';
|
|
4
|
-
/**
|
|
5
|
-
* Modify vertex colors array to visualize 3D objects in a attribute driven way
|
|
6
|
-
* @param colors - vertex colors attribute
|
|
7
|
-
* @param featureIds - feature Ids attribute
|
|
8
|
-
* @param tileOptions - tile - related options
|
|
9
|
-
* @param tilesetOptions - tileset-related options
|
|
10
|
-
* @param options - loader options
|
|
11
|
-
* @returns midified colors attribute
|
|
12
|
-
*/
|
|
13
|
-
export declare function customizeColors(colors: MeshAttribute, featureIds: MeshAttribute, tileOptions: I3STileOptions, tilesetOptions: I3STilesetOptions, options?: I3SLoaderOptions): Promise<MeshAttribute>;
|
|
14
|
-
//# sourceMappingURL=customize-%D1%81olors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"customize-сolors.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/customize-сolors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAQ,cAAc,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAI1E,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAIlD;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,aAAa,EACzB,WAAW,EAAE,cAAc,EAC3B,cAAc,EAAE,iBAAiB,EACjC,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,aAAa,CAAC,CAwExB"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { load } from '@loaders.gl/core';
|
|
2
|
-
import { getAttributeValueType, I3SAttributeLoader } from "../../i3s-attribute-loader.js";
|
|
3
|
-
import { getUrlWithToken } from "./url-utils.js";
|
|
4
|
-
export async function customizeColors(colors, featureIds, tileOptions, tilesetOptions, options) {
|
|
5
|
-
var _options$i3s;
|
|
6
|
-
if (!(options !== null && options !== void 0 && (_options$i3s = options.i3s) !== null && _options$i3s !== void 0 && _options$i3s.colorsByAttribute)) {
|
|
7
|
-
return colors;
|
|
8
|
-
}
|
|
9
|
-
const colorizeAttributeField = tilesetOptions.fields.find(_ref => {
|
|
10
|
-
var _options$i3s2, _options$i3s2$colorsB;
|
|
11
|
-
let {
|
|
12
|
-
name
|
|
13
|
-
} = _ref;
|
|
14
|
-
return name === (options === null || options === void 0 ? void 0 : (_options$i3s2 = options.i3s) === null || _options$i3s2 === void 0 ? void 0 : (_options$i3s2$colorsB = _options$i3s2.colorsByAttribute) === null || _options$i3s2$colorsB === void 0 ? void 0 : _options$i3s2$colorsB.attributeName);
|
|
15
|
-
});
|
|
16
|
-
if (!colorizeAttributeField || !['esriFieldTypeDouble', 'esriFieldTypeInteger', 'esriFieldTypeSmallInteger'].includes(colorizeAttributeField.type)) {
|
|
17
|
-
return colors;
|
|
18
|
-
}
|
|
19
|
-
const colorizeAttributeData = await loadFeatureAttributeData(colorizeAttributeField.name, tileOptions, tilesetOptions, options);
|
|
20
|
-
if (!colorizeAttributeData) {
|
|
21
|
-
return colors;
|
|
22
|
-
}
|
|
23
|
-
const objectIdField = tilesetOptions.fields.find(_ref2 => {
|
|
24
|
-
let {
|
|
25
|
-
type
|
|
26
|
-
} = _ref2;
|
|
27
|
-
return type === 'esriFieldTypeOID';
|
|
28
|
-
});
|
|
29
|
-
if (!objectIdField) {
|
|
30
|
-
return colors;
|
|
31
|
-
}
|
|
32
|
-
const objectIdAttributeData = await loadFeatureAttributeData(objectIdField.name, tileOptions, tilesetOptions, options);
|
|
33
|
-
if (!objectIdAttributeData) {
|
|
34
|
-
return colors;
|
|
35
|
-
}
|
|
36
|
-
const attributeValuesMap = {};
|
|
37
|
-
for (let i = 0; i < objectIdAttributeData[objectIdField.name].length; i++) {
|
|
38
|
-
attributeValuesMap[objectIdAttributeData[objectIdField.name][i]] = calculateColorForAttribute(colorizeAttributeData[colorizeAttributeField.name][i], options);
|
|
39
|
-
}
|
|
40
|
-
for (let i = 0; i < featureIds.value.length; i++) {
|
|
41
|
-
const color = attributeValuesMap[featureIds.value[i]];
|
|
42
|
-
if (!color) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
if (options.i3s.colorsByAttribute.mode === 'multiply') {
|
|
46
|
-
color.forEach((colorItem, index) => {
|
|
47
|
-
colors.value[i * 4 + index] = colors.value[i * 4 + index] * colorItem / 255;
|
|
48
|
-
});
|
|
49
|
-
} else {
|
|
50
|
-
colors.value.set(color, i * 4);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return colors;
|
|
54
|
-
}
|
|
55
|
-
function calculateColorForAttribute(attributeValue, options) {
|
|
56
|
-
var _options$i3s3;
|
|
57
|
-
if (!(options !== null && options !== void 0 && (_options$i3s3 = options.i3s) !== null && _options$i3s3 !== void 0 && _options$i3s3.colorsByAttribute)) {
|
|
58
|
-
return [255, 255, 255, 255];
|
|
59
|
-
}
|
|
60
|
-
const {
|
|
61
|
-
minValue,
|
|
62
|
-
maxValue,
|
|
63
|
-
minColor,
|
|
64
|
-
maxColor
|
|
65
|
-
} = options.i3s.colorsByAttribute;
|
|
66
|
-
const rate = (attributeValue - minValue) / (maxValue - minValue);
|
|
67
|
-
const color = [255, 255, 255, 255];
|
|
68
|
-
for (let i = 0; i < minColor.length; i++) {
|
|
69
|
-
color[i] = Math.round((maxColor[i] - minColor[i]) * rate + minColor[i]);
|
|
70
|
-
}
|
|
71
|
-
return color;
|
|
72
|
-
}
|
|
73
|
-
async function loadFeatureAttributeData(attributeName, _ref3, _ref4, options) {
|
|
74
|
-
var _options$i3s4;
|
|
75
|
-
let {
|
|
76
|
-
attributeUrls
|
|
77
|
-
} = _ref3;
|
|
78
|
-
let {
|
|
79
|
-
attributeStorageInfo
|
|
80
|
-
} = _ref4;
|
|
81
|
-
const attributeIndex = attributeStorageInfo.findIndex(_ref5 => {
|
|
82
|
-
let {
|
|
83
|
-
name
|
|
84
|
-
} = _ref5;
|
|
85
|
-
return attributeName === name;
|
|
86
|
-
});
|
|
87
|
-
if (attributeIndex === -1) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], options === null || options === void 0 ? void 0 : (_options$i3s4 = options.i3s) === null || _options$i3s4 === void 0 ? void 0 : _options$i3s4.token);
|
|
91
|
-
const attributeType = getAttributeValueType(attributeStorageInfo[attributeIndex]);
|
|
92
|
-
const objectIdAttributeData = await load(objectIdAttributeUrl, I3SAttributeLoader, {
|
|
93
|
-
attributeName,
|
|
94
|
-
attributeType
|
|
95
|
-
});
|
|
96
|
-
return objectIdAttributeData;
|
|
97
|
-
}
|
|
98
|
-
//# sourceMappingURL=customize-сolors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"customize-сolors.js","names":["load","getAttributeValueType","I3SAttributeLoader","getUrlWithToken","customizeColors","colors","featureIds","tileOptions","tilesetOptions","options","_options$i3s","i3s","colorsByAttribute","colorizeAttributeField","fields","find","_ref","_options$i3s2","_options$i3s2$colorsB","name","attributeName","includes","type","colorizeAttributeData","loadFeatureAttributeData","objectIdField","_ref2","objectIdAttributeData","attributeValuesMap","i","length","calculateColorForAttribute","value","color","mode","forEach","colorItem","index","set","attributeValue","_options$i3s3","minValue","maxValue","minColor","maxColor","rate","Math","round","_ref3","_ref4","_options$i3s4","attributeUrls","attributeStorageInfo","attributeIndex","findIndex","_ref5","objectIdAttributeUrl","token","attributeType"],"sources":["../../../src/lib/utils/customize-сolors.ts"],"sourcesContent":["import type {MeshAttribute} from '@loaders.gl/schema';\nimport type {COLOR, I3STileOptions, I3STilesetOptions} from '../../types';\n\nimport {load} from '@loaders.gl/core';\nimport {getAttributeValueType, I3SAttributeLoader} from '../../i3s-attribute-loader';\nimport {I3SLoaderOptions} from '../../i3s-loader';\nimport {getUrlWithToken} from './url-utils';\nimport {I3STileAttributes} from '../parsers/parse-i3s-attribute';\n\n/**\n * Modify vertex colors array to visualize 3D objects in a attribute driven way\n * @param colors - vertex colors attribute\n * @param featureIds - feature Ids attribute\n * @param tileOptions - tile - related options\n * @param tilesetOptions - tileset-related options\n * @param options - loader options\n * @returns midified colors attribute\n */\nexport async function customizeColors(\n colors: MeshAttribute,\n featureIds: MeshAttribute,\n tileOptions: I3STileOptions,\n tilesetOptions: I3STilesetOptions,\n options?: I3SLoaderOptions\n): Promise<MeshAttribute> {\n if (!options?.i3s?.colorsByAttribute) {\n return colors;\n }\n\n const colorizeAttributeField = tilesetOptions.fields.find(\n ({name}) => name === options?.i3s?.colorsByAttribute?.attributeName\n );\n if (\n !colorizeAttributeField ||\n !['esriFieldTypeDouble', 'esriFieldTypeInteger', 'esriFieldTypeSmallInteger'].includes(\n colorizeAttributeField.type\n )\n ) {\n return colors;\n }\n\n const colorizeAttributeData = await loadFeatureAttributeData(\n colorizeAttributeField.name,\n tileOptions,\n tilesetOptions,\n options\n );\n if (!colorizeAttributeData) {\n return colors;\n }\n\n const objectIdField = tilesetOptions.fields.find(({type}) => type === 'esriFieldTypeOID');\n if (!objectIdField) {\n return colors;\n }\n\n const objectIdAttributeData = await loadFeatureAttributeData(\n objectIdField.name,\n tileOptions,\n tilesetOptions,\n options\n );\n if (!objectIdAttributeData) {\n return colors;\n }\n\n const attributeValuesMap: {[key: number]: COLOR} = {};\n // @ts-expect-error\n for (let i = 0; i < objectIdAttributeData[objectIdField.name].length; i++) {\n // @ts-expect-error\n attributeValuesMap[objectIdAttributeData[objectIdField.name][i]] = calculateColorForAttribute(\n // @ts-expect-error\n colorizeAttributeData[colorizeAttributeField.name][i] as number,\n options\n );\n }\n\n for (let i = 0; i < featureIds.value.length; i++) {\n const color = attributeValuesMap[featureIds.value[i]];\n if (!color) {\n continue; // eslint-disable-line no-continue\n }\n\n /* eslint max-statements: [\"error\", 30] */\n /* eslint complexity: [\"error\", 12] */\n if (options.i3s.colorsByAttribute.mode === 'multiply') {\n // multiplying original mesh and calculated for attribute rgba colors in range 0-255\n color.forEach((colorItem, index) => {\n colors.value[i * 4 + index] = (colors.value[i * 4 + index] * colorItem) / 255;\n });\n } else {\n colors.value.set(color, i * 4);\n }\n }\n\n return colors;\n}\n\n/**\n * Calculate rgba color from the attribute value\n * @param attributeValue - value of the attribute\n * @param options - loader options\n * @returns - color array for a specific attribute value\n */\nfunction calculateColorForAttribute(attributeValue: number, options?: I3SLoaderOptions): COLOR {\n if (!options?.i3s?.colorsByAttribute) {\n return [255, 255, 255, 255];\n }\n const {minValue, maxValue, minColor, maxColor} = options.i3s.colorsByAttribute;\n const rate = (attributeValue - minValue) / (maxValue - minValue);\n const color: COLOR = [255, 255, 255, 255];\n for (let i = 0; i < minColor.length; i++) {\n color[i] = Math.round((maxColor[i] - minColor[i]) * rate + minColor[i]);\n }\n return color;\n}\n\n/**\n * Load feature attribute data from the ArcGIS rest service\n * @param attributeName - attribute name\n * @param tileOptions - tile-related options\n * @param tilesetOptions - tileset-related options\n * @param options - loader options\n * @returns - Array-like list of the attribute values\n */\nasync function loadFeatureAttributeData(\n attributeName: string,\n {attributeUrls}: I3STileOptions,\n {attributeStorageInfo}: I3STilesetOptions,\n options?: I3SLoaderOptions\n): Promise<I3STileAttributes | null> {\n const attributeIndex = attributeStorageInfo.findIndex(({name}) => attributeName === name);\n if (attributeIndex === -1) {\n return null;\n }\n const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], options?.i3s?.token);\n const attributeType = getAttributeValueType(attributeStorageInfo[attributeIndex]);\n const objectIdAttributeData = await load(objectIdAttributeUrl, I3SAttributeLoader, {\n attributeName,\n attributeType\n });\n\n return objectIdAttributeData;\n}\n"],"mappings":"AAGA,SAAQA,IAAI,QAAO,kBAAkB;AAAC,SAC9BC,qBAAqB,EAAEC,kBAAkB;AAAA,SAEzCC,eAAe;AAYvB,OAAO,eAAeC,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