@loaders.gl/tile-converter 4.3.0-alpha.4 → 4.3.0-alpha.5
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-converter/3d-tiles-converter.d.ts +4 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/converter-cli.js +0 -13
- package/dist/converter.min.cjs +89 -89
- package/dist/deps-installer/deps-installer.js +1 -1
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-index-document.js +6 -14
- package/dist/i3s-converter/helpers/node-pages.d.ts +1 -1
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-pages.js +14 -40
- package/dist/i3s-converter/i3s-converter.d.ts +24 -23
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +60 -130
- package/dist/i3s-server/app.d.ts +2 -1
- package/dist/i3s-server/app.d.ts.map +1 -1
- package/dist/i3s-server/app.js +7 -10
- package/dist/i3s-server/bin/i3s-server.min.cjs +71 -71
- package/dist/i3s-server/bin/www.js +5 -0
- package/dist/index.cjs +82 -194
- package/dist/index.cjs.map +2 -2
- package/dist/lib/utils/statistic-utills.d.ts +4 -1
- package/dist/lib/utils/statistic-utills.d.ts.map +1 -1
- package/dist/lib/utils/statistic-utills.js +4 -23
- package/dist/pgm-loader.js +1 -1
- package/package.json +19 -20
- package/src/3d-tiles-converter/3d-tiles-converter.ts +2 -1
- package/src/converter-cli.ts +0 -19
- package/src/i3s-converter/helpers/node-index-document.ts +16 -26
- package/src/i3s-converter/helpers/node-pages.ts +20 -46
- package/src/i3s-converter/i3s-converter.ts +88 -154
- package/src/i3s-server/app.ts +7 -10
- package/src/i3s-server/bin/www.ts +6 -0
- package/src/lib/utils/statistic-utills.ts +5 -27
- package/bin/slpk-extractor.js +0 -2
- package/dist/i3s-server/controllers/index-controller.d.ts +0 -8
- package/dist/i3s-server/controllers/index-controller.d.ts.map +0 -1
- package/dist/i3s-server/controllers/index-controller.js +0 -31
- package/dist/i3s-server/routes/index.d.ts +0 -2
- package/dist/i3s-server/routes/index.d.ts.map +0 -1
- package/dist/i3s-server/routes/index.js +0 -17
- package/dist/slpk-extractor/slpk-extractor.d.ts +0 -23
- package/dist/slpk-extractor/slpk-extractor.d.ts.map +0 -1
- package/dist/slpk-extractor/slpk-extractor.js +0 -73
- package/dist/slpk-extractor-cli.d.ts +0 -17
- package/dist/slpk-extractor-cli.d.ts.map +0 -1
- package/dist/slpk-extractor-cli.js +0 -105
- package/dist/slpk-extractor.min.cjs +0 -344
- package/src/i3s-server/controllers/index-controller.ts +0 -32
- package/src/i3s-server/routes/index.ts +0 -18
- package/src/slpk-extractor/slpk-extractor.ts +0 -102
- package/src/slpk-extractor-cli.ts +0 -136
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
|
|
4
|
-
const {promises} = fs;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get local file name by input HTTP URL
|
|
8
|
-
* @param url - I3S HTTP service url
|
|
9
|
-
* @param i3sLayerPath - I3S layer path
|
|
10
|
-
* @returns - local file name
|
|
11
|
-
*/
|
|
12
|
-
export async function getFileNameByUrl(url: string, i3sLayerPath = ''): Promise<string | null> {
|
|
13
|
-
i3sLayerPath = i3sLayerPath || process.env.I3sLayerPath || '';
|
|
14
|
-
const extensions = ['json', 'bin', 'jpg', 'jpeg', 'png', 'bin.dds', 'ktx2'];
|
|
15
|
-
let filePath = process.cwd();
|
|
16
|
-
// Checks if the first character is not a point to indicate absolute path
|
|
17
|
-
const absolutePath = /^[^.]/.exec(i3sLayerPath);
|
|
18
|
-
if (absolutePath) {
|
|
19
|
-
filePath = '';
|
|
20
|
-
}
|
|
21
|
-
const FULL_LAYER_PATH = path.join(filePath, i3sLayerPath, url);
|
|
22
|
-
for (const ext of extensions) {
|
|
23
|
-
const fileName = `${FULL_LAYER_PATH}/index.${ext}`;
|
|
24
|
-
try {
|
|
25
|
-
await promises.access(fileName);
|
|
26
|
-
return fileName;
|
|
27
|
-
} catch {
|
|
28
|
-
continue; // eslint-disable-line no-continue
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import {getFileNameByUrl} from '../controllers/index-controller';
|
|
3
|
-
|
|
4
|
-
export const router = express.Router();
|
|
5
|
-
|
|
6
|
-
/* GET home page. */
|
|
7
|
-
router.get('*', (req, res, next) => {
|
|
8
|
-
async function routerCallback(req, res, next) {
|
|
9
|
-
const fileName = await getFileNameByUrl(req.path);
|
|
10
|
-
if (fileName) {
|
|
11
|
-
res.sendFile(fileName);
|
|
12
|
-
} else {
|
|
13
|
-
res.status(404);
|
|
14
|
-
res.send('File not found');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
routerCallback(req, res, next);
|
|
18
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import {isBrowser} from '@loaders.gl/core';
|
|
2
|
-
|
|
3
|
-
import {BROWSER_ERROR_MESSAGE} from '../constants';
|
|
4
|
-
import {path} from '@loaders.gl/loader-utils';
|
|
5
|
-
import {FileHandleFile} from '@loaders.gl/loader-utils';
|
|
6
|
-
import {parseZipLocalFileHeader} from '@loaders.gl/zip';
|
|
7
|
-
import {GZipCompression} from '@loaders.gl/compression';
|
|
8
|
-
import {writeFile} from '../lib/utils/file-utils';
|
|
9
|
-
|
|
10
|
-
const indexNames = [
|
|
11
|
-
'3dSceneLayer.json.gz',
|
|
12
|
-
'3dNodeIndexDocument.json.gz',
|
|
13
|
-
'sharedResource.json.gz'
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Description of the file in the SLPK
|
|
18
|
-
*/
|
|
19
|
-
type File = {
|
|
20
|
-
name: string | null;
|
|
21
|
-
data: ArrayBuffer;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Converter from slpk to i3s
|
|
26
|
-
*/
|
|
27
|
-
export default class SLPKExtractor {
|
|
28
|
-
/**
|
|
29
|
-
* Extract slpk to i3s
|
|
30
|
-
* @param options
|
|
31
|
-
* @param options.inputUrl the url to read SLPK file
|
|
32
|
-
* @param options.outputPath the output filename
|
|
33
|
-
*/
|
|
34
|
-
public async extract(options: {inputUrl: string; outputPath: string}): Promise<string> {
|
|
35
|
-
if (isBrowser) {
|
|
36
|
-
// eslint-disable-next-line no-console
|
|
37
|
-
console.log(BROWSER_ERROR_MESSAGE);
|
|
38
|
-
return BROWSER_ERROR_MESSAGE;
|
|
39
|
-
}
|
|
40
|
-
const {inputUrl} = options;
|
|
41
|
-
|
|
42
|
-
const provider = new FileHandleFile(inputUrl);
|
|
43
|
-
|
|
44
|
-
let localHeader = await parseZipLocalFileHeader(0n, provider);
|
|
45
|
-
while (localHeader) {
|
|
46
|
-
await this.writeFile(
|
|
47
|
-
await this.unGzip({
|
|
48
|
-
name: this.correctIndexNames(localHeader.fileName),
|
|
49
|
-
data: await provider.slice(
|
|
50
|
-
localHeader.fileDataOffset,
|
|
51
|
-
localHeader.fileDataOffset + localHeader.compressedSize
|
|
52
|
-
)
|
|
53
|
-
}),
|
|
54
|
-
options.outputPath
|
|
55
|
-
);
|
|
56
|
-
localHeader = await parseZipLocalFileHeader(
|
|
57
|
-
localHeader.fileDataOffset + localHeader?.compressedSize,
|
|
58
|
-
provider
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return 'success';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Defines file name and path for i3s format
|
|
67
|
-
* @param fileName initial file name and path
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
private correctIndexNames(fileName: string): string | null {
|
|
71
|
-
if (indexNames.includes(path.filename(path.join('/', fileName)))) {
|
|
72
|
-
return path.join(path.dirname(fileName), 'index.json.gz');
|
|
73
|
-
}
|
|
74
|
-
// finds path with name part and extention part
|
|
75
|
-
const parts = /^(.*\/[^\/\.]*)(\..+)$/.exec(fileName);
|
|
76
|
-
if (!parts) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
return `${parts?.at(1)}/index${parts?.at(2)}`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private async unGzip(file: File): Promise<File> {
|
|
83
|
-
if (/\.gz$/.test(file.name ?? '')) {
|
|
84
|
-
const compression = new GZipCompression();
|
|
85
|
-
|
|
86
|
-
const decompressedData = await compression.decompress(file.data);
|
|
87
|
-
|
|
88
|
-
return {data: decompressedData, name: (file.name ?? '').slice(0, -3)};
|
|
89
|
-
}
|
|
90
|
-
return Promise.resolve(file);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private async writeFile(options: File, outputPath: string): Promise<void> {
|
|
94
|
-
if (!options.name) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const finalPath = path.join(outputPath, options.name);
|
|
98
|
-
const dirName = path.dirname(finalPath);
|
|
99
|
-
const fileName = path.filename(finalPath);
|
|
100
|
-
await writeFile(dirName, options.data, fileName);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import '@loaders.gl/polyfills';
|
|
2
|
-
import SLPKExtractor from './slpk-extractor/slpk-extractor';
|
|
3
|
-
import {getURLValue, validateOptionsWithEqual} from './lib/utils/cli-utils';
|
|
4
|
-
|
|
5
|
-
type SLPKExtractionOptions = {
|
|
6
|
-
/** "tileset.json" file (3DTiles) / "http://..../SceneServer/layers/0" resource (I3S) */
|
|
7
|
-
tileset?: string;
|
|
8
|
-
/** Output folder. This folder will be created by converter if doesn't exist. It is relative to the converter path.
|
|
9
|
-
* Default: "data" folder */
|
|
10
|
-
output?: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/* During validation we check that particular options are defined so they can't be undefined */
|
|
14
|
-
export type ValidatedSLPKExtractionOptions = SLPKExtractionOptions & {
|
|
15
|
-
/** slpk file */
|
|
16
|
-
tileset: string;
|
|
17
|
-
/** Output folder. This folder will be created by converter if doesn't exist. It is relative to the converter path.
|
|
18
|
-
* Default: "data" folder */
|
|
19
|
-
output: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* CLI entry
|
|
24
|
-
* @returns
|
|
25
|
-
*/
|
|
26
|
-
async function main() {
|
|
27
|
-
const [, , ...args] = process.argv;
|
|
28
|
-
|
|
29
|
-
if (args.length === 0) {
|
|
30
|
-
printHelp();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const validatedOptionsArr = validateOptionsWithEqual(args);
|
|
34
|
-
|
|
35
|
-
const options: SLPKExtractionOptions = parseOptions(validatedOptionsArr);
|
|
36
|
-
|
|
37
|
-
const validatedOptions: ValidatedSLPKExtractionOptions = validateOptions(options);
|
|
38
|
-
|
|
39
|
-
await convert(validatedOptions);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
main().catch((error) => {
|
|
43
|
-
console.log(error); // eslint-disable-line no-console
|
|
44
|
-
process.exit(1); // eslint-disable-line no-process-exit
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Output for `npx slpk-extractor --help`
|
|
49
|
-
*/
|
|
50
|
-
function printHelp(): void {
|
|
51
|
-
// eslint-disable-next-line no-console
|
|
52
|
-
console.log('cli: converter slpk to I3S...');
|
|
53
|
-
// eslint-disable-next-line no-console
|
|
54
|
-
console.log('--output [Output folder, default: "data" folder]');
|
|
55
|
-
// eslint-disable-next-line no-console
|
|
56
|
-
console.log('--tileset [SLPK file]');
|
|
57
|
-
process.exit(0); // eslint-disable-line no-process-exit
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Run extraction process
|
|
62
|
-
* @param options validated slpk-extractor options
|
|
63
|
-
*/
|
|
64
|
-
async function convert(options: ValidatedSLPKExtractionOptions) {
|
|
65
|
-
// eslint-disable-next-line no-console
|
|
66
|
-
console.log('------------------------------------------------');
|
|
67
|
-
// eslint-disable-next-line no-console
|
|
68
|
-
console.log('Starting conversion of SLPK');
|
|
69
|
-
// eslint-disable-next-line no-console
|
|
70
|
-
console.log('------------------------------------------------');
|
|
71
|
-
const slpkExtractor = new SLPKExtractor();
|
|
72
|
-
slpkExtractor.extract({
|
|
73
|
-
inputUrl: options.tileset,
|
|
74
|
-
outputPath: options.output
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// OPTIONS
|
|
79
|
-
/**
|
|
80
|
-
* Validate input options of the CLI command
|
|
81
|
-
* @param options - input options of the CLI command
|
|
82
|
-
* @returns validated options
|
|
83
|
-
*/
|
|
84
|
-
function validateOptions(options: SLPKExtractionOptions): ValidatedSLPKExtractionOptions {
|
|
85
|
-
const mandatoryOptionsWithExceptions: {
|
|
86
|
-
[key: string]: () => void;
|
|
87
|
-
} = {
|
|
88
|
-
// eslint-disable-next-line no-console
|
|
89
|
-
output: () => console.log('Missed: --output [Output path name]'),
|
|
90
|
-
// eslint-disable-next-line no-console
|
|
91
|
-
tileset: () => console.log('Missed: --tileset [SLPK file]')
|
|
92
|
-
};
|
|
93
|
-
const exceptions: (() => void)[] = [];
|
|
94
|
-
for (const mandatoryOption in mandatoryOptionsWithExceptions) {
|
|
95
|
-
const optionValue = options[mandatoryOption];
|
|
96
|
-
if (!optionValue) {
|
|
97
|
-
exceptions.push(mandatoryOptionsWithExceptions[mandatoryOption]);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (exceptions.length) {
|
|
101
|
-
exceptions.forEach((exeption) => exeption());
|
|
102
|
-
process.exit(1); // eslint-disable-line no-process-exit
|
|
103
|
-
}
|
|
104
|
-
return <ValidatedSLPKExtractionOptions>options;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Parse option from the cli arguments array
|
|
109
|
-
* @param args
|
|
110
|
-
* @returns
|
|
111
|
-
*/
|
|
112
|
-
function parseOptions(args: string[]): SLPKExtractionOptions {
|
|
113
|
-
const opts: SLPKExtractionOptions = {};
|
|
114
|
-
|
|
115
|
-
// eslint-disable-next-line complexity
|
|
116
|
-
args.forEach((arg, index) => {
|
|
117
|
-
if (arg.indexOf('--') === 0) {
|
|
118
|
-
switch (arg) {
|
|
119
|
-
case '--tileset':
|
|
120
|
-
opts.tileset = getURLValue(index, args);
|
|
121
|
-
break;
|
|
122
|
-
case '--output':
|
|
123
|
-
opts.output = getURLValue(index, args);
|
|
124
|
-
break;
|
|
125
|
-
case '--help':
|
|
126
|
-
printHelp();
|
|
127
|
-
break;
|
|
128
|
-
default:
|
|
129
|
-
// eslint-disable-next-line no-console
|
|
130
|
-
console.warn(`Unknown option ${arg}`);
|
|
131
|
-
process.exit(0); // eslint-disable-line
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
return opts;
|
|
136
|
-
}
|