@loaders.gl/tile-converter 3.3.0-alpha.3 → 3.3.0-alpha.4
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/dist/3d-tiles-attributes-worker.js +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +8 -0
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js +57 -43
- package/dist/converter.min.js +21 -21
- package/dist/deps-installer/deps-installer.d.ts +5 -1
- package/dist/deps-installer/deps-installer.d.ts.map +1 -1
- package/dist/deps-installer/deps-installer.js +21 -1
- package/dist/dist.min.js +660 -1016
- package/dist/es5/3d-tiles-attributes-worker.js +1 -1
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +115 -101
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +70 -6
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-attributes-worker.js +1 -1
- package/dist/es5/i3s-attributes-worker.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +4 -0
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/feature-attributes.js +153 -0
- package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +40 -44
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js +55 -36
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-pages.js +10 -2
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +364 -435
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/pgm-loader.js +1 -1
- package/dist/esm/3d-tiles-attributes-worker.js +1 -1
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +59 -44
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/esm/deps-installer/deps-installer.js +21 -2
- package/dist/esm/deps-installer/deps-installer.js.map +1 -1
- package/dist/esm/i3s-attributes-worker.js +1 -1
- package/dist/esm/i3s-attributes-worker.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +4 -0
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/feature-attributes.js +138 -0
- package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +19 -21
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js +55 -36
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-pages.js +9 -2
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +93 -183
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/i3s-attributes-worker.d.ts +5 -1
- package/dist/i3s-attributes-worker.d.ts.map +1 -1
- package/dist/i3s-attributes-worker.js +3 -3
- package/dist/i3s-attributes-worker.js.map +2 -2
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +2 -3
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +3 -0
- package/dist/i3s-converter/helpers/coordinate-converter.d.ts +2 -2
- package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/feature-attributes.d.ts +32 -0
- package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/feature-attributes.js +162 -1
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +5 -4
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.js +29 -27
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js +50 -30
- package/dist/i3s-converter/helpers/node-pages.d.ts +4 -0
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-pages.js +9 -2
- package/dist/i3s-converter/i3s-converter.d.ts +24 -48
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +88 -186
- package/dist/i3s-converter/types.d.ts +4 -0
- package/dist/i3s-converter/types.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/3d-tiles-converter/3d-tiles-converter.ts +71 -55
- package/src/deps-installer/deps-installer.ts +29 -2
- package/src/i3s-attributes-worker.ts +5 -1
- package/src/i3s-converter/helpers/batch-ids-extensions.ts +13 -6
- package/src/i3s-converter/helpers/coordinate-converter.ts +2 -2
- package/src/i3s-converter/helpers/feature-attributes.ts +182 -0
- package/src/i3s-converter/helpers/geometry-converter.ts +45 -36
- package/src/i3s-converter/helpers/gltf-attributes.ts +54 -33
- package/src/i3s-converter/helpers/node-pages.ts +10 -2
- package/src/i3s-converter/i3s-converter.ts +125 -210
- package/src/i3s-converter/types.ts +4 -0
|
@@ -15,12 +15,11 @@ import {convertScreenThresholdToGeometricError} from '../lib/utils/lod-conversio
|
|
|
15
15
|
import {writeFile, removeDir} from '../lib/utils/file-utils';
|
|
16
16
|
import {calculateFilesSize, timeConverter} from '../lib/utils/statistic-utills';
|
|
17
17
|
import {TILESET as tilesetTemplate} from './json-templates/tileset';
|
|
18
|
-
import B3dmConverter from './helpers/b3dm-converter';
|
|
19
18
|
import {createObbFromMbs} from '../i3s-converter/helpers/coordinate-converter';
|
|
20
19
|
import {
|
|
21
20
|
I3SAttributesData,
|
|
22
|
-
Tile3dAttributesWorker
|
|
23
|
-
|
|
21
|
+
Tile3dAttributesWorker,
|
|
22
|
+
transform3DTilesAttributesOnWorker
|
|
24
23
|
} from '../3d-tiles-attributes-worker';
|
|
25
24
|
import {getWorkerURL, WorkerFarm} from '@loaders.gl/worker-utils';
|
|
26
25
|
import {BROWSER_ERROR_MESSAGE} from '../constants';
|
|
@@ -85,6 +84,11 @@ export default class Tiles3DConverter {
|
|
|
85
84
|
|
|
86
85
|
this.sourceTileset = new Tileset3D(sourceTilesetJson, {
|
|
87
86
|
loadOptions: {
|
|
87
|
+
_nodeWorkers: true,
|
|
88
|
+
reuseWorkers: true,
|
|
89
|
+
'i3s-content-nodejs': {
|
|
90
|
+
workerUrl: './modules/i3s/dist/i3s-content-nodejs-worker.js'
|
|
91
|
+
},
|
|
88
92
|
i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false}
|
|
89
93
|
}
|
|
90
94
|
});
|
|
@@ -124,6 +128,67 @@ export default class Tiles3DConverter {
|
|
|
124
128
|
workerFarm.destroy();
|
|
125
129
|
}
|
|
126
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Convert particular I3S Node
|
|
133
|
+
* @param parentSourceNode the parent node tile object (@loaders.gl/tiles/Tile3D)
|
|
134
|
+
* @param parentNode object in resulting tileset
|
|
135
|
+
* @param level a current level of a tree depth
|
|
136
|
+
* @param childNodeInfo child node to convert
|
|
137
|
+
*/
|
|
138
|
+
private async convertChildNode(
|
|
139
|
+
parentSourceNode: Tile3D,
|
|
140
|
+
parentNode: Node3D,
|
|
141
|
+
level: number,
|
|
142
|
+
childNodeInfo: NodeReference
|
|
143
|
+
): Promise<void> {
|
|
144
|
+
const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);
|
|
145
|
+
parentSourceNode.children.push(sourceChild);
|
|
146
|
+
if (sourceChild.contentUrl) {
|
|
147
|
+
await this.sourceTileset!._loadTile(sourceChild);
|
|
148
|
+
this.vertexCounter += sourceChild.content.vertexCount;
|
|
149
|
+
|
|
150
|
+
let featureAttributes: FeatureAttribute | null = null;
|
|
151
|
+
if (this.attributeStorageInfo) {
|
|
152
|
+
featureAttributes = await this._loadChildAttributes(sourceChild, this.attributeStorageInfo);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!sourceChild.header.obb) {
|
|
156
|
+
sourceChild.header.obb = createObbFromMbs(sourceChild.header.mbs);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const boundingVolume = {
|
|
160
|
+
box: i3sObbTo3dTilesObb(sourceChild.header.obb, this.geoidHeightModel)
|
|
161
|
+
};
|
|
162
|
+
const child: Node3D = {
|
|
163
|
+
boundingVolume,
|
|
164
|
+
geometricError: convertScreenThresholdToGeometricError(sourceChild),
|
|
165
|
+
children: []
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const i3sAttributesData: I3SAttributesData = {
|
|
169
|
+
tileContent: sourceChild.content,
|
|
170
|
+
textureFormat: sourceChild?.header?.textureFormat
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const b3dm = await transform3DTilesAttributesOnWorker(i3sAttributesData, {
|
|
174
|
+
source: this.workerSource.tile3dWorkerSource,
|
|
175
|
+
featureAttributes
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
child.content = {
|
|
179
|
+
uri: `${sourceChild.id}.b3dm`,
|
|
180
|
+
boundingVolume
|
|
181
|
+
};
|
|
182
|
+
await writeFile(this.tilesetPath, new Uint8Array(b3dm), `${sourceChild.id}.b3dm`);
|
|
183
|
+
parentNode.children.push(child);
|
|
184
|
+
|
|
185
|
+
sourceChild.unloadContent();
|
|
186
|
+
await this._addChildren(sourceChild, child, level + 1);
|
|
187
|
+
} else {
|
|
188
|
+
await this._addChildren(sourceChild, parentNode, level + 1);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
127
192
|
/**
|
|
128
193
|
* The recursive function of traversal of a nodes tree
|
|
129
194
|
* @param parentSourceNode the parent node tile object (@loaders.gl/tiles/Tile3D)
|
|
@@ -138,60 +203,11 @@ export default class Tiles3DConverter {
|
|
|
138
203
|
if (this.options.maxDepth && level > this.options.maxDepth) {
|
|
139
204
|
return;
|
|
140
205
|
}
|
|
206
|
+
const promises: Promise<void>[] = [];
|
|
141
207
|
for (const childNodeInfo of parentSourceNode.header.children || []) {
|
|
142
|
-
|
|
143
|
-
parentSourceNode.children.push(sourceChild);
|
|
144
|
-
if (sourceChild.contentUrl) {
|
|
145
|
-
await this.sourceTileset!._loadTile(sourceChild);
|
|
146
|
-
this.vertexCounter += sourceChild.content.vertexCount;
|
|
147
|
-
|
|
148
|
-
let featureAttributes: FeatureAttribute | null = null;
|
|
149
|
-
if (this.attributeStorageInfo) {
|
|
150
|
-
featureAttributes = await this._loadChildAttributes(
|
|
151
|
-
sourceChild,
|
|
152
|
-
this.attributeStorageInfo
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (!sourceChild.header.obb) {
|
|
157
|
-
sourceChild.header.obb = createObbFromMbs(sourceChild.header.mbs);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const boundingVolume = {
|
|
161
|
-
box: i3sObbTo3dTilesObb(sourceChild.header.obb, this.geoidHeightModel)
|
|
162
|
-
};
|
|
163
|
-
const child: Node3D = {
|
|
164
|
-
boundingVolume,
|
|
165
|
-
geometricError: convertScreenThresholdToGeometricError(sourceChild),
|
|
166
|
-
children: []
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
const i3sAttributesData: I3SAttributesData = {
|
|
170
|
-
tileContent: sourceChild.content,
|
|
171
|
-
textureFormat: sourceChild?.header?.textureFormat
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
// TODO Uncomment when 3d-tiles-attributes-worker will be published on CDN.
|
|
175
|
-
// const b3dm = await transform3DTilesAttributesOnWorker(i3sAttributesData, {
|
|
176
|
-
// source: this.workerSource.tile3dWorkerSource,
|
|
177
|
-
// featureAttributes
|
|
178
|
-
// });
|
|
179
|
-
|
|
180
|
-
const b3dm = await new B3dmConverter().convert(i3sAttributesData, featureAttributes);
|
|
181
|
-
|
|
182
|
-
child.content = {
|
|
183
|
-
uri: `${sourceChild.id}.b3dm`,
|
|
184
|
-
boundingVolume
|
|
185
|
-
};
|
|
186
|
-
await writeFile(this.tilesetPath, new Uint8Array(b3dm), `${sourceChild.id}.b3dm`);
|
|
187
|
-
parentNode.children.push(child);
|
|
188
|
-
|
|
189
|
-
sourceChild.unloadContent();
|
|
190
|
-
await this._addChildren(sourceChild, child, level + 1);
|
|
191
|
-
} else {
|
|
192
|
-
await this._addChildren(sourceChild, parentNode, level + 1);
|
|
193
|
-
}
|
|
208
|
+
promises.push(this.convertChildNode(parentSourceNode, parentNode, level, childNodeInfo));
|
|
194
209
|
}
|
|
210
|
+
await Promise.all(promises);
|
|
195
211
|
}
|
|
196
212
|
|
|
197
213
|
/**
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {load} from '@loaders.gl/core';
|
|
1
|
+
import {load, fetchFile} from '@loaders.gl/core';
|
|
2
2
|
import {ZipLoader} from '@loaders.gl/zip';
|
|
3
3
|
import {writeFile} from '../lib/utils/file-utils';
|
|
4
4
|
import {join} from 'path';
|
|
5
5
|
|
|
6
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
|
+
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'beta';
|
|
8
|
+
|
|
6
9
|
const PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';
|
|
7
10
|
|
|
8
11
|
/**
|
|
@@ -15,8 +18,11 @@ export class DepsInstaller {
|
|
|
15
18
|
/**
|
|
16
19
|
* Run instalation
|
|
17
20
|
* @param path destination folder
|
|
21
|
+
* @param workersPath destination folder for workers.
|
|
22
|
+
* This path is '' by default and is not used by tile-converter.
|
|
23
|
+
* It is used in tests to prevent rewriting actual workers during tests running
|
|
18
24
|
*/
|
|
19
|
-
async install(path: string = ''): Promise<void> {
|
|
25
|
+
async install(path: string = '', workersPath: string = ''): Promise<void> {
|
|
20
26
|
console.log('Installing "EGM2008-5" model...'); // eslint-disable-line no-console
|
|
21
27
|
const fileMap = await load(PGM_LINK, ZipLoader, {});
|
|
22
28
|
|
|
@@ -27,6 +33,27 @@ export class DepsInstaller {
|
|
|
27
33
|
|
|
28
34
|
await writeFile(depsPath, new Uint8Array(fileMap['geoids/egm2008-5.pgm']), 'egm2008-5.pgm');
|
|
29
35
|
|
|
36
|
+
console.log('Installing "I3S Content Loader worker"'); // eslint-disable-line no-console
|
|
37
|
+
await this.installWorker('i3s', 'i3s-content-nodejs-worker.js', workersPath);
|
|
38
|
+
|
|
39
|
+
console.log('Installing "Draco Loader worker"'); // eslint-disable-line no-console
|
|
40
|
+
await this.installWorker('draco', 'draco-nodejs-worker.js', workersPath);
|
|
41
|
+
|
|
42
|
+
console.log('Installing "Basis Loader worker"'); // eslint-disable-line no-console
|
|
43
|
+
await this.installWorker('textures', 'basis-nodejs-worker.js', workersPath);
|
|
44
|
+
|
|
30
45
|
console.log('All dependencies were installed succesfully.'); // eslint-disable-line no-console
|
|
31
46
|
}
|
|
47
|
+
|
|
48
|
+
private async installWorker(module: string, name: string, extraPath: string) {
|
|
49
|
+
const fileResponse = await fetchFile(
|
|
50
|
+
`https://unpkg.com/@loaders.gl/${module}@${VERSION}/dist/${name}`
|
|
51
|
+
);
|
|
52
|
+
const fileData = await fileResponse.arrayBuffer();
|
|
53
|
+
if (!fileData) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const path = join(process.cwd(), extraPath, 'modules', module, 'dist');
|
|
57
|
+
await writeFile(path, fileData, name);
|
|
58
|
+
}
|
|
32
59
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {WorkerObject} from '@loaders.gl/worker-utils';
|
|
2
2
|
import type {ConvertedAttributes} from './i3s-converter/types';
|
|
3
3
|
import type {Matrix4, Vector3} from '@math.gl/core';
|
|
4
|
+
import type {GLTFImagePostprocessed, GLTFNodePostprocessed} from '@loaders.gl/gltf';
|
|
4
5
|
|
|
5
6
|
import {processOnWorker} from '@loaders.gl/worker-utils';
|
|
6
7
|
|
|
@@ -9,13 +10,16 @@ import {processOnWorker} from '@loaders.gl/worker-utils';
|
|
|
9
10
|
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
10
11
|
|
|
11
12
|
export type I3SAttributesWorkerOptions = {
|
|
13
|
+
_nodeWorkers: boolean;
|
|
14
|
+
reuseWorkers: boolean;
|
|
12
15
|
useCartesianPositions: boolean;
|
|
13
16
|
source: string;
|
|
14
17
|
};
|
|
15
18
|
|
|
16
19
|
export type B3DMAttributesData = {
|
|
17
20
|
gltfMaterials?: {id: string}[];
|
|
18
|
-
nodes:
|
|
21
|
+
nodes: GLTFNodePostprocessed[];
|
|
22
|
+
images: GLTFImagePostprocessed[];
|
|
19
23
|
cartographicOrigin: Vector3;
|
|
20
24
|
cartesianModelMatrix: Matrix4;
|
|
21
25
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
GLTFAccessorPostprocessed,
|
|
3
|
+
GLTFImagePostprocessed,
|
|
4
|
+
GLTFMeshPrimitivePostprocessed
|
|
5
|
+
} from '@loaders.gl/gltf';
|
|
3
6
|
import type {
|
|
4
7
|
GLTF_EXT_feature_metadata_attribute,
|
|
5
8
|
GLTF_EXT_feature_metadata_primitive
|
|
@@ -18,8 +21,8 @@ export function handleBatchIdsExtensions(
|
|
|
18
21
|
attributes: {
|
|
19
22
|
[key: string]: GLTFAccessorPostprocessed;
|
|
20
23
|
},
|
|
21
|
-
primitive:
|
|
22
|
-
images:
|
|
24
|
+
primitive: GLTFMeshPrimitivePostprocessed,
|
|
25
|
+
images: GLTFImagePostprocessed[]
|
|
23
26
|
): number[] {
|
|
24
27
|
const extensions = primitive?.extensions;
|
|
25
28
|
|
|
@@ -58,7 +61,7 @@ function handleExtFeatureMetadataExtension(
|
|
|
58
61
|
[key: string]: GLTFAccessorPostprocessed;
|
|
59
62
|
},
|
|
60
63
|
extFeatureMetadata: GLTF_EXT_feature_metadata_primitive,
|
|
61
|
-
images:
|
|
64
|
+
images: GLTFImagePostprocessed[]
|
|
62
65
|
): number[] {
|
|
63
66
|
// Take only first extension object to get batchIds attribute name.
|
|
64
67
|
const featureIdAttribute = extFeatureMetadata?.featureIdAttributes?.[0];
|
|
@@ -149,8 +152,12 @@ function generateImplicitFeatureIds(
|
|
|
149
152
|
function generateBatchIdsFromTexture(
|
|
150
153
|
featureIdTexture: GLTF_EXT_feature_metadata_attribute,
|
|
151
154
|
textureCoordinates: Float32Array,
|
|
152
|
-
images:
|
|
155
|
+
images: GLTFImagePostprocessed[]
|
|
153
156
|
) {
|
|
157
|
+
if (!images?.length) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
|
|
154
161
|
const CHANNELS_MAP = {
|
|
155
162
|
r: 0,
|
|
156
163
|
g: 1,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
makeBoundingSphereFromPoints,
|
|
9
9
|
BoundingSphere
|
|
10
10
|
} from '@math.gl/culling';
|
|
11
|
-
import
|
|
11
|
+
import {Tile3D} from '@loaders.gl/tiles';
|
|
12
12
|
import {Geoid} from '@math.gl/geoid';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -17,7 +17,7 @@ import {Geoid} from '@math.gl/geoid';
|
|
|
17
17
|
* @param geoidHeightModel
|
|
18
18
|
* @returns - Bounding volumes object
|
|
19
19
|
*/
|
|
20
|
-
export function createBoundingVolumes(tile:
|
|
20
|
+
export function createBoundingVolumes(tile: Tile3D, geoidHeightModel: Geoid): BoundingVolumes {
|
|
21
21
|
let radius;
|
|
22
22
|
let halfSize;
|
|
23
23
|
let quaternion;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type {FeatureTableJson} from '@loaders.gl/3d-tiles';
|
|
2
|
+
import {
|
|
3
|
+
Attribute,
|
|
4
|
+
AttributeStorageInfo,
|
|
5
|
+
ESRIField,
|
|
6
|
+
Field,
|
|
7
|
+
FieldInfo,
|
|
8
|
+
PopupInfo
|
|
9
|
+
} from '@loaders.gl/i3s';
|
|
2
10
|
|
|
3
11
|
/**
|
|
4
12
|
* Takes attributes from property table based on featureIds.
|
|
@@ -63,3 +71,177 @@ export function checkPropertiesLength(
|
|
|
63
71
|
|
|
64
72
|
return needFlatten;
|
|
65
73
|
}
|
|
74
|
+
|
|
75
|
+
/** String data type name for feature attributes */
|
|
76
|
+
const STRING_TYPE = 'string';
|
|
77
|
+
/** Integer data type name for feature attributes */
|
|
78
|
+
const SHORT_INT_TYPE = 'Int32';
|
|
79
|
+
/** Double data type name for feature attributes */
|
|
80
|
+
const DOUBLE_TYPE = 'double';
|
|
81
|
+
/** Type of attribute that is linked with feature ids */
|
|
82
|
+
const OBJECT_ID_TYPE = 'OBJECTID';
|
|
83
|
+
/**
|
|
84
|
+
* Get the attribute type for attributeStorageInfo https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md
|
|
85
|
+
* @param key - attribute's key
|
|
86
|
+
* @param attribute - attribute's type in propertyTable
|
|
87
|
+
*/
|
|
88
|
+
export function getAttributeType(key: string, attribute: string): string {
|
|
89
|
+
if (key === OBJECT_ID_TYPE) {
|
|
90
|
+
return OBJECT_ID_TYPE;
|
|
91
|
+
}
|
|
92
|
+
if (typeof attribute === STRING_TYPE) {
|
|
93
|
+
return STRING_TYPE;
|
|
94
|
+
} else if (typeof attribute === 'number') {
|
|
95
|
+
return Number.isInteger(attribute) ? SHORT_INT_TYPE : DOUBLE_TYPE;
|
|
96
|
+
}
|
|
97
|
+
return STRING_TYPE;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Generate storage attribute for map segmentation.
|
|
102
|
+
* @param attributeIndex - order index of attribute (f_0, f_1 ...).
|
|
103
|
+
* @param key - attribute key from propertyTable.
|
|
104
|
+
* @param attributeType - attribute type.
|
|
105
|
+
* @return Updated storageAttribute.
|
|
106
|
+
*/
|
|
107
|
+
export function createdStorageAttribute(
|
|
108
|
+
attributeIndex: number,
|
|
109
|
+
key: string,
|
|
110
|
+
attributeType: Attribute
|
|
111
|
+
): AttributeStorageInfo {
|
|
112
|
+
const storageAttribute = {
|
|
113
|
+
key: `f_${attributeIndex}`,
|
|
114
|
+
name: key,
|
|
115
|
+
ordering: ['attributeValues'],
|
|
116
|
+
header: [{property: 'count', valueType: 'UInt32'}],
|
|
117
|
+
attributeValues: {valueType: 'Int32', valuesPerElement: 1}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
switch (attributeType) {
|
|
121
|
+
case OBJECT_ID_TYPE:
|
|
122
|
+
setupIdAttribute(storageAttribute);
|
|
123
|
+
break;
|
|
124
|
+
case STRING_TYPE:
|
|
125
|
+
setupStringAttribute(storageAttribute);
|
|
126
|
+
break;
|
|
127
|
+
case DOUBLE_TYPE:
|
|
128
|
+
setupDoubleAttribute(storageAttribute);
|
|
129
|
+
break;
|
|
130
|
+
case SHORT_INT_TYPE:
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
setupStringAttribute(storageAttribute);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return storageAttribute;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Find and return attribute type based on key form propertyTable.
|
|
141
|
+
* @param attributeType
|
|
142
|
+
*/
|
|
143
|
+
export function getFieldAttributeType(attributeType: Attribute): ESRIField {
|
|
144
|
+
switch (attributeType) {
|
|
145
|
+
case OBJECT_ID_TYPE:
|
|
146
|
+
return 'esriFieldTypeOID';
|
|
147
|
+
case STRING_TYPE:
|
|
148
|
+
return 'esriFieldTypeString';
|
|
149
|
+
case SHORT_INT_TYPE:
|
|
150
|
+
return 'esriFieldTypeInteger';
|
|
151
|
+
case DOUBLE_TYPE:
|
|
152
|
+
return 'esriFieldTypeDouble';
|
|
153
|
+
default:
|
|
154
|
+
return 'esriFieldTypeString';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Setup field attribute for map segmentation.
|
|
160
|
+
* @param key - attribute for map segmentation.
|
|
161
|
+
* @param fieldAttributeType - esri attribute type ('esriFieldTypeString' or 'esriFieldTypeOID').
|
|
162
|
+
*/
|
|
163
|
+
export function createFieldAttribute(key: string, fieldAttributeType: ESRIField): Field {
|
|
164
|
+
return {
|
|
165
|
+
name: key,
|
|
166
|
+
type: fieldAttributeType,
|
|
167
|
+
alias: key
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Generate popup info to show metadata on the map.
|
|
173
|
+
* @param propertyTable - table data with OBJECTID.
|
|
174
|
+
* @return data for correct rendering of popup.
|
|
175
|
+
*/
|
|
176
|
+
export function createPopupInfo(propertyTable: FeatureTableJson): PopupInfo {
|
|
177
|
+
const title = '{OBJECTID}';
|
|
178
|
+
const mediaInfos = [];
|
|
179
|
+
const fieldInfos: FieldInfo[] = [];
|
|
180
|
+
const popupElements: {
|
|
181
|
+
fieldInfos: FieldInfo[];
|
|
182
|
+
type: string;
|
|
183
|
+
}[] = [];
|
|
184
|
+
const expressionInfos = [];
|
|
185
|
+
|
|
186
|
+
for (const key in propertyTable) {
|
|
187
|
+
fieldInfos.push({
|
|
188
|
+
fieldName: key,
|
|
189
|
+
visible: true,
|
|
190
|
+
isEditable: false,
|
|
191
|
+
label: key
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
popupElements.push({
|
|
195
|
+
fieldInfos,
|
|
196
|
+
type: 'fields'
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
title,
|
|
201
|
+
mediaInfos,
|
|
202
|
+
popupElements,
|
|
203
|
+
fieldInfos,
|
|
204
|
+
expressionInfos
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Setup storage attribute as string.
|
|
210
|
+
* @param storageAttribute - attribute for map segmentation.
|
|
211
|
+
*/
|
|
212
|
+
function setupStringAttribute(storageAttribute: AttributeStorageInfo): void {
|
|
213
|
+
// @ts-expect-error
|
|
214
|
+
storageAttribute.ordering.unshift('attributeByteCounts');
|
|
215
|
+
storageAttribute.header.push({property: 'attributeValuesByteCount', valueType: 'UInt32'});
|
|
216
|
+
storageAttribute.attributeValues = {
|
|
217
|
+
valueType: 'String',
|
|
218
|
+
encoding: 'UTF-8',
|
|
219
|
+
valuesPerElement: 1
|
|
220
|
+
};
|
|
221
|
+
storageAttribute.attributeByteCounts = {
|
|
222
|
+
valueType: 'UInt32',
|
|
223
|
+
valuesPerElement: 1
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Setup Id attribute for map segmentation.
|
|
229
|
+
* @param storageAttribute - attribute for map segmentation .
|
|
230
|
+
*/
|
|
231
|
+
function setupIdAttribute(storageAttribute: AttributeStorageInfo): void {
|
|
232
|
+
storageAttribute.attributeValues = {
|
|
233
|
+
valueType: 'Oid32',
|
|
234
|
+
valuesPerElement: 1
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Setup double attribute for map segmentation.
|
|
240
|
+
* @param storageAttribute - attribute for map segmentation .
|
|
241
|
+
*/
|
|
242
|
+
function setupDoubleAttribute(storageAttribute: AttributeStorageInfo): void {
|
|
243
|
+
storageAttribute.attributeValues = {
|
|
244
|
+
valueType: 'Float64',
|
|
245
|
+
valuesPerElement: 1
|
|
246
|
+
};
|
|
247
|
+
}
|