@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
|
@@ -23,6 +23,7 @@ var _fileUtils = require("../lib/utils/file-utils");
|
|
|
23
23
|
|
|
24
24
|
var _path = require("path");
|
|
25
25
|
|
|
26
|
+
var VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'beta';
|
|
26
27
|
var PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';
|
|
27
28
|
|
|
28
29
|
var DepsInstaller = function () {
|
|
@@ -35,6 +36,7 @@ var DepsInstaller = function () {
|
|
|
35
36
|
value: function () {
|
|
36
37
|
var _install = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee() {
|
|
37
38
|
var path,
|
|
39
|
+
workersPath,
|
|
38
40
|
fileMap,
|
|
39
41
|
depsPath,
|
|
40
42
|
_args = arguments;
|
|
@@ -43,11 +45,12 @@ var DepsInstaller = function () {
|
|
|
43
45
|
switch (_context.prev = _context.next) {
|
|
44
46
|
case 0:
|
|
45
47
|
path = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
|
|
48
|
+
workersPath = _args.length > 1 && _args[1] !== undefined ? _args[1] : '';
|
|
46
49
|
console.log('Installing "EGM2008-5" model...');
|
|
47
|
-
_context.next =
|
|
50
|
+
_context.next = 5;
|
|
48
51
|
return (0, _core.load)(PGM_LINK, _zip.ZipLoader, {});
|
|
49
52
|
|
|
50
|
-
case
|
|
53
|
+
case 5:
|
|
51
54
|
fileMap = _context.sent;
|
|
52
55
|
depsPath = process.cwd();
|
|
53
56
|
|
|
@@ -55,18 +58,33 @@ var DepsInstaller = function () {
|
|
|
55
58
|
depsPath = (0, _path.join)(depsPath, path);
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
_context.next =
|
|
61
|
+
_context.next = 10;
|
|
59
62
|
return (0, _fileUtils.writeFile)(depsPath, new Uint8Array(fileMap['geoids/egm2008-5.pgm']), 'egm2008-5.pgm');
|
|
60
63
|
|
|
61
|
-
case
|
|
64
|
+
case 10:
|
|
65
|
+
console.log('Installing "I3S Content Loader worker"');
|
|
66
|
+
_context.next = 13;
|
|
67
|
+
return this.installWorker('i3s', 'i3s-content-nodejs-worker.js', workersPath);
|
|
68
|
+
|
|
69
|
+
case 13:
|
|
70
|
+
console.log('Installing "Draco Loader worker"');
|
|
71
|
+
_context.next = 16;
|
|
72
|
+
return this.installWorker('draco', 'draco-nodejs-worker.js', workersPath);
|
|
73
|
+
|
|
74
|
+
case 16:
|
|
75
|
+
console.log('Installing "Basis Loader worker"');
|
|
76
|
+
_context.next = 19;
|
|
77
|
+
return this.installWorker('textures', 'basis-nodejs-worker.js', workersPath);
|
|
78
|
+
|
|
79
|
+
case 19:
|
|
62
80
|
console.log('All dependencies were installed succesfully.');
|
|
63
81
|
|
|
64
|
-
case
|
|
82
|
+
case 20:
|
|
65
83
|
case "end":
|
|
66
84
|
return _context.stop();
|
|
67
85
|
}
|
|
68
86
|
}
|
|
69
|
-
}, _callee);
|
|
87
|
+
}, _callee, this);
|
|
70
88
|
}));
|
|
71
89
|
|
|
72
90
|
function install() {
|
|
@@ -75,6 +93,52 @@ var DepsInstaller = function () {
|
|
|
75
93
|
|
|
76
94
|
return install;
|
|
77
95
|
}()
|
|
96
|
+
}, {
|
|
97
|
+
key: "installWorker",
|
|
98
|
+
value: function () {
|
|
99
|
+
var _installWorker = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(module, name, extraPath) {
|
|
100
|
+
var fileResponse, fileData, path;
|
|
101
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
102
|
+
while (1) {
|
|
103
|
+
switch (_context2.prev = _context2.next) {
|
|
104
|
+
case 0:
|
|
105
|
+
_context2.next = 2;
|
|
106
|
+
return (0, _core.fetchFile)("https://unpkg.com/@loaders.gl/".concat(module, "@").concat(VERSION, "/dist/").concat(name));
|
|
107
|
+
|
|
108
|
+
case 2:
|
|
109
|
+
fileResponse = _context2.sent;
|
|
110
|
+
_context2.next = 5;
|
|
111
|
+
return fileResponse.arrayBuffer();
|
|
112
|
+
|
|
113
|
+
case 5:
|
|
114
|
+
fileData = _context2.sent;
|
|
115
|
+
|
|
116
|
+
if (fileData) {
|
|
117
|
+
_context2.next = 8;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return _context2.abrupt("return");
|
|
122
|
+
|
|
123
|
+
case 8:
|
|
124
|
+
path = (0, _path.join)(process.cwd(), extraPath, 'modules', module, 'dist');
|
|
125
|
+
_context2.next = 11;
|
|
126
|
+
return (0, _fileUtils.writeFile)(path, fileData, name);
|
|
127
|
+
|
|
128
|
+
case 11:
|
|
129
|
+
case "end":
|
|
130
|
+
return _context2.stop();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}, _callee2);
|
|
134
|
+
}));
|
|
135
|
+
|
|
136
|
+
function installWorker(_x, _x2, _x3) {
|
|
137
|
+
return _installWorker.apply(this, arguments);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return installWorker;
|
|
141
|
+
}()
|
|
78
142
|
}]);
|
|
79
143
|
return DepsInstaller;
|
|
80
144
|
}();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/deps-installer/deps-installer.ts"],"names":["PGM_LINK","DepsInstaller","path","console","log","ZipLoader","fileMap","depsPath","process","cwd","Uint8Array"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["../../../src/deps-installer/deps-installer.ts"],"names":["VERSION","PGM_LINK","DepsInstaller","path","workersPath","console","log","ZipLoader","fileMap","depsPath","process","cwd","Uint8Array","installWorker","module","name","extraPath","fileResponse","arrayBuffer","fileData"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAGA,IAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,MAAnE;AAEA,IAAMC,QAAQ,GAAG,+EAAjB;;IAQaC,a;;;;;;;;+EAQX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAcC,gBAAAA,IAAd,2DAA6B,EAA7B;AAAiCC,gBAAAA,WAAjC,2DAAuD,EAAvD;AACEC,gBAAAA,OAAO,CAACC,GAAR,CAAY,iCAAZ;AADF;AAAA,uBAEwB,gBAAKL,QAAL,EAAeM,cAAf,EAA0B,EAA1B,CAFxB;;AAAA;A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CF,MAA1C,EAAkD,MAAlD,CARf;AAAA;AAAA,uBASQ,0BAAUX,IAAV,EAAgBgB,QAAhB,EAA0BJ,IAA1B,CATR;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O","sourcesContent":["import {load, fetchFile} from '@loaders.gl/core';\nimport {ZipLoader} from '@loaders.gl/zip';\nimport {writeFile} from '../lib/utils/file-utils';\nimport {join} from 'path';\n\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'beta';\n\nconst PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';\n\n/**\n * Install external dependencies for converter:\n * * PGM file (implemented);\n * * Draco library (not implemented);\n * * 7z archiver (not implemented);\n */\nexport class DepsInstaller {\n /**\n * Run instalation\n * @param path destination folder\n * @param workersPath destination folder for workers.\n * This path is '' by default and is not used by tile-converter.\n * It is used in tests to prevent rewriting actual workers during tests running\n */\n async install(path: string = '', workersPath: string = ''): Promise<void> {\n console.log('Installing \"EGM2008-5\" model...'); // eslint-disable-line no-console\n const fileMap = await load(PGM_LINK, ZipLoader, {});\n\n let depsPath = process.cwd();\n if (path) {\n depsPath = join(depsPath, path);\n }\n\n await writeFile(depsPath, new Uint8Array(fileMap['geoids/egm2008-5.pgm']), 'egm2008-5.pgm');\n\n console.log('Installing \"I3S Content Loader worker\"'); // eslint-disable-line no-console\n await this.installWorker('i3s', 'i3s-content-nodejs-worker.js', workersPath);\n\n console.log('Installing \"Draco Loader worker\"'); // eslint-disable-line no-console\n await this.installWorker('draco', 'draco-nodejs-worker.js', workersPath);\n\n console.log('Installing \"Basis Loader worker\"'); // eslint-disable-line no-console\n await this.installWorker('textures', 'basis-nodejs-worker.js', workersPath);\n\n console.log('All dependencies were installed succesfully.'); // eslint-disable-line no-console\n }\n\n private async installWorker(module: string, name: string, extraPath: string) {\n const fileResponse = await fetchFile(\n `https://unpkg.com/@loaders.gl/${module}@${VERSION}/dist/${name}`\n );\n const fileData = await fileResponse.arrayBuffer();\n if (!fileData) {\n return;\n }\n const path = join(process.cwd(), extraPath, 'modules', module, 'dist');\n await writeFile(path, fileData, name);\n }\n}\n"],"file":"deps-installer.js"}
|
|
@@ -8,7 +8,7 @@ exports._typecheckI3SAttributesWorker = exports.I3SAttributesWorker = void 0;
|
|
|
8
8
|
|
|
9
9
|
var _workerUtils = require("@loaders.gl/worker-utils");
|
|
10
10
|
|
|
11
|
-
var VERSION = typeof "3.3.0-alpha.
|
|
11
|
+
var VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'latest';
|
|
12
12
|
var I3SAttributesWorker = {
|
|
13
13
|
id: 'i3s-attributes',
|
|
14
14
|
name: 'I3S Attributes Worker',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/i3s-attributes-worker.ts"],"names":["VERSION","I3SAttributesWorker","id","name","module","version","options","useCartesianPositions","transformI3SAttributesOnWorker","attributesData","_typecheckI3SAttributesWorker"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/i3s-attributes-worker.ts"],"names":["VERSION","I3SAttributesWorker","id","name","module","version","options","useCartesianPositions","transformI3SAttributesOnWorker","attributesData","_typecheckI3SAttributesWorker"],"mappings":";;;;;;;;AAKA;;AAIA,IAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAoBO,IAAMC,mBAAmB,GAAG;AACjCC,EAAAA,EAAE,EAAE,gBAD6B;AAEjCC,EAAAA,IAAI,EAAE,uBAF2B;AAGjCC,EAAAA,MAAM,EAAE,gBAHyB;AAIjCC,EAAAA,OAAO,EAAEL,OAJwB;AAKjCM,EAAAA,OAAO,EAAE;AACPC,IAAAA,qBAAqB,EAAE;AADhB;AALwB,CAA5B;;;AAaA,SAASC,8BAAT,CACLC,cADK,EAELH,OAFK,EAGsC;AAC3C,SAAO,kCAAgBL,mBAAhB,EAAqCQ,cAArC,EAAqDH,OAArD,CAAP;AACD;;AAEM,IAAMI,6BAA2C,GAAGT,mBAApD","sourcesContent":["import type {WorkerObject} from '@loaders.gl/worker-utils';\nimport type {ConvertedAttributes} from './i3s-converter/types';\nimport type {Matrix4, Vector3} from '@math.gl/core';\nimport type {GLTFImagePostprocessed, GLTFNodePostprocessed} from '@loaders.gl/gltf';\n\nimport {processOnWorker} from '@loaders.gl/worker-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type I3SAttributesWorkerOptions = {\n _nodeWorkers: boolean;\n reuseWorkers: boolean;\n useCartesianPositions: boolean;\n source: string;\n};\n\nexport type B3DMAttributesData = {\n gltfMaterials?: {id: string}[];\n nodes: GLTFNodePostprocessed[];\n images: GLTFImagePostprocessed[];\n cartographicOrigin: Vector3;\n cartesianModelMatrix: Matrix4;\n};\n\n/**\n * I3S Attributes Worker to handle B3DM object\n */\nexport const I3SAttributesWorker = {\n id: 'i3s-attributes',\n name: 'I3S Attributes Worker',\n module: 'tile-converter',\n version: VERSION,\n options: {\n useCartesianPositions: false\n }\n};\n\n/**\n * Performs I3S attributes transformation\n */\nexport function transformI3SAttributesOnWorker(\n attributesData: B3DMAttributesData,\n options: I3SAttributesWorkerOptions\n): Promise<Map<string, ConvertedAttributes>> {\n return processOnWorker(I3SAttributesWorker, attributesData, options);\n}\n\nexport const _typecheckI3SAttributesWorker: WorkerObject = I3SAttributesWorker;\n"],"file":"i3s-attributes-worker.js"}
|
|
@@ -106,6 +106,10 @@ function generateImplicitFeatureIds(featuresCount) {
|
|
|
106
106
|
function generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images) {
|
|
107
107
|
var _featureIdTexture$fea3, _featureIdTexture$fea4, _featureIdTexture$fea5;
|
|
108
108
|
|
|
109
|
+
if (!(images !== null && images !== void 0 && images.length)) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
|
|
109
113
|
var CHANNELS_MAP = {
|
|
110
114
|
r: 0,
|
|
111
115
|
g: 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/i3s-converter/helpers/batch-ids-extensions.ts"],"names":["EXT_MESH_FEATURES","EXT_FEATURE_METADATA","handleBatchIdsExtensions","attributes","primitive","images","extensions","Object","entries","extensionName","extensionData","handleExtFeatureMetadataExtension","console","warn","extFeatureMetadata","featureIdAttribute","featureIdAttributes","featureIds","attribute","batchIdsAttribute","value","hasOwnProperty","featuresCount","POSITIONS","length","generateImplicitFeatureIds","constant","divisor","featureIdTexture","featureIdTextures","textureAttributeIndex","texture","texCoord","textCoordAttribute","textureCoordinates","generateBatchIdsFromTexture","featureTexture","featureTextures","currentValue","devisorCounter","index","push","Array","fill","CHANNELS_MAP","r","g","b","a","textureIndex","featureChannel","channels","undefined","image","batchIds","compressed","u","v","tx","Math","min","emod","width","ty","height","offset","components","batchId","Uint8Array","data","mimeType","n"],"mappings":";;;;;;;;;;;AAOA,IAAMA,iBAAiB,GAAG,mBAA1B;AACA,IAAMC,oBAAoB,GAAG,sBAA7B;;AAQO,SAASC,wBAAT,CACLC,UADK,EAILC,SAJK,EAKLC,MALK,EAMK;AACV,MAAMC,UAAU,GAAGF,SAAH,aAAGA,SAAH,uBAAGA,SAAS,CAAEE,UAA9B;;AAEA,MAAI,CAACA,UAAL,EAAiB;AACf,WAAO,EAAP;AACD;;AAED,qCAA6CC,MAAM,CAACC,OAAP,CAAeF,UAAU,IAAI,EAA7B,CAA7C,qCAA+E;AAA1E;AAAA,QAAOG,aAAP;AAAA,QAAsBC,aAAtB;;AACH,YAAQD,aAAR;AACE,WAAKR,oBAAL;AACE,eAAOU,iCAAiC,CACtCR,UADsC,EAEtCO,aAFsC,EAGtCL,MAHsC,CAAxC;;AAKF,WAAKL,iBAAL;AACEY,QAAAA,OAAO,CAACC,IAAR,CAAa,kDAAb;AACA,eAAO,EA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,KAAN,GAAc,CAApD,CAAX;AACA,UAAMC,EAAE,GAAGJ,IAAI,CAACC,GAAL,CAAUC,IAAI,CAACJ,CAAD,CAAJ,GAAUJ,KAAK,CAACW,MAAjB,GAA2B,CAApC,EAAuCX,KAAK,CAACW,MAAN,GAAe,CAAtD,CAAX;AAEA,UAAMC,MAAM,GAAG,CAACF,EAAE,GAAGV,KAAK,CAACS,KAAX,GAAmBJ,EAApB,IAA0BL,KAAK,CAACa,UAAhC,GAA6Cf,QAA5D;AACA,UAAMgB,OAAO,GAAG,IAAIC,UAAJ,CAAef,KAAK,CAACgB,IAArB,EAA2BJ,MAA3B,CAAhB;AAEAX,MAAAA,QAAQ,CAACb,IAAT,CAAc0B,OAAd;AACD;AACF,GAbD,MAaO;AACLvD,IAAAA,OAAO,CAACC,IAAR,oCAAyCwC,KAAK,CAACiB,QAA/C;AACD;;AAED,SAAOhB,QAAP;AACD;;AAOD,SAASO,IAAT,CAAcU,CAAd,EAAiC;AAC/B,SAAO,CAAEA,CAAC,GAAG,CAAL,GAAU,CAAX,IAAgB,CAAvB;AACD","sourcesContent":["import type {GLTFAccessorPostprocessed} from 'modules/gltf/src/lib/types/gltf-types';\nimport type {Image, MeshPrimitive} from 'modules/gltf/src/lib/types/gltf-postprocessed-schema';\nimport type {\n GLTF_EXT_feature_metadata_attribute,\n GLTF_EXT_feature_metadata_primitive\n} from 'modules/gltf/src/lib/types/gltf-json-schema';\n\nconst EXT_MESH_FEATURES = 'EXT_mesh_features';\nconst EXT_FEATURE_METADATA = 'EXT_feature_metadata';\n\n/**\n * Getting batchIds from 3DTilesNext extensions.\n * @param attributes\n * @param primitive\n * @param textures\n */\nexport function handleBatchIdsExtensions(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n primitive: MeshPrimitive,\n images: Image[]\n): number[] {\n const extensions = primitive?.extensions;\n\n if (!extensions) {\n return [];\n }\n\n for (const [extensionName, extensionData] of Object.entries(extensions || {})) {\n switch (extensionName) {\n case EXT_FEATURE_METADATA:\n return handleExtFeatureMetadataExtension(\n attributes,\n extensionData as GLTF_EXT_feature_metadata_primitive,\n images\n );\n case EXT_MESH_FEATURES:\n console.warn('EXT_mesh_features extension is not supported yet');\n return [];\n default:\n return [];\n }\n }\n\n return [];\n}\n\n/**\n * Get batchIds from EXT_feature_metadata extension.\n * Docs - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata\n * @param attributes\n * @param extFeatureMetadata\n * @param textures\n */\nfunction handleExtFeatureMetadataExtension(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n extFeatureMetadata: GLTF_EXT_feature_metadata_primitive,\n images: Image[]\n): number[] {\n // Take only first extension object to get batchIds attribute name.\n const featureIdAttribute = extFeatureMetadata?.featureIdAttributes?.[0];\n\n if (featureIdAttribute?.featureIds?.attribute) {\n const batchIdsAttribute = attributes[featureIdAttribute.featureIds.attribute];\n return batchIdsAttribute.value;\n }\n\n if (\n featureIdAttribute?.featureIds?.hasOwnProperty('constant') &&\n featureIdAttribute?.featureIds?.hasOwnProperty('divisor')\n ) {\n const featuresCount = attributes?.POSITIONS?.value.length / 3 || 0;\n return generateImplicitFeatureIds(\n featuresCount,\n featureIdAttribute.featureIds.constant,\n featureIdAttribute.featureIds.divisor\n );\n }\n\n // Take only first extension object to get batchIds attribute name.\n const featureIdTexture =\n extFeatureMetadata?.featureIdTextures && extFeatureMetadata?.featureIdTextures[0];\n\n if (featureIdTexture) {\n const textureAttributeIndex = featureIdTexture?.featureIds?.texture?.texCoord || 0;\n const textCoordAttribute = `TEXCOORD_${textureAttributeIndex}`;\n const textureCoordinates = attributes[textCoordAttribute].value;\n return generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images);\n }\n\n // Take only first extension texture to get batchIds from the root EXT_feature_metadata object.\n const featureTexture =\n extFeatureMetadata?.featureTextures && extFeatureMetadata?.featureTextures[0];\n\n /**\n * TODO need to get batchIds from root extension\n */\n if (featureTexture) {\n console.warn(\"EXT_feature_metadata doesn't yet support featureTextures in primitive\");\n return [];\n }\n\n return [];\n}\n\n/**\n * Generates implicit feature ids\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#implicit-feature-ids\n * @param featuresCount\n * @param constant\n * @param devisor\n */\nfunction generateImplicitFeatureIds(\n featuresCount: number,\n constant: number = 0,\n divisor: number = 0\n): number[] {\n let featureIds: number[] = [];\n\n if (divisor > 0) {\n let currentValue = constant;\n let devisorCounter = divisor;\n\n for (let index = 0; index < featuresCount; index++) {\n featureIds.push(currentValue);\n\n devisorCounter -= 1;\n\n if (devisorCounter === 0) {\n currentValue++;\n devisorCounter = divisor;\n }\n }\n } else {\n featureIds = Array<number>(featuresCount).fill(constant, 0, featuresCount);\n }\n\n return featureIds;\n}\n\n/**\n * Get batchIds from texture.\n * @param primitive\n * @param featureIdTextures\n */\nfunction generateBatchIdsFromTexture(\n featureIdTexture: GLTF_EXT_feature_metadata_attribute,\n textureCoordinates: Float32Array,\n images: Image[]\n) {\n const CHANNELS_MAP = {\n r: 0,\n g: 1,\n b: 2,\n a: 3\n };\n\n const textureIndex = featureIdTexture?.featureIds?.texture?.index;\n const featureChannel = featureIdTexture?.featureIds?.channels;\n\n if (!featureChannel || textureIndex === undefined) {\n return [];\n }\n\n const image = images[textureIndex];\n const batchIds: number[] = [];\n const channels = CHANNELS_MAP[featureChannel];\n\n if (!image.compressed) {\n for (let index = 0; index < textureCoordinates.length; index += 2) {\n const u = textureCoordinates[index];\n const v = textureCoordinates[index + 1];\n\n const tx = Math.min((emod(u) * image.width) | 0, image.width - 1);\n const ty = Math.min((emod(v) * image.height) | 0, image.height - 1);\n\n const offset = (ty * image.width + tx) * image.components + channels;\n const batchId = new Uint8Array(image.data)[offset];\n\n batchIds.push(batchId);\n }\n } else {\n console.warn(`Can't get batch Ids from ${image.mimeType} compressed texture`);\n }\n\n return batchIds;\n}\n\n/**\n * Handle UVs if they are out of range [0,1].\n * @param n\n * @param m\n */\nfunction emod(n: number): number {\n return ((n % 1) + 1) % 1;\n}\n"],"file":"batch-ids-extensions.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/batch-ids-extensions.ts"],"names":["EXT_MESH_FEATURES","EXT_FEATURE_METADATA","handleBatchIdsExtensions","attributes","primitive","images","extensions","Object","entries","extensionName","extensionData","handleExtFeatureMetadataExtension","console","warn","extFeatureMetadata","featureIdAttribute","featureIdAttributes","featureIds","attribute","batchIdsAttribute","value","hasOwnProperty","featuresCount","POSITIONS","length","generateImplicitFeatureIds","constant","divisor","featureIdTexture","featureIdTextures","textureAttributeIndex","texture","texCoord","textCoordAttribute","textureCoordinates","generateBatchIdsFromTexture","featureTexture","featureTextures","currentValue","devisorCounter","index","push","Array","fill","CHANNELS_MAP","r","g","b","a","textureIndex","featureChannel","channels","undefined","image","batchIds","compressed","u","v","tx","Math","min","emod","width","ty","height","offset","components","batchId","Uint8Array","data","mimeType","n"],"mappings":";;;;;;;;;;;AAUA,IAAMA,iBAAiB,GAAG,mBAA1B;AACA,IAAMC,oBAAoB,GAAG,sBAA7B;;AAQO,SAASC,wBAAT,CACLC,UADK,EAILC,SAJK,EAKLC,MALK,EAMK;AACV,MAAMC,UAAU,GAAGF,SAAH,aAAGA,SAAH,uBAAGA,SAAS,CAAEE,UAA9B;;AAEA,MAAI,CAACA,UAAL,EAAiB;AACf,WAAO,EAAP;AACD;;AAED,qCAA6CC,MAAM,CAACC,OAAP,CAAeF,UAAU,IAAI,EAA7B,CAA7C,qCAA+E;AAA1E;AAAA,QAAOG,aAAP;AAAA,QAAsBC,aAAtB;;AACH,YAAQD,aAAR;AACE,WAAKR,oBAAL;AACE,eAAOU,iCAAiC,CACtCR,UADsC,EAEtCO,aAFsC,EAGtCL,MAHsC,CAAxC;;AAKF,WAAKL,iBAAL;AACEY,QAAAA,OAAO,CAACC,IAAR,CAAa,kDAAb;AACA,eAAO,EAAP;;AACF;AACE,eAAO,EAAP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,CAAD,CAAJ,GAAUH,KAAK,CAACS,KAAjB,GAA0B,CAAnC,EAAsCT,KAAK,CAACS,KAAN,GAAc,CAApD,CAAX;AACA,UAAMC,EAAE,GAAGJ,IAAI,CAACC,GAAL,CAAUC,IAAI,CAACJ,CAAD,CAAJ,GAAUJ,KAAK,CAACW,MAAjB,GAA2B,CAApC,EAAuCX,KAAK,CAACW,MAAN,GAAe,CAAtD,CAAX;AAEA,UAAMC,MAAM,GAAG,CAACF,EAAE,GAAGV,KAAK,CAACS,KAAX,GAAmBJ,EAApB,IAA0BL,KAAK,CAACa,UAAhC,GAA6Cf,QAA5D;AACA,UAAMgB,OAAO,GAAG,IAAIC,UAAJ,CAAef,KAAK,CAACgB,IAArB,EAA2BJ,MAA3B,CAAhB;AAEAX,MAAAA,QAAQ,CAACb,IAAT,CAAc0B,OAAd;AACD;AACF,GAbD,MAaO;AACLvD,IAAAA,OAAO,CAACC,IAAR,oCAAyCwC,KAAK,CAACiB,QAA/C;AACD;;AAED,SAAOhB,QAAP;AACD;;AAOD,SAASO,IAAT,CAAcU,CAAd,EAAiC;AAC/B,SAAO,CAAEA,CAAC,GAAG,CAAL,GAAU,CAAX,IAAgB,CAAvB;AACD","sourcesContent":["import {\n GLTFAccessorPostprocessed,\n GLTFImagePostprocessed,\n GLTFMeshPrimitivePostprocessed\n} from '@loaders.gl/gltf';\nimport type {\n GLTF_EXT_feature_metadata_attribute,\n GLTF_EXT_feature_metadata_primitive\n} from 'modules/gltf/src/lib/types/gltf-json-schema';\n\nconst EXT_MESH_FEATURES = 'EXT_mesh_features';\nconst EXT_FEATURE_METADATA = 'EXT_feature_metadata';\n\n/**\n * Getting batchIds from 3DTilesNext extensions.\n * @param attributes\n * @param primitive\n * @param textures\n */\nexport function handleBatchIdsExtensions(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n primitive: GLTFMeshPrimitivePostprocessed,\n images: GLTFImagePostprocessed[]\n): number[] {\n const extensions = primitive?.extensions;\n\n if (!extensions) {\n return [];\n }\n\n for (const [extensionName, extensionData] of Object.entries(extensions || {})) {\n switch (extensionName) {\n case EXT_FEATURE_METADATA:\n return handleExtFeatureMetadataExtension(\n attributes,\n extensionData as GLTF_EXT_feature_metadata_primitive,\n images\n );\n case EXT_MESH_FEATURES:\n console.warn('EXT_mesh_features extension is not supported yet');\n return [];\n default:\n return [];\n }\n }\n\n return [];\n}\n\n/**\n * Get batchIds from EXT_feature_metadata extension.\n * Docs - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata\n * @param attributes\n * @param extFeatureMetadata\n * @param textures\n */\nfunction handleExtFeatureMetadataExtension(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n extFeatureMetadata: GLTF_EXT_feature_metadata_primitive,\n images: GLTFImagePostprocessed[]\n): number[] {\n // Take only first extension object to get batchIds attribute name.\n const featureIdAttribute = extFeatureMetadata?.featureIdAttributes?.[0];\n\n if (featureIdAttribute?.featureIds?.attribute) {\n const batchIdsAttribute = attributes[featureIdAttribute.featureIds.attribute];\n return batchIdsAttribute.value;\n }\n\n if (\n featureIdAttribute?.featureIds?.hasOwnProperty('constant') &&\n featureIdAttribute?.featureIds?.hasOwnProperty('divisor')\n ) {\n const featuresCount = attributes?.POSITIONS?.value.length / 3 || 0;\n return generateImplicitFeatureIds(\n featuresCount,\n featureIdAttribute.featureIds.constant,\n featureIdAttribute.featureIds.divisor\n );\n }\n\n // Take only first extension object to get batchIds attribute name.\n const featureIdTexture =\n extFeatureMetadata?.featureIdTextures && extFeatureMetadata?.featureIdTextures[0];\n\n if (featureIdTexture) {\n const textureAttributeIndex = featureIdTexture?.featureIds?.texture?.texCoord || 0;\n const textCoordAttribute = `TEXCOORD_${textureAttributeIndex}`;\n const textureCoordinates = attributes[textCoordAttribute].value;\n return generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images);\n }\n\n // Take only first extension texture to get batchIds from the root EXT_feature_metadata object.\n const featureTexture =\n extFeatureMetadata?.featureTextures && extFeatureMetadata?.featureTextures[0];\n\n /**\n * TODO need to get batchIds from root extension\n */\n if (featureTexture) {\n console.warn(\"EXT_feature_metadata doesn't yet support featureTextures in primitive\");\n return [];\n }\n\n return [];\n}\n\n/**\n * Generates implicit feature ids\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#implicit-feature-ids\n * @param featuresCount\n * @param constant\n * @param devisor\n */\nfunction generateImplicitFeatureIds(\n featuresCount: number,\n constant: number = 0,\n divisor: number = 0\n): number[] {\n let featureIds: number[] = [];\n\n if (divisor > 0) {\n let currentValue = constant;\n let devisorCounter = divisor;\n\n for (let index = 0; index < featuresCount; index++) {\n featureIds.push(currentValue);\n\n devisorCounter -= 1;\n\n if (devisorCounter === 0) {\n currentValue++;\n devisorCounter = divisor;\n }\n }\n } else {\n featureIds = Array<number>(featuresCount).fill(constant, 0, featuresCount);\n }\n\n return featureIds;\n}\n\n/**\n * Get batchIds from texture.\n * @param primitive\n * @param featureIdTextures\n */\nfunction generateBatchIdsFromTexture(\n featureIdTexture: GLTF_EXT_feature_metadata_attribute,\n textureCoordinates: Float32Array,\n images: GLTFImagePostprocessed[]\n) {\n if (!images?.length) {\n return [];\n }\n\n const CHANNELS_MAP = {\n r: 0,\n g: 1,\n b: 2,\n a: 3\n };\n\n const textureIndex = featureIdTexture?.featureIds?.texture?.index;\n const featureChannel = featureIdTexture?.featureIds?.channels;\n\n if (!featureChannel || textureIndex === undefined) {\n return [];\n }\n\n const image = images[textureIndex];\n const batchIds: number[] = [];\n const channels = CHANNELS_MAP[featureChannel];\n\n if (!image.compressed) {\n for (let index = 0; index < textureCoordinates.length; index += 2) {\n const u = textureCoordinates[index];\n const v = textureCoordinates[index + 1];\n\n const tx = Math.min((emod(u) * image.width) | 0, image.width - 1);\n const ty = Math.min((emod(v) * image.height) | 0, image.height - 1);\n\n const offset = (ty * image.width + tx) * image.components + channels;\n const batchId = new Uint8Array(image.data)[offset];\n\n batchIds.push(batchId);\n }\n } else {\n console.warn(`Can't get batch Ids from ${image.mimeType} compressed texture`);\n }\n\n return batchIds;\n}\n\n/**\n * Handle UVs if they are out of range [0,1].\n * @param n\n * @param m\n */\nfunction emod(n: number): number {\n return ((n % 1) + 1) % 1;\n}\n"],"file":"batch-ids-extensions.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/i3s-converter/helpers/coordinate-converter.ts"],"names":["createBoundingVolumes","tile","geoidHeightModel","radius","halfSize","quaternion","boundingVolume","cartographicCenter","Ellipsoid","WGS84","cartesianToCartographic","center","Vector3","getHeight","OrientedBoundingBox","len","Quaternion","fromMatrix3","Matrix3","normalize","mbs","obb","createBoundingVolumesFromGeometry","cartesianPositions","positionVectors","convertPositionsToVectors","geometryObb","geometryMbs","mbsCenter","obbCenter","positions","result","i","length","positionVector","push","convertBoundingVolumeToI3SFullExtent","sphere","BoundingSphere","getBoundingSphere","vertexMax","vertexMin","xmin","xmax","ymin","ymax","zmin","zmax","createObbFromMbs","halfAxex"],"mappings":";;;;;;;;;;;AAEA;;AACA;;AACA;;AAeO,SAASA,qBAAT,CAA+BC,IAA/B,
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/coordinate-converter.ts"],"names":["createBoundingVolumes","tile","geoidHeightModel","radius","halfSize","quaternion","boundingVolume","cartographicCenter","Ellipsoid","WGS84","cartesianToCartographic","center","Vector3","getHeight","OrientedBoundingBox","len","Quaternion","fromMatrix3","Matrix3","normalize","mbs","obb","createBoundingVolumesFromGeometry","cartesianPositions","positionVectors","convertPositionsToVectors","geometryObb","geometryMbs","mbsCenter","obbCenter","positions","result","i","length","positionVector","push","convertBoundingVolumeToI3SFullExtent","sphere","BoundingSphere","getBoundingSphere","vertexMax","vertexMin","xmin","xmax","ymin","ymax","zmin","zmax","createObbFromMbs","halfAxex"],"mappings":";;;;;;;;;;;AAEA;;AACA;;AACA;;AAeO,SAASA,qBAAT,C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@loaders.gl/i3s';\n\nimport {Matrix3, Quaternion, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {\n OrientedBoundingBox,\n makeOrientedBoundingBoxFromPoints,\n makeBoundingSphereFromPoints,\n BoundingSphere\n} from '@math.gl/culling';\nimport {Tile3D} from '@loaders.gl/tiles';\nimport {Geoid} from '@math.gl/geoid';\n\n/**\n * Create bounding volumes object from tile and geoid height model.\n * @param tile\n * @param geoidHeightModel\n * @returns - Bounding volumes object\n */\nexport function createBoundingVolumes(tile: Tile3D, geoidHeightModel: Geoid): BoundingVolumes {\n let radius;\n let halfSize;\n let quaternion;\n\n const boundingVolume = tile.boundingVolume;\n const cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(\n boundingVolume.center,\n new Vector3()\n );\n cartographicCenter[2] =\n cartographicCenter[2] -\n geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);\n if (boundingVolume instanceof OrientedBoundingBox) {\n halfSize = boundingVolume.halfSize;\n radius = new Vector3(halfSize[0], halfSize[1], halfSize[2]).len();\n quaternion = boundingVolume.quaternion;\n } else {\n radius = tile.boundingVolume.radius;\n halfSize = [radius, radius, radius];\n quaternion = new Quaternion()\n .fromMatrix3(new Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]]))\n .normalize();\n }\n\n return {\n mbs: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2], radius],\n obb: {\n center: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2]],\n halfSize,\n quaternion\n }\n };\n}\n\n/**\n * Generates bounding volumes from geometry positions\n * @param cartesianPositions\n * @param geoidHeightModel\n */\nexport function createBoundingVolumesFromGeometry(\n cartesianPositions: Float32Array,\n geoidHeightModel: Geoid\n): {mbs: Mbs; obb: Obb} {\n const positionVectors = convertPositionsToVectors(cartesianPositions);\n\n const geometryObb = makeOrientedBoundingBoxFromPoints(positionVectors);\n const geometryMbs = makeBoundingSphereFromPoints(positionVectors);\n\n let mbsCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new Vector3());\n let obbCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new Vector3());\n\n mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);\n obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);\n\n return {\n mbs: [mbsCenter[0], mbsCenter[1], mbsCenter[2], geometryMbs.radius],\n obb: {\n center: obbCenter,\n halfSize: geometryObb.halfSize,\n quaternion: geometryObb.quaternion\n }\n };\n}\n\n/**\n * Create array of posisitons where each vertex is vector\n * @param {array} positions\n * @returns {Vector3[]}\n */\nexport function convertPositionsToVectors(positions: Float32Array): Vector3[] {\n const result: Vector3[] = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n // TODO: (perf) new Vector3 is not optimal but required in `makeOrientedBoundingBoxFromPoints`.\n // modify `makeOrientedBoundingBoxFromPoints` to use scratch vectors\n const positionVector = new Vector3([positions[i], positions[i + 1], positions[i + 2]]);\n result.push(positionVector);\n }\n\n return result;\n}\n\n/**\n * Convert common coordinate to fullExtent https://github.com/Esri/i3s-spec/blob/master/docs/1.8/fullExtent.cmn.md\n * @param\n * @param boundingVolume\n * @returns - fullExtent object\n */\nexport function convertBoundingVolumeToI3SFullExtent(\n boundingVolume: OrientedBoundingBox | BoundingSphere\n): FullExtent {\n let sphere: BoundingSphere;\n if (boundingVolume instanceof BoundingSphere) {\n sphere = boundingVolume;\n } else {\n sphere = boundingVolume.getBoundingSphere();\n }\n const center: Vector3 = sphere.center;\n const radius: number = sphere.radius;\n const vertexMax = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(center[0] + radius, center[1] + radius, center[2] + radius),\n new Vector3()\n );\n const vertexMin = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(center[0] - radius, center[1] - radius, center[2] - radius),\n new Vector3()\n );\n\n return {\n xmin: vertexMin[0],\n xmax: vertexMax[0],\n ymin: vertexMin[1],\n ymax: vertexMax[1],\n zmin: vertexMin[2],\n zmax: vertexMax[2]\n };\n}\n\n/**\n * Creates oriented boundinb box from mbs.\n * @param mbs - Minimum Bounding Sphere\n * @returns - Oriented BOunding Box\n */\nexport function createObbFromMbs(mbs: Mbs): Obb {\n const radius = mbs[3];\n const center = new Vector3(mbs[0], mbs[1], mbs[2]);\n const halfAxex = new Matrix3([radius, 0, 0, 0, radius, 0, 0, 0, radius]);\n return new OrientedBoundingBox(center, halfAxex);\n}\n"],"file":"coordinate-converter.js"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.flattenPropertyTableByFeatureIds = flattenPropertyTableByFeatureIds;
|
|
7
9
|
exports.checkPropertiesLength = checkPropertiesLength;
|
|
10
|
+
exports.getAttributeType = getAttributeType;
|
|
11
|
+
exports.createdStorageAttribute = createdStorageAttribute;
|
|
12
|
+
exports.getFieldAttributeType = getFieldAttributeType;
|
|
13
|
+
exports.createFieldAttribute = createFieldAttribute;
|
|
14
|
+
exports.createPopupInfo = createPopupInfo;
|
|
15
|
+
|
|
16
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
8
17
|
|
|
9
18
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
10
19
|
|
|
@@ -57,4 +66,148 @@ function checkPropertiesLength(featureIds, propertyTable) {
|
|
|
57
66
|
|
|
58
67
|
return needFlatten;
|
|
59
68
|
}
|
|
69
|
+
|
|
70
|
+
var STRING_TYPE = 'string';
|
|
71
|
+
var SHORT_INT_TYPE = 'Int32';
|
|
72
|
+
var DOUBLE_TYPE = 'double';
|
|
73
|
+
var OBJECT_ID_TYPE = 'OBJECTID';
|
|
74
|
+
|
|
75
|
+
function getAttributeType(key, attribute) {
|
|
76
|
+
if (key === OBJECT_ID_TYPE) {
|
|
77
|
+
return OBJECT_ID_TYPE;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if ((0, _typeof2.default)(attribute) === STRING_TYPE) {
|
|
81
|
+
return STRING_TYPE;
|
|
82
|
+
} else if (typeof attribute === 'number') {
|
|
83
|
+
return Number.isInteger(attribute) ? SHORT_INT_TYPE : DOUBLE_TYPE;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return STRING_TYPE;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function createdStorageAttribute(attributeIndex, key, attributeType) {
|
|
90
|
+
var storageAttribute = {
|
|
91
|
+
key: "f_".concat(attributeIndex),
|
|
92
|
+
name: key,
|
|
93
|
+
ordering: ['attributeValues'],
|
|
94
|
+
header: [{
|
|
95
|
+
property: 'count',
|
|
96
|
+
valueType: 'UInt32'
|
|
97
|
+
}],
|
|
98
|
+
attributeValues: {
|
|
99
|
+
valueType: 'Int32',
|
|
100
|
+
valuesPerElement: 1
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
switch (attributeType) {
|
|
105
|
+
case OBJECT_ID_TYPE:
|
|
106
|
+
setupIdAttribute(storageAttribute);
|
|
107
|
+
break;
|
|
108
|
+
|
|
109
|
+
case STRING_TYPE:
|
|
110
|
+
setupStringAttribute(storageAttribute);
|
|
111
|
+
break;
|
|
112
|
+
|
|
113
|
+
case DOUBLE_TYPE:
|
|
114
|
+
setupDoubleAttribute(storageAttribute);
|
|
115
|
+
break;
|
|
116
|
+
|
|
117
|
+
case SHORT_INT_TYPE:
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
default:
|
|
121
|
+
setupStringAttribute(storageAttribute);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return storageAttribute;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function getFieldAttributeType(attributeType) {
|
|
128
|
+
switch (attributeType) {
|
|
129
|
+
case OBJECT_ID_TYPE:
|
|
130
|
+
return 'esriFieldTypeOID';
|
|
131
|
+
|
|
132
|
+
case STRING_TYPE:
|
|
133
|
+
return 'esriFieldTypeString';
|
|
134
|
+
|
|
135
|
+
case SHORT_INT_TYPE:
|
|
136
|
+
return 'esriFieldTypeInteger';
|
|
137
|
+
|
|
138
|
+
case DOUBLE_TYPE:
|
|
139
|
+
return 'esriFieldTypeDouble';
|
|
140
|
+
|
|
141
|
+
default:
|
|
142
|
+
return 'esriFieldTypeString';
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function createFieldAttribute(key, fieldAttributeType) {
|
|
147
|
+
return {
|
|
148
|
+
name: key,
|
|
149
|
+
type: fieldAttributeType,
|
|
150
|
+
alias: key
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function createPopupInfo(propertyTable) {
|
|
155
|
+
var title = '{OBJECTID}';
|
|
156
|
+
var mediaInfos = [];
|
|
157
|
+
var fieldInfos = [];
|
|
158
|
+
var popupElements = [];
|
|
159
|
+
var expressionInfos = [];
|
|
160
|
+
|
|
161
|
+
for (var key in propertyTable) {
|
|
162
|
+
fieldInfos.push({
|
|
163
|
+
fieldName: key,
|
|
164
|
+
visible: true,
|
|
165
|
+
isEditable: false,
|
|
166
|
+
label: key
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
popupElements.push({
|
|
171
|
+
fieldInfos: fieldInfos,
|
|
172
|
+
type: 'fields'
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
title: title,
|
|
176
|
+
mediaInfos: mediaInfos,
|
|
177
|
+
popupElements: popupElements,
|
|
178
|
+
fieldInfos: fieldInfos,
|
|
179
|
+
expressionInfos: expressionInfos
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function setupStringAttribute(storageAttribute) {
|
|
184
|
+
storageAttribute.ordering.unshift('attributeByteCounts');
|
|
185
|
+
storageAttribute.header.push({
|
|
186
|
+
property: 'attributeValuesByteCount',
|
|
187
|
+
valueType: 'UInt32'
|
|
188
|
+
});
|
|
189
|
+
storageAttribute.attributeValues = {
|
|
190
|
+
valueType: 'String',
|
|
191
|
+
encoding: 'UTF-8',
|
|
192
|
+
valuesPerElement: 1
|
|
193
|
+
};
|
|
194
|
+
storageAttribute.attributeByteCounts = {
|
|
195
|
+
valueType: 'UInt32',
|
|
196
|
+
valuesPerElement: 1
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function setupIdAttribute(storageAttribute) {
|
|
201
|
+
storageAttribute.attributeValues = {
|
|
202
|
+
valueType: 'Oid32',
|
|
203
|
+
valuesPerElement: 1
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function setupDoubleAttribute(storageAttribute) {
|
|
208
|
+
storageAttribute.attributeValues = {
|
|
209
|
+
valueType: 'Float64',
|
|
210
|
+
valuesPerElement: 1
|
|
211
|
+
};
|
|
212
|
+
}
|
|
60
213
|
//# sourceMappingURL=feature-attributes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/i3s-converter/helpers/feature-attributes.ts"],"names":["flattenPropertyTableByFeatureIds","featureIds","propertyTable","resultPropertyTable","propertyName","properties","getPropertiesByFeatureIds","resultProperties","featureId","property","push","checkPropertiesLength","needFlatten","Object","values","attribute","length"],"mappings":";;;;;;;;;;;;;;AAeO,SAASA,gCAAT,CACLC,UADK,EAELC,aAFK,EAGa;AAClB,MAAMC,mBAAqC,GAAG,EAA9C;;AACA,OAAK,IAAMC,YAAX,IAA2BF,aAA3B,EAA0C;AACxC,QAAMG,UAAU,GAAGH,aAAa,CAACE,YAAD,CAAhC;AACAD,IAAAA,mBAAmB,CAACC,YAAD,CAAnB,GAAoCE,yBAAyB,CAACD,UAAD,EAAaJ,UAAb,CAA7D;AACD;;AAED,SAAOE,mBAAP;AACD;;AAOD,SAASG,yBAAT,CAAmCD,UAAnC,EAAsDJ,UAAtD,EAAmF;AACjF,MAAMM,gBAAqB,GAAG,EAA9B;;AADiF,6CAGzDN,UAHyD;AAAA;;AAAA;AAGjF,wDAAoC;AAAA,UAAzBO,SAAyB;AAClC,UAAMC,QAAQ,GAAGJ,UAAU,CAACG,SAAD,CAAV,IAAyB,IAA1C;AACAD,MAAAA,gBAAgB,CAACG,IAAjB,CAAsBD,QAAtB;AACD;AANgF;AAAA;AAAA;AAAA;AAAA;;AAQjF,SAAOF,gBAAP;AACD;;AASM,SAASI,qBAAT,CACLV,UADK,EAELC,aAFK,EAGI;AACT,MAAIU,WAAW,GAAG,KAAlB;;AAEA,oCAAwBC,MAAM,CAACC,MAAP,CAAcZ,aAAd,CAAxB,oCAAsD;AAAjD,QAAMa,SAAS,qBAAf;;AACH,QAAId,UAAU,CAACe,MAAX,KAAsBD,SAAS,CAACC,MAApC,EAA4C;AAC1CJ,MAAAA,WAAW,GAAG,IAAd;AACD;AACF;;AAED,SAAOA,WAAP;AACD","sourcesContent":["import type {FeatureTableJson} from '@loaders.gl/3d-tiles';\n\n/**\n * Takes attributes from property table based on featureIds.\n * If there is no property value for particular featureId (index) the property will be null.\n * Example:\n * Initial data:\n * OBJECTID: [0, 1, 5]\n * component: ['Windows', 'Frames', 'Wall', 'Roof', 'Skylight']\n * Result:\n * OBJECTID: [0, 1, 5]\n * component: ['Windows', 'Frames', 'null']\n * @param featureIds\n * @param propertyTable\n */\nexport function flattenPropertyTableByFeatureIds(\n featureIds: number[],\n propertyTable: FeatureTableJson\n): FeatureTableJson {\n const resultPropertyTable: FeatureTableJson = {};\n for (const propertyName in propertyTable) {\n const properties = propertyTable[propertyName];\n resultPropertyTable[propertyName] = getPropertiesByFeatureIds(properties, featureIds);\n }\n\n return resultPropertyTable;\n}\n\n/**\n * Getting properties by featureId index\n * @param properties\n * @param featureIds\n */\nfunction getPropertiesByFeatureIds(properties: any[], featureIds: number[]): any[] {\n const resultProperties: any = [];\n\n for (const featureId of featureIds) {\n const property = properties[featureId] || null;\n resultProperties.push(property);\n }\n\n return resultProperties;\n}\n\n/**\n * Check that all attributes in propertyTable have the same length as FeatureIds.\n * If there are differencies between lengths we should flatten property table based on exiesting featureIds.\n * @param featureIds\n * @param propertyTable\n * @returns\n */\nexport function checkPropertiesLength(\n featureIds: number[],\n propertyTable: FeatureTableJson\n): boolean {\n let needFlatten = false;\n\n for (const attribute of Object.values(propertyTable)) {\n if (featureIds.length !== attribute.length) {\n needFlatten = true;\n }\n }\n\n return needFlatten;\n}\n"],"file":"feature-attributes.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/feature-attributes.ts"],"names":["flattenPropertyTableByFeatureIds","featureIds","propertyTable","resultPropertyTable","propertyName","properties","getPropertiesByFeatureIds","resultProperties","featureId","property","push","checkPropertiesLength","needFlatten","Object","values","attribute","length","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","getAttributeType","key","Number","isInteger","createdStorageAttribute","attributeIndex","attributeType","storageAttribute","name","ordering","header","valueType","attributeValues","valuesPerElement","setupIdAttribute","setupStringAttribute","setupDoubleAttribute","getFieldAttributeType","createFieldAttribute","fieldAttributeType","type","alias","createPopupInfo","title","mediaInfos","fieldInfos","popupElements","expressionInfos","fieldName","visible","isEditable","label","unshift","encoding","attributeByteCounts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBO,SAASA,gCAAT,CACLC,UADK,EAELC,aAFK,EAGa;AAClB,MAAMC,mBAAqC,GAAG,EAA9C;;AACA,OAAK,IAAMC,YAAX,IAA2BF,aAA3B,EAA0C;AACxC,QAAMG,UAAU,GAAGH,aAAa,CAACE,YAAD,CAAhC;AACAD,IAAAA,mBAAmB,CAACC,YAAD,CAAnB,GAAoCE,yBAAyB,CAACD,UAAD,EAAaJ,UAAb,CAA7D;AACD;;AAED,SAAOE,mBAAP;AACD;;AAOD,SAASG,yBAAT,CAAmCD,UAAnC,EAAsDJ,UAAtD,EAAmF;AACjF,MAAMM,gBAAqB,GAAG,EAA9B;;AADiF,6CAGzDN,UAHyD;AAAA;;AAAA;AAGjF,wDAAoC;AAAA,UAAzBO,SAAyB;AAClC,UAAMC,QAAQ,GAAGJ,UAAU,CAACG,SAAD,CAAV,IAAyB,IAA1C;AACAD,MAAAA,gBAAgB,CAACG,IAAjB,CAAsBD,QAAtB;AACD;AANgF;AAAA;AAAA;AAAA;AAAA;;AAQjF,SAAOF,gBAAP;AACD;;AASM,SAASI,qBAAT,CACLV,UADK,EAELC,aAFK,EAGI;AACT,MAAIU,WAAW,GAAG,KAAlB;;AAEA,oCAAwBC,MAAM,CAACC,MAAP,CAAcZ,aAAd,CAAxB,oCAAsD;AAAjD,QAAMa,SAAS,qBAAf;;AACH,QAAId,UAAU,CAACe,MAAX,KAAsBD,SAAS,CAACC,MAApC,EAA4C;AAC1CJ,MAAAA,WAAW,GAAG,IAAd;AACD;AACF;;AAED,SAAOA,WAAP;AACD;;AAGD,IAAMK,WAAW,GAAG,QAApB;AAEA,IAAMC,cAAc,GAAG,OAAvB;AAEA,IAAMC,WAAW,GAAG,QAApB;AAEA,IAAMC,cAAc,GAAG,UAAvB;;AA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wBrB,IAAxB,CAA6B;AAACD,IAAAA,QAAQ,EAAE,0BAAX;AAAuCuB,IAAAA,SAAS,EAAE;AAAlD,GAA7B;AACAJ,EAAAA,gBAAgB,CAACK,eAAjB,GAAmC;AACjCD,IAAAA,SAAS,EAAE,QADsB;AAEjCsB,IAAAA,QAAQ,EAAE,OAFuB;AAGjCpB,IAAAA,gBAAgB,EAAE;AAHe,GAAnC;AAKAN,EAAAA,gBAAgB,CAAC2B,mBAAjB,GAAuC;AACrCvB,IAAAA,SAAS,EAAE,QAD0B;AAErCE,IAAAA,gBAAgB,EAAE;AAFmB,GAAvC;AAID;;AAMD,SAASC,gBAAT,CAA0BP,gBAA1B,EAAwE;AACtEA,EAAAA,gBAAgB,CAACK,eAAjB,GAAmC;AACjCD,IAAAA,SAAS,EAAE,OADsB;AAEjCE,IAAAA,gBAAgB,EAAE;AAFe,GAAnC;AAID;;AAMD,SAASG,oBAAT,CAA8BT,gBAA9B,EAA4E;AAC1EA,EAAAA,gBAAgB,CAACK,eAAjB,GAAmC;AACjCD,IAAAA,SAAS,EAAE,SADsB;AAEjCE,IAAAA,gBAAgB,EAAE;AAFe,GAAnC;AAID","sourcesContent":["import type {FeatureTableJson} from '@loaders.gl/3d-tiles';\nimport {\n Attribute,\n AttributeStorageInfo,\n ESRIField,\n Field,\n FieldInfo,\n PopupInfo\n} from '@loaders.gl/i3s';\n\n/**\n * Takes attributes from property table based on featureIds.\n * If there is no property value for particular featureId (index) the property will be null.\n * Example:\n * Initial data:\n * OBJECTID: [0, 1, 5]\n * component: ['Windows', 'Frames', 'Wall', 'Roof', 'Skylight']\n * Result:\n * OBJECTID: [0, 1, 5]\n * component: ['Windows', 'Frames', 'null']\n * @param featureIds\n * @param propertyTable\n */\nexport function flattenPropertyTableByFeatureIds(\n featureIds: number[],\n propertyTable: FeatureTableJson\n): FeatureTableJson {\n const resultPropertyTable: FeatureTableJson = {};\n for (const propertyName in propertyTable) {\n const properties = propertyTable[propertyName];\n resultPropertyTable[propertyName] = getPropertiesByFeatureIds(properties, featureIds);\n }\n\n return resultPropertyTable;\n}\n\n/**\n * Getting properties by featureId index\n * @param properties\n * @param featureIds\n */\nfunction getPropertiesByFeatureIds(properties: any[], featureIds: number[]): any[] {\n const resultProperties: any = [];\n\n for (const featureId of featureIds) {\n const property = properties[featureId] || null;\n resultProperties.push(property);\n }\n\n return resultProperties;\n}\n\n/**\n * Check that all attributes in propertyTable have the same length as FeatureIds.\n * If there are differencies between lengths we should flatten property table based on exiesting featureIds.\n * @param featureIds\n * @param propertyTable\n * @returns\n */\nexport function checkPropertiesLength(\n featureIds: number[],\n propertyTable: FeatureTableJson\n): boolean {\n let needFlatten = false;\n\n for (const attribute of Object.values(propertyTable)) {\n if (featureIds.length !== attribute.length) {\n needFlatten = true;\n }\n }\n\n return needFlatten;\n}\n\n/** String data type name for feature attributes */\nconst STRING_TYPE = 'string';\n/** Integer data type name for feature attributes */\nconst SHORT_INT_TYPE = 'Int32';\n/** Double data type name for feature attributes */\nconst DOUBLE_TYPE = 'double';\n/** Type of attribute that is linked with feature ids */\nconst OBJECT_ID_TYPE = 'OBJECTID';\n/**\n * Get the attribute type for attributeStorageInfo https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md\n * @param key - attribute's key\n * @param attribute - attribute's type in propertyTable\n */\nexport function getAttributeType(key: string, attribute: string): string {\n if (key === OBJECT_ID_TYPE) {\n return OBJECT_ID_TYPE;\n }\n if (typeof attribute === STRING_TYPE) {\n return STRING_TYPE;\n } else if (typeof attribute === 'number') {\n return Number.isInteger(attribute) ? SHORT_INT_TYPE : DOUBLE_TYPE;\n }\n return STRING_TYPE;\n}\n\n/**\n * Generate storage attribute for map segmentation.\n * @param attributeIndex - order index of attribute (f_0, f_1 ...).\n * @param key - attribute key from propertyTable.\n * @param attributeType - attribute type.\n * @return Updated storageAttribute.\n */\nexport function createdStorageAttribute(\n attributeIndex: number,\n key: string,\n attributeType: Attribute\n): AttributeStorageInfo {\n const storageAttribute = {\n key: `f_${attributeIndex}`,\n name: key,\n ordering: ['attributeValues'],\n header: [{property: 'count', valueType: 'UInt32'}],\n attributeValues: {valueType: 'Int32', valuesPerElement: 1}\n };\n\n switch (attributeType) {\n case OBJECT_ID_TYPE:\n setupIdAttribute(storageAttribute);\n break;\n case STRING_TYPE:\n setupStringAttribute(storageAttribute);\n break;\n case DOUBLE_TYPE:\n setupDoubleAttribute(storageAttribute);\n break;\n case SHORT_INT_TYPE:\n break;\n default:\n setupStringAttribute(storageAttribute);\n }\n\n return storageAttribute;\n}\n\n/**\n * Find and return attribute type based on key form propertyTable.\n * @param attributeType\n */\nexport function getFieldAttributeType(attributeType: Attribute): ESRIField {\n switch (attributeType) {\n case OBJECT_ID_TYPE:\n return 'esriFieldTypeOID';\n case STRING_TYPE:\n return 'esriFieldTypeString';\n case SHORT_INT_TYPE:\n return 'esriFieldTypeInteger';\n case DOUBLE_TYPE:\n return 'esriFieldTypeDouble';\n default:\n return 'esriFieldTypeString';\n }\n}\n\n/**\n * Setup field attribute for map segmentation.\n * @param key - attribute for map segmentation.\n * @param fieldAttributeType - esri attribute type ('esriFieldTypeString' or 'esriFieldTypeOID').\n */\nexport function createFieldAttribute(key: string, fieldAttributeType: ESRIField): Field {\n return {\n name: key,\n type: fieldAttributeType,\n alias: key\n };\n}\n\n/**\n * Generate popup info to show metadata on the map.\n * @param propertyTable - table data with OBJECTID.\n * @return data for correct rendering of popup.\n */\nexport function createPopupInfo(propertyTable: FeatureTableJson): PopupInfo {\n const title = '{OBJECTID}';\n const mediaInfos = [];\n const fieldInfos: FieldInfo[] = [];\n const popupElements: {\n fieldInfos: FieldInfo[];\n type: string;\n }[] = [];\n const expressionInfos = [];\n\n for (const key in propertyTable) {\n fieldInfos.push({\n fieldName: key,\n visible: true,\n isEditable: false,\n label: key\n });\n }\n popupElements.push({\n fieldInfos,\n type: 'fields'\n });\n\n return {\n title,\n mediaInfos,\n popupElements,\n fieldInfos,\n expressionInfos\n };\n}\n\n/**\n * Setup storage attribute as string.\n * @param storageAttribute - attribute for map segmentation.\n */\nfunction setupStringAttribute(storageAttribute: AttributeStorageInfo): void {\n // @ts-expect-error\n storageAttribute.ordering.unshift('attributeByteCounts');\n storageAttribute.header.push({property: 'attributeValuesByteCount', valueType: 'UInt32'});\n storageAttribute.attributeValues = {\n valueType: 'String',\n encoding: 'UTF-8',\n valuesPerElement: 1\n };\n storageAttribute.attributeByteCounts = {\n valueType: 'UInt32',\n valuesPerElement: 1\n };\n}\n\n/**\n * Setup Id attribute for map segmentation.\n * @param storageAttribute - attribute for map segmentation .\n */\nfunction setupIdAttribute(storageAttribute: AttributeStorageInfo): void {\n storageAttribute.attributeValues = {\n valueType: 'Oid32',\n valuesPerElement: 1\n };\n}\n\n/**\n * Setup double attribute for map segmentation.\n * @param storageAttribute - attribute for map segmentation .\n */\nfunction setupDoubleAttribute(storageAttribute: AttributeStorageInfo): void {\n storageAttribute.attributeValues = {\n valueType: 'Float64',\n valuesPerElement: 1\n };\n}\n"],"file":"feature-attributes.js"}
|