@loaders.gl/tile-converter 3.1.0-alpha.3 → 3.1.0-beta.2
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/bin/converter.js +1 -1
- package/dist/bundle.js +85947 -4
- package/dist/converter.min.js +292 -0
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +267 -0
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
- package/dist/{3d-tiles-converter → es5/3d-tiles-converter}/helpers/b3dm-converter.d.ts +0 -0
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +269 -0
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
- package/dist/{3d-tiles-converter → es5/3d-tiles-converter}/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -0
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +22 -0
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +40 -0
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js +48 -0
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -0
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/{deps-installer → es5/deps-installer}/deps-installer.d.ts +0 -0
- package/dist/es5/deps-installer/deps-installer.js +39 -0
- package/dist/es5/deps-installer/deps-installer.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +65 -0
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +30 -0
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +208 -0
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -0
- package/dist/{i3s-converter → es5/i3s-converter}/helpers/geometry-converter.d.ts +0 -0
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +700 -0
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/node-debug.js +103 -0
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -0
- package/dist/{i3s-converter → es5/i3s-converter}/helpers/node-pages.d.ts +0 -0
- package/dist/es5/i3s-converter/helpers/node-pages.js +150 -0
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -0
- package/dist/es5/i3s-converter/i3s-converter.js +915 -0
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/layers.js +203 -0
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/metadata.js +29 -0
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/node.js +91 -0
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/scene-server.js +35 -0
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +141 -0
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/store.js +105 -0
- package/dist/es5/i3s-converter/json-templates/store.js.map +1 -0
- package/dist/es5/i3s-server/app.js +23 -0
- package/dist/es5/i3s-server/app.js.map +1 -0
- package/dist/{i3s-server → es5/i3s-server}/bin/www +0 -0
- package/dist/{i3s-server → es5/i3s-server}/certs/cert.pem +0 -0
- package/dist/{i3s-server → es5/i3s-server}/certs/key.pem +0 -0
- package/dist/es5/i3s-server/controllers/index-controller.js +33 -0
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -0
- package/dist/es5/i3s-server/routes/index.js +22 -0
- package/dist/es5/i3s-server/routes/index.js.map +1 -0
- package/dist/es5/index.js +40 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/{lib → es5/lib}/geoid-height-model.d.ts +0 -0
- package/dist/es5/lib/geoid-height-model.js +149 -0
- package/dist/es5/lib/geoid-height-model.js.map +1 -0
- package/dist/{lib → es5/lib}/pgm-parser.d.ts +0 -0
- package/dist/es5/lib/pgm-parser.js +192 -0
- package/dist/es5/lib/pgm-parser.js.map +1 -0
- package/dist/es5/lib/utils/compress-util.js +202 -0
- package/dist/es5/lib/utils/compress-util.js.map +1 -0
- package/dist/{lib → es5/lib}/utils/compress-utils.d.ts +0 -0
- package/dist/{lib → es5/lib}/utils/file-utils.d.ts +0 -0
- package/dist/es5/lib/utils/file-utils.js +59 -0
- package/dist/es5/lib/utils/file-utils.js.map +1 -0
- package/dist/{lib → es5/lib}/utils/lod-conversion-utils.d.ts +0 -0
- package/dist/es5/lib/utils/lod-conversion-utils.js +52 -0
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -0
- package/dist/{lib → es5/lib}/utils/statistic-utills.d.ts +0 -0
- package/dist/es5/lib/utils/statistic-utills.js +85 -0
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -0
- package/dist/es5/pgm-loader.js +24 -0
- package/dist/es5/pgm-loader.js.map +1 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/3d-tiles-converter.js +19 -13
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.d.ts +23 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/helpers/b3dm-converter.js +19 -8
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +16 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/helpers/i3s-obb-to-3d-tiles-obb.js +0 -0
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +33 -0
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/json-templates/tileset.js +0 -0
- package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/deps-installer/deps-installer.d.ts +10 -0
- package/dist/{deps-installer → esm/deps-installer}/deps-installer.js +0 -0
- package/dist/esm/deps-installer/deps-installer.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/coordinate-converter.js +0 -0
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/create-scene-server-path.js +0 -0
- package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/geometry-attributes.js +0 -0
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +40 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/geometry-converter.js +29 -31
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/node-debug.js +2 -2
- package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/node-pages.d.ts +144 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/node-pages.js +2 -2
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/i3s-converter.js +50 -31
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/layers.js +0 -0
- package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/metadata.js +1 -1
- package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/node.js +0 -0
- package/dist/esm/i3s-converter/json-templates/node.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/scene-server.js +1 -1
- package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/shared-resources.js +2 -2
- package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/store.js +2 -2
- package/dist/esm/i3s-converter/json-templates/store.js.map +1 -0
- package/dist/{i3s-server → esm/i3s-server}/app.js +0 -0
- package/dist/esm/i3s-server/app.js.map +1 -0
- package/dist/esm/i3s-server/bin/www +102 -0
- package/dist/esm/i3s-server/certs/cert.pem +19 -0
- package/dist/esm/i3s-server/certs/key.pem +27 -0
- package/dist/{i3s-server → esm/i3s-server}/controllers/index-controller.js +2 -2
- package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -0
- package/dist/{i3s-server → esm/i3s-server}/routes/index.js +0 -0
- package/dist/esm/i3s-server/routes/index.js.map +1 -0
- package/dist/{index.js → esm/index.js} +0 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/geoid-height-model.d.ts +41 -0
- package/dist/{lib → esm/lib}/geoid-height-model.js +0 -0
- package/dist/esm/lib/geoid-height-model.js.map +1 -0
- package/dist/esm/lib/pgm-parser.d.ts +14 -0
- package/dist/{lib → esm/lib}/pgm-parser.js +0 -0
- package/dist/esm/lib/pgm-parser.js.map +1 -0
- package/dist/{lib → esm/lib}/utils/compress-util.js +13 -13
- package/dist/esm/lib/utils/compress-util.js.map +1 -0
- package/dist/esm/lib/utils/compress-utils.d.ts +53 -0
- package/dist/esm/lib/utils/file-utils.d.ts +43 -0
- package/dist/{lib → esm/lib}/utils/file-utils.js +1 -1
- package/dist/esm/lib/utils/file-utils.js.map +1 -0
- package/dist/esm/lib/utils/lod-conversion-utils.d.ts +32 -0
- package/dist/{lib → esm/lib}/utils/lod-conversion-utils.js +0 -0
- package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -0
- package/dist/esm/lib/utils/statistic-utills.d.ts +25 -0
- package/dist/{lib → esm/lib}/utils/statistic-utills.js +5 -5
- package/dist/esm/lib/utils/statistic-utills.js.map +1 -0
- package/dist/{pgm-loader.js → esm/pgm-loader.js} +1 -1
- package/dist/esm/pgm-loader.js.map +1 -0
- package/package.json +24 -21
- package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -2
- package/src/3d-tiles-converter/helpers/b3dm-converter.js +35 -7
- package/src/3d-tiles-converter/helpers/texture-atlas.ts +55 -0
- package/src/i3s-converter/helpers/geometry-converter.js +21 -22
- package/src/i3s-converter/i3s-converter.ts +32 -7
- package/src/i3s-converter/json-templates/metadata.js +1 -1
- package/src/i3s-converter/json-templates/scene-server.js +1 -1
- package/src/i3s-converter/json-templates/store.js +2 -2
- package/src/i3s-server/controllers/index-controller.js +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
- package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
- package/dist/bundle.js.map +0 -1
- package/dist/deps-installer/deps-installer.js.map +0 -1
- package/dist/dist.min.js +0 -94
- package/dist/dist.min.js.map +0 -1
- package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
- package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
- package/dist/i3s-converter/i3s-converter.js.map +0 -1
- package/dist/i3s-converter/json-templates/layers.js.map +0 -1
- package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
- package/dist/i3s-converter/json-templates/node.js.map +0 -1
- package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
- package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
- package/dist/i3s-converter/json-templates/store.js.map +0 -1
- package/dist/i3s-server/app.js.map +0 -1
- package/dist/i3s-server/controllers/index-controller.js.map +0 -1
- package/dist/i3s-server/routes/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/geoid-height-model.js.map +0 -1
- package/dist/lib/pgm-parser.js.map +0 -1
- package/dist/lib/utils/compress-util.js.map +0 -1
- package/dist/lib/utils/file-utils.js.map +0 -1
- package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
- package/dist/lib/utils/statistic-utills.js.map +0 -1
- package/dist/pgm-loader.js.map +0 -1
- package/dist/scripts/converter.js +0 -274
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parsePgm = parsePgm;
|
|
7
|
+
|
|
8
|
+
var _geoidHeightModel = require("./geoid-height-model");
|
|
9
|
+
|
|
10
|
+
const ENDL = 10;
|
|
11
|
+
const PIXEL_MAX = 65535;
|
|
12
|
+
|
|
13
|
+
function parsePgm(data, options) {
|
|
14
|
+
const getline = _getLineGenerator(data);
|
|
15
|
+
|
|
16
|
+
let currentLine = getline.next();
|
|
17
|
+
|
|
18
|
+
if (currentLine.done || currentLine.value.line !== 'P5') {
|
|
19
|
+
throw new Error('Geoid model file: File not in PGM format');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let _offset = Number.MAX_VALUE;
|
|
23
|
+
let _scale = 0;
|
|
24
|
+
|
|
25
|
+
let _maxerror = -1;
|
|
26
|
+
|
|
27
|
+
let _rmserror = -1;
|
|
28
|
+
|
|
29
|
+
let _description = 'NONE';
|
|
30
|
+
let _datetime = 'UNKNOWN';
|
|
31
|
+
let _width = 0;
|
|
32
|
+
let _height = 0;
|
|
33
|
+
let _datastart = null;
|
|
34
|
+
let _swidth = null;
|
|
35
|
+
|
|
36
|
+
do {
|
|
37
|
+
currentLine = getline.next();
|
|
38
|
+
const s = currentLine.value.line;
|
|
39
|
+
|
|
40
|
+
if (!s.length) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (s[0] === '#') {
|
|
45
|
+
const sArr = s.split(' ');
|
|
46
|
+
const commentId = sArr[0];
|
|
47
|
+
const key = sArr[1];
|
|
48
|
+
|
|
49
|
+
if (commentId !== '#' || !key) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const infoArr = sArr.length > 2 ? sArr.slice(2) : [];
|
|
54
|
+
|
|
55
|
+
if (key === 'Description') {
|
|
56
|
+
_description = infoArr.join(' ');
|
|
57
|
+
} else if (key === 'DateTime') {
|
|
58
|
+
_datetime = infoArr.join(' ');
|
|
59
|
+
} else if (key === 'Offset') {
|
|
60
|
+
if (!sArr[2]) {
|
|
61
|
+
throw new Error('Geoid model file: Error reading offset');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_offset = parseInt(sArr[2], 10);
|
|
65
|
+
} else if (key === 'Scale') {
|
|
66
|
+
if (!sArr[2]) {
|
|
67
|
+
throw new Error('Geoid model file: Error reading scale');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
_scale = parseFloat(sArr[2]);
|
|
71
|
+
} else if (key === (options.cubic ? 'MaxCubicError' : 'MaxBilinearError')) {
|
|
72
|
+
if (isFinite(parseFloat(sArr[2]))) {
|
|
73
|
+
_maxerror = parseFloat(sArr[2]);
|
|
74
|
+
}
|
|
75
|
+
} else if (key === (options.cubic ? 'RMSCubicError' : 'RMSBilinearError')) {
|
|
76
|
+
if (isFinite(parseFloat(sArr[2]))) {
|
|
77
|
+
_rmserror = parseFloat(sArr[2]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
let sArr = s.split(' ');
|
|
82
|
+
sArr = sArr.filter(testString => testString !== '');
|
|
83
|
+
_width = parseInt(sArr[0], 10);
|
|
84
|
+
_height = parseInt(sArr[1], 10);
|
|
85
|
+
|
|
86
|
+
if (!(_width && _height)) {
|
|
87
|
+
throw new Error('Geoid model file: Error reading raster size');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
} while (!currentLine.done);
|
|
93
|
+
|
|
94
|
+
currentLine = getline.next();
|
|
95
|
+
const maxval = parseInt(currentLine.value.line, 10);
|
|
96
|
+
|
|
97
|
+
if (currentLine.done) {
|
|
98
|
+
throw new Error('Geoid model file: Error reading maxval');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (maxval !== PIXEL_MAX) {
|
|
102
|
+
throw new Error('Geoid model file: Incorrect value of maxval');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
_datastart = currentLine.value.offset;
|
|
106
|
+
_swidth = _width;
|
|
107
|
+
|
|
108
|
+
if (_offset === Number.MAX_VALUE) {
|
|
109
|
+
throw new Error('Geoid model file: Offset not set');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (_scale === 0) {
|
|
113
|
+
throw new Error('Geoid model file: Scale not set');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (_scale < 0) {
|
|
117
|
+
throw new Error('Geoid model file: Scale must be positive');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (_height < 2 || _width < 2) {
|
|
121
|
+
throw new Error('Geoid model file: Raster size too small');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (_width & 1) {
|
|
125
|
+
throw new Error('Geoid model file: Raster width is odd');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!(_height & 1)) {
|
|
129
|
+
throw new Error('Geoid model file: Raster height is even');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const _rlonres = _width / 360;
|
|
133
|
+
|
|
134
|
+
const _rlatres = (_height - 1) / 180;
|
|
135
|
+
|
|
136
|
+
return new _geoidHeightModel.GeoidHeightModel({
|
|
137
|
+
cubic: options.cubic,
|
|
138
|
+
_width,
|
|
139
|
+
_height,
|
|
140
|
+
_rlonres,
|
|
141
|
+
_rlatres,
|
|
142
|
+
_offset,
|
|
143
|
+
_scale,
|
|
144
|
+
_swidth,
|
|
145
|
+
_datastart,
|
|
146
|
+
_maxerror,
|
|
147
|
+
_rmserror,
|
|
148
|
+
_description,
|
|
149
|
+
_datetime,
|
|
150
|
+
data
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function* _getLineGenerator(data) {
|
|
155
|
+
let offset = 0;
|
|
156
|
+
|
|
157
|
+
do {
|
|
158
|
+
const endLineIndex = data.indexOf(ENDL, offset);
|
|
159
|
+
|
|
160
|
+
if (endLineIndex !== -1) {
|
|
161
|
+
const line = data.subarray(offset, endLineIndex);
|
|
162
|
+
offset = endLineIndex + 1;
|
|
163
|
+
yield {
|
|
164
|
+
offset,
|
|
165
|
+
line: _getStringFromCharArray(line)
|
|
166
|
+
};
|
|
167
|
+
} else {
|
|
168
|
+
const line = data.subarray(offset, data.length);
|
|
169
|
+
offset = data.length;
|
|
170
|
+
yield {
|
|
171
|
+
offset,
|
|
172
|
+
line: _getStringFromCharArray(line)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
} while (offset < data.length);
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
offset,
|
|
179
|
+
line: ''
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function _getStringFromCharArray(array) {
|
|
184
|
+
let s = '';
|
|
185
|
+
|
|
186
|
+
for (const char of array) {
|
|
187
|
+
s += String.fromCharCode(char);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return s;
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=pgm-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/pgm-parser.js"],"names":["ENDL","PIXEL_MAX","parsePgm","data","options","getline","_getLineGenerator","currentLine","next","done","value","line","Error","_offset","Number","MAX_VALUE","_scale","_maxerror","_rmserror","_description","_datetime","_width","_height","_datastart","_swidth","s","length","sArr","split","commentId","key","infoArr","slice","join","parseInt","parseFloat","cubic","isFinite","filter","testString","maxval","offset","_rlonres","_rlatres","GeoidHeightModel","endLineIndex","indexOf","subarray","_getStringFromCharArray","array","char","String","fromCharCode"],"mappings":";;;;;;;AAcA;;AAEA,MAAMA,IAAI,GAAG,EAAb;AACA,MAAMC,SAAS,GAAG,KAAlB;;AAGO,SAASC,QAAT,CAAkBC,IAAlB,EAAwBC,OAAxB,EAAiC;AACtC,QAAMC,OAAO,GAAGC,iBAAiB,CAACH,IAAD,CAAjC;;AACA,MAAII,WAAW,GAAGF,OAAO,CAACG,IAAR,EAAlB;;AACA,MAAID,WAAW,CAACE,IAAZ,IAAoBF,WAAW,CAACG,KAAZ,CAAkBC,IAAlB,KAA2B,IAAnD,EAAyD;AACvD,UAAM,IAAIC,KAAJ,CAAU,0CAAV,CAAN;AACD;;AACD,MAAIC,OAAO,GAAGC,MAAM,CAACC,SAArB;AACA,MAAIC,MAAM,GAAG,CAAb;;AACA,MAAIC,SAAS,GAAG,CAAC,CAAjB;;AACA,MAAIC,SAAS,GAAG,CAAC,CAAjB;;AACA,MAAIC,YAAY,GAAG,MAAnB;AACA,MAAIC,SAAS,GAAG,SAAhB;AACA,MAAIC,MAAM,GAAG,CAAb;AACA,MAAIC,OAAO,GAAG,CAAd;AACA,MAAIC,UAAU,GAAG,IAAjB;AACA,MAAIC,OAAO,GAAG,IAAd;;AACA,KAAG;AACDjB,IAAAA,WAAW,GAAGF,OAAO,CAACG,IAAR,EAAd;AACA,UAAMiB,CAAC,GAAGlB,WAAW,CAACG,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B;AAc1BjB,IAAAA;AAd0B,GAArB,CAAP;AAgBD;;AAOD,UAAUG,iBAAV,CAA4BH,IAA5B,EAAkC;AAChC,MAAIsC,MAAM,GAAG,CAAb;;AACA,KAAG;AACD,UAAMI,YAAY,GAAG1C,IAAI,CAAC2C,OAAL,CAAa9C,IAAb,EAAmByC,MAAnB,CAArB;;AACA,QAAII,YAAY,KAAK,CAAC,CAAtB,EAAyB;AACvB,YAAMlC,IAAI,GAAGR,IAAI,CAAC4C,QAAL,CAAcN,MAAd,EAAsBI,YAAtB,CAAb;AACAJ,MAAAA,MAAM,GAAGI,YAAY,GAAG,CAAxB;AACA,YAAM;AAACJ,QAAAA,MAAD;AAAS9B,QAAAA,IAAI,EAAEqC,uBAAuB,CAACrC,IAAD;AAAtC,OAAN;AACD,KAJD,MAIO;AACL,YAAMA,IAAI,GAAGR,IAAI,CAAC4C,QAAL,CAAcN,MAAd,EAAsBtC,IAAI,CAACuB,MAA3B,CAAb;AACAe,MAAAA,MAAM,GAAGtC,IAAI,CAACuB,MAAd;AACA,YAAM;AAACe,QAAAA,MAAD;AAAS9B,QAAAA,IAAI,EAAEqC,uBAAuB,CAACrC,IAAD;AAAtC,OAAN;AACD;AACF,GAXD,QAWS8B,MAAM,GAAGtC,IAAI,CAACuB,MAXvB;;AAYA,SAAO;AAACe,IAAAA,MAAD;AAAS9B,IAAAA,IAAI,EAAE;AAAf,GAAP;AACD;;AAOD,SAASqC,uBAAT,CAAiCC,KAAjC,EAAwC;AACtC,MAAIxB,CAAC,GAAG,EAAR;;AACA,OAAK,MAAMyB,IAAX,IAAmBD,KAAnB,EAA0B;AACxBxB,IAAAA,CAAC,IAAI0B,MAAM,CAACC,YAAP,CAAoBF,IAApB,CAAL;AACD;;AACD,SAAOzB,CAAP;AACD","sourcesContent":["/**\n * Parsing code is ported from GeographicLib-1.50.1\n * https://geographiclib.sourceforge.io/html/index.html\n * Location: /GeographicLib-1.50.1/src/Geoid.cpp\n *\n * File header:\n * * \\file Geoid.cpp\n * * \\brief Implementation for GeographicLib::Geoid class\n * *\n * * Copyright (c) Charles Karney (2009-2018) <charles@karney.com> and licensed\n * * under the MIT/X11 License. For more information, see\n * * https://geographiclib.sourceforge.io/\n **********************************************************************/\n\nimport {GeoidHeightModel} from './geoid-height-model';\n\nconst ENDL = 10;\nconst PIXEL_MAX = 65535;\n\n// eslint-disable-next-line\nexport function parsePgm(data, options) {\n const getline = _getLineGenerator(data);\n let currentLine = getline.next();\n if (currentLine.done || currentLine.value.line !== 'P5') {\n throw new Error('Geoid model file: File not in PGM format');\n }\n let _offset = Number.MAX_VALUE;\n let _scale = 0;\n let _maxerror = -1;\n let _rmserror = -1;\n let _description = 'NONE';\n let _datetime = 'UNKNOWN';\n let _width = 0;\n let _height = 0;\n let _datastart = null;\n let _swidth = null;\n do {\n currentLine = getline.next();\n const s = currentLine.value.line;\n if (!s.length) {\n continue; // eslint-disable-line no-continue\n }\n if (s[0] === '#') {\n const sArr = s.split(' ');\n const commentId = sArr[0];\n const key = sArr[1];\n if (commentId !== '#' || !key) {\n continue; // eslint-disable-line no-continue\n }\n const infoArr = sArr.length > 2 ? sArr.slice(2) : [];\n if (key === 'Description') {\n _description = infoArr.join(' ');\n } else if (key === 'DateTime') {\n _datetime = infoArr.join(' ');\n } else if (key === 'Offset') {\n // eslint-disable-next-line max-depth\n if (!sArr[2]) {\n throw new Error('Geoid model file: Error reading offset');\n }\n _offset = parseInt(sArr[2], 10);\n } else if (key === 'Scale') {\n // eslint-disable-next-line max-depth\n if (!sArr[2]) {\n throw new Error('Geoid model file: Error reading scale');\n }\n _scale = parseFloat(sArr[2]);\n } else if (key === (options.cubic ? 'MaxCubicError' : 'MaxBilinearError')) {\n // It's not an error if the error can't be read\n // eslint-disable-next-line max-depth\n if (isFinite(parseFloat(sArr[2]))) {\n _maxerror = parseFloat(sArr[2]);\n }\n } else if (key === (options.cubic ? 'RMSCubicError' : 'RMSBilinearError')) {\n // It's not an error if the error can't be read\n // eslint-disable-next-line max-depth\n if (isFinite(parseFloat(sArr[2]))) {\n _rmserror = parseFloat(sArr[2]);\n }\n }\n } else {\n let sArr = s.split(' ');\n sArr = sArr.filter((testString) => testString !== '');\n _width = parseInt(sArr[0], 10);\n _height = parseInt(sArr[1], 10);\n if (!(_width && _height)) {\n throw new Error('Geoid model file: Error reading raster size');\n }\n break;\n }\n } while (!currentLine.done);\n\n currentLine = getline.next();\n const maxval = parseInt(currentLine.value.line, 10);\n if (currentLine.done) {\n throw new Error('Geoid model file: Error reading maxval');\n }\n if (maxval !== PIXEL_MAX) {\n throw new Error('Geoid model file: Incorrect value of maxval');\n }\n // Add 1 for whitespace after maxval\n _datastart = currentLine.value.offset;\n _swidth = _width;\n\n if (_offset === Number.MAX_VALUE) {\n throw new Error('Geoid model file: Offset not set');\n }\n if (_scale === 0) {\n throw new Error('Geoid model file: Scale not set');\n }\n if (_scale < 0) {\n throw new Error('Geoid model file: Scale must be positive');\n }\n if (_height < 2 || _width < 2) {\n // Coarsest grid spacing is 180deg.\n throw new Error('Geoid model file: Raster size too small');\n }\n if (_width & 1) {\n // This is so that longitude grids can be extended thru the poles.\n throw new Error('Geoid model file: Raster width is odd');\n }\n if (!(_height & 1)) {\n // This is so that latitude grid includes the equator.\n throw new Error('Geoid model file: Raster height is even');\n }\n\n const _rlonres = _width / 360;\n const _rlatres = (_height - 1) / 180;\n return new GeoidHeightModel({\n cubic: options.cubic,\n _width,\n _height,\n _rlonres,\n _rlatres,\n _offset,\n _scale,\n _swidth,\n _datastart,\n _maxerror,\n _rmserror,\n _description,\n _datetime,\n data\n });\n}\n\n/**\n * Yields strings from pgm file (splitted by 10 - new line symbol)\n * @param {Uint8Array} data - binary buffer of pgm file\n * @returns {Generator}\n */\nfunction* _getLineGenerator(data) {\n let offset = 0;\n do {\n const endLineIndex = data.indexOf(ENDL, offset);\n if (endLineIndex !== -1) {\n const line = data.subarray(offset, endLineIndex);\n offset = endLineIndex + 1;\n yield {offset, line: _getStringFromCharArray(line)};\n } else {\n const line = data.subarray(offset, data.length);\n offset = data.length;\n yield {offset, line: _getStringFromCharArray(line)};\n }\n } while (offset < data.length);\n return {offset, line: ''};\n}\n\n/**\n * Converts Uint8Array of char-codes to string\n * @param {Uint8Array} array - binary buffer of pgm file\n * @returns {string}\n */\nfunction _getStringFromCharArray(array) {\n let s = '';\n for (const char of array) {\n s += String.fromCharCode(char);\n }\n return s;\n}\n"],"file":"pgm-parser.js"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.compressFileWithGzip = compressFileWithGzip;
|
|
9
|
+
exports.compressFilesWithZip = compressFilesWithZip;
|
|
10
|
+
exports.compressWithChildProcess = compressWithChildProcess;
|
|
11
|
+
exports.generateHash128FromZip = generateHash128FromZip;
|
|
12
|
+
exports.addFileToZip = addFileToZip;
|
|
13
|
+
|
|
14
|
+
var _zlib = require("zlib");
|
|
15
|
+
|
|
16
|
+
var _path = require("path");
|
|
17
|
+
|
|
18
|
+
var _fs = require("fs");
|
|
19
|
+
|
|
20
|
+
var _archiver = _interopRequireDefault(require("archiver"));
|
|
21
|
+
|
|
22
|
+
var _fileUtils = require("./file-utils");
|
|
23
|
+
|
|
24
|
+
var _workerUtils = require("@loaders.gl/worker-utils");
|
|
25
|
+
|
|
26
|
+
var _jszip = _interopRequireDefault(require("jszip"));
|
|
27
|
+
|
|
28
|
+
var _crypto = require("@loaders.gl/crypto");
|
|
29
|
+
|
|
30
|
+
var _crypt = _interopRequireDefault(require("crypt"));
|
|
31
|
+
|
|
32
|
+
function compressFileWithGzip(pathFile) {
|
|
33
|
+
const compressedPathFile = "".concat(pathFile, ".gz");
|
|
34
|
+
const gzip = (0, _zlib.createGzip)();
|
|
35
|
+
const input = (0, _fs.createReadStream)(pathFile);
|
|
36
|
+
const output = (0, _fs.createWriteStream)(compressedPathFile);
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
input.on('end', () => {
|
|
39
|
+
console.log("".concat(compressedPathFile, " compressed and saved."));
|
|
40
|
+
resolve(compressedPathFile);
|
|
41
|
+
});
|
|
42
|
+
input.on('error', error => {
|
|
43
|
+
console.log("".concat(compressedPathFile, ": compression error!"));
|
|
44
|
+
reject(error);
|
|
45
|
+
});
|
|
46
|
+
input.pipe(gzip).pipe(output);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function compressFilesWithZip(fileMap, outputFile, level = 0) {
|
|
51
|
+
try {
|
|
52
|
+
await (0, _fileUtils.removeFile)(outputFile);
|
|
53
|
+
} catch (e) {}
|
|
54
|
+
|
|
55
|
+
const output = (0, _fs.createWriteStream)(outputFile);
|
|
56
|
+
const archive = (0, _archiver.default)('zip', {
|
|
57
|
+
zlib: {
|
|
58
|
+
level
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return new Promise(async (resolve, reject) => {
|
|
62
|
+
output.on('close', function () {
|
|
63
|
+
console.log("".concat(outputFile, " saved."));
|
|
64
|
+
console.log("".concat(archive.pointer(), " total bytes"));
|
|
65
|
+
resolve(null);
|
|
66
|
+
});
|
|
67
|
+
output.on('end', function () {
|
|
68
|
+
console.log('Data has been drained');
|
|
69
|
+
resolve(null);
|
|
70
|
+
});
|
|
71
|
+
archive.on('warning', function (err) {
|
|
72
|
+
console.log(err);
|
|
73
|
+
reject(err);
|
|
74
|
+
});
|
|
75
|
+
archive.on('error', function (err) {
|
|
76
|
+
reject(err);
|
|
77
|
+
});
|
|
78
|
+
archive.pipe(output);
|
|
79
|
+
|
|
80
|
+
for (const subFileName in fileMap) {
|
|
81
|
+
const subFileData = fileMap[subFileName];
|
|
82
|
+
await appendFileToArchive(archive, subFileName, subFileData);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
archive.finalize();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function compressWithChildProcess() {
|
|
90
|
+
if (process.platform === 'win32') {
|
|
91
|
+
await compressWithChildProcessWindows(...arguments);
|
|
92
|
+
} else {
|
|
93
|
+
await compressWithChildProcessUnix(...arguments);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function compressWithChildProcessUnix(inputFolder, outputFile, level = 0, inputFiles = '.') {
|
|
98
|
+
const fullOutputFile = (0, _fileUtils.getAbsoluteFilePath)(outputFile);
|
|
99
|
+
const args = ["-".concat(level), '-r', fullOutputFile, inputFiles];
|
|
100
|
+
const childProcess = new _workerUtils.ChildProcessProxy();
|
|
101
|
+
await childProcess.start({
|
|
102
|
+
command: 'zip',
|
|
103
|
+
arguments: args,
|
|
104
|
+
spawn: {
|
|
105
|
+
cwd: inputFolder
|
|
106
|
+
},
|
|
107
|
+
wait: 0
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function compressWithChildProcessWindows(inputFolder, outputFile, level = 0, inputFiles = (0, _path.join)('.', '*'), sevenZipExe) {
|
|
112
|
+
if (inputFiles[0] === '@') {
|
|
113
|
+
inputFiles = "*".concat(inputFiles.substr(1));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const fullOutputFile = (0, _fileUtils.getAbsoluteFilePath)(outputFile);
|
|
117
|
+
const args = ['a', '-tzip', "-mx=".concat(level), fullOutputFile, inputFiles];
|
|
118
|
+
const childProcess = new _workerUtils.ChildProcessProxy();
|
|
119
|
+
await childProcess.start({
|
|
120
|
+
command: sevenZipExe,
|
|
121
|
+
arguments: args,
|
|
122
|
+
spawn: {
|
|
123
|
+
cwd: "".concat(inputFolder)
|
|
124
|
+
},
|
|
125
|
+
wait: 0
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function generateHash128FromZip(inputZipFile, outputFile) {
|
|
130
|
+
const input = await _fs.promises.readFile(inputZipFile);
|
|
131
|
+
const zip = await _jszip.default.loadAsync(input);
|
|
132
|
+
const hashTable = [];
|
|
133
|
+
const zipFiles = zip.files;
|
|
134
|
+
|
|
135
|
+
for (const relativePath in zipFiles) {
|
|
136
|
+
const zipEntry = zipFiles[relativePath];
|
|
137
|
+
const _data = '_data';
|
|
138
|
+
const content = zipEntry[_data].compressedContent;
|
|
139
|
+
if (zipEntry.dir) continue;
|
|
140
|
+
const hash = await new _crypto.MD5Hash().hash(Buffer.from(relativePath.toLowerCase()));
|
|
141
|
+
hashTable.push({
|
|
142
|
+
key: atob(hash),
|
|
143
|
+
value: content.byteOffset
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
hashTable.sort((prev, next) => {
|
|
148
|
+
if (prev.key === next.key) {
|
|
149
|
+
return prev.value < next.value ? -1 : 1;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return prev.key < next.key ? -1 : 1;
|
|
153
|
+
});
|
|
154
|
+
const output = (0, _fs.createWriteStream)(outputFile);
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
output.on('close', function () {
|
|
157
|
+
console.log("".concat(outputFile, " generated and saved"));
|
|
158
|
+
resolve(null);
|
|
159
|
+
});
|
|
160
|
+
output.on('error', function (err) {
|
|
161
|
+
console.log(err);
|
|
162
|
+
reject(err);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
for (const key in hashTable) {
|
|
166
|
+
const item = hashTable[key];
|
|
167
|
+
|
|
168
|
+
const value = _longToByteArray(item.value);
|
|
169
|
+
|
|
170
|
+
output.write(Buffer.from(_crypt.default.hexToBytes(item.key).concat(value)));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
output.close();
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function _longToByteArray(long) {
|
|
178
|
+
const buffer = new ArrayBuffer(8);
|
|
179
|
+
const longNum = new Float64Array(buffer);
|
|
180
|
+
longNum[0] = long;
|
|
181
|
+
return Array.from(new Uint8Array(buffer)).reverse();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {
|
|
185
|
+
await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);
|
|
186
|
+
console.log("".concat(fileName, " added to ").concat(zipFile, "."));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function appendFileToArchive(archive, subFileName, subFileData) {
|
|
190
|
+
return new Promise(resolve => {
|
|
191
|
+
const fileStream = (0, _fs.createReadStream)(subFileData);
|
|
192
|
+
console.log("Compression start: ".concat(subFileName));
|
|
193
|
+
fileStream.on('close', () => {
|
|
194
|
+
console.log("Compression finish: ".concat(subFileName));
|
|
195
|
+
resolve(null);
|
|
196
|
+
});
|
|
197
|
+
archive.append(fileStream, {
|
|
198
|
+
name: subFileName
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=compress-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/utils/compress-util.js"],"names":["compressFileWithGzip","pathFile","compressedPathFile","gzip","input","output","Promise","resolve","reject","on","console","log","error","pipe","compressFilesWithZip","fileMap","outputFile","level","e","archive","zlib","pointer","err","subFileName","subFileData","appendFileToArchive","finalize","compressWithChildProcess","process","platform","compressWithChildProcessWindows","arguments","compressWithChildProcessUnix","inputFolder","inputFiles","fullOutputFile","args","childProcess","ChildProcessProxy","start","command","spawn","cwd","wait","sevenZipExe","substr","generateHash128FromZip","inputZipFile","fs","readFile","zip","JSZip","loadAsync","hashTable","zipFiles","files","relativePath","zipEntry","_data","content","compressedContent","dir","hash","MD5Hash","Buffer","from","toLowerCase","push","key","atob","value","byteOffset","sort","prev","next","item","_longToByteArray","write","crypt","hexToBytes","concat","close","long","buffer","ArrayBuffer","longNum","Float64Array","Array","Uint8Array","reverse","addFileToZip","fileName","zipFile","fileStream","append","name"],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,SAAO,IAAIlB,OAAJ,CAAaC,OAAD,IAAa;AAC9B,UAAMsF,UAAU,GAAG,0BAAiBrE,WAAjB,CAAnB;AACAd,IAAAA,OAAO,CAACC,GAAR,8BAAkCY,WAAlC;AACAsE,IAAAA,UAAU,CAACpF,EAAX,CAAc,OAAd,EAAuB,MAAM;AAC3BC,MAAAA,OAAO,CAACC,GAAR,+BAAmCY,WAAnC;AACAhB,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD,KAHD;AAIAY,IAAAA,OAAO,CAAC2E,MAAR,CAAeD,UAAf,EAA2B;AAACE,MAAAA,IAAI,EAAExE;AAAP,KAA3B;AACD,GARM,CAAP;AASD","sourcesContent":["import {createGzip} from 'zlib';\nimport {join} from 'path';\nimport {promises as fs, createReadStream, createWriteStream} from 'fs';\nimport archiver from 'archiver';\nimport {removeFile} from './file-utils';\nimport {ChildProcessProxy} from '@loaders.gl/worker-utils';\nimport JSZip from 'jszip';\nimport {MD5Hash} from '@loaders.gl/crypto';\nimport crypt from 'crypt';\nimport {getAbsoluteFilePath} from './file-utils';\n\nexport function compressFileWithGzip(pathFile) {\n const compressedPathFile = `${pathFile}.gz`;\n const gzip = createGzip();\n const input = createReadStream(pathFile);\n const output = createWriteStream(compressedPathFile);\n\n return new Promise((resolve, reject) => {\n input.on('end', () => {\n console.log(`${compressedPathFile} compressed and saved.`); // eslint-disable-line no-undef,no-console\n resolve(compressedPathFile);\n });\n input.on('error', (error) => {\n console.log(`${compressedPathFile}: compression error!`); // eslint-disable-line no-undef,no-console\n reject(error);\n });\n input.pipe(gzip).pipe(output);\n });\n}\n\nexport async function compressFilesWithZip(fileMap, outputFile, level = 0) {\n // Before creating a new file, we need to delete the old file\n try {\n await removeFile(outputFile);\n } catch (e) {\n // Do nothing if old file doesn't exist\n }\n\n const output = createWriteStream(outputFile);\n const archive = archiver('zip', {\n zlib: {level} // Sets the compression level.\n });\n\n return new Promise(async (resolve, reject) => {\n // listen for all archive data to be writte\n // 'close' event is fired only when a file descriptor is involved\n output.on('close', function () {\n console.log(`${outputFile} saved.`); // eslint-disable-line no-undef,no-console\n console.log(`${archive.pointer()} total bytes`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // This event is fired when the data source is drained no matter what was the data source.\n // It is not part of this library but rather from the NodeJS Stream API.\n // @see: https://nodejs.org/api/stream.html#stream_event_end\n output.on('end', function () {\n console.log('Data has been drained'); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // good practice to catch warnings (ie stat failures and other non-blocking errors)\n archive.on('warning', function (err) {\n console.log(err); // eslint-disable-line no-undef,no-console\n reject(err);\n });\n\n // good practice to catch this error explicitly\n archive.on('error', function (err) {\n reject(err);\n });\n\n // pipe archive data to the file\n archive.pipe(output);\n\n for (const subFileName in fileMap) {\n const subFileData = fileMap[subFileName];\n await appendFileToArchive(archive, subFileName, subFileData);\n }\n\n // finalize the archive (ie we are done appending files but streams have to finish yet)\n archive.finalize();\n });\n}\n\nexport async function compressWithChildProcess() {\n // eslint-disable-next-line no-undef\n if (process.platform === 'win32') {\n await compressWithChildProcessWindows(...arguments);\n } else {\n await compressWithChildProcessUnix(...arguments);\n }\n}\n\nasync function compressWithChildProcessUnix(inputFolder, outputFile, level = 0, inputFiles = '.') {\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = [`-${level}`, '-r', fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: 'zip',\n arguments: args,\n spawn: {\n cwd: inputFolder\n },\n wait: 0\n });\n}\n\nasync function compressWithChildProcessWindows(\n inputFolder,\n outputFile,\n level = 0,\n inputFiles = join('.', '*'),\n sevenZipExe\n) {\n // Workaround for @listfile issue. In 7z.exe @-leading files are handled as listfiles\n // https://sevenzip.osdn.jp/chm/cmdline/syntax.htm\n if (inputFiles[0] === '@') {\n inputFiles = `*${inputFiles.substr(1)}`;\n }\n\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = ['a', '-tzip', `-mx=${level}`, fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: sevenZipExe,\n arguments: args,\n spawn: {\n cwd: `${inputFolder}`\n },\n wait: 0\n });\n}\n\nexport async function generateHash128FromZip(inputZipFile, outputFile) {\n const input = await fs.readFile(inputZipFile);\n const zip = await JSZip.loadAsync(input);\n const hashTable = [];\n const zipFiles = zip.files;\n for (const relativePath in zipFiles) {\n const zipEntry = zipFiles[relativePath];\n // Had to use a workaround because the correct string is getting the wrong data\n // const content = await zipEntry.async('nodebuffer');\n // _data isn't described in the interface, so lint thought it was wrong\n const _data = '_data';\n const content = zipEntry[_data].compressedContent;\n if (zipEntry.dir) continue; // eslint-disable-line no-continue\n // eslint-disable-next-line no-undef\n const hash = await new MD5Hash().hash(Buffer.from(relativePath.toLowerCase()));\n // eslint-disable-next-line no-undef\n hashTable.push({key: atob(hash), value: content.byteOffset});\n }\n\n hashTable.sort((prev, next) => {\n if (prev.key === next.key) {\n return prev.value < next.value ? -1 : 1;\n }\n return prev.key < next.key ? -1 : 1;\n });\n\n const output = createWriteStream(outputFile);\n return new Promise((resolve, reject) => {\n output.on('close', function () {\n console.log(`${outputFile} generated and saved`); // eslint-disable-line\n resolve(null);\n });\n output.on('error', function (err) {\n console.log(err); // eslint-disable-line\n reject(err);\n });\n for (const key in hashTable) {\n const item = hashTable[key];\n const value = _longToByteArray(item.value);\n // TODO: perhaps you need to wait for the 'drain' event if the write returns 'false'\n // eslint-disable-next-line no-undef\n output.write(Buffer.from(crypt.hexToBytes(item.key).concat(value)));\n }\n output.close();\n });\n}\n\nfunction _longToByteArray(long) {\n const buffer = new ArrayBuffer(8); // JS numbers are 8 bytes long, or 64 bits\n const longNum = new Float64Array(buffer); // so equivalent to Float64\n longNum[0] = long;\n return Array.from(new Uint8Array(buffer)).reverse(); // reverse to get little endian\n}\n\nexport async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {\n await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);\n console.log(`${fileName} added to ${zipFile}.`); // eslint-disable-line\n}\n\nfunction appendFileToArchive(archive, subFileName, subFileData) {\n return new Promise((resolve) => {\n const fileStream = createReadStream(subFileData);\n console.log(`Compression start: ${subFileName}`); // eslint-disable-line no-undef,no-console\n fileStream.on('close', () => {\n console.log(`Compression finish: ${subFileName}`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n archive.append(fileStream, {name: subFileName});\n });\n}\n"],"file":"compress-util.js"}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.writeFile = writeFile;
|
|
7
|
+
exports.writeFileForSlpk = writeFileForSlpk;
|
|
8
|
+
exports.removeDir = removeDir;
|
|
9
|
+
exports.removeFile = removeFile;
|
|
10
|
+
exports.getAbsoluteFilePath = getAbsoluteFilePath;
|
|
11
|
+
|
|
12
|
+
var _fs = require("fs");
|
|
13
|
+
|
|
14
|
+
var _path = require("path");
|
|
15
|
+
|
|
16
|
+
var _compressUtil = require("./compress-util");
|
|
17
|
+
|
|
18
|
+
async function writeFile(path, data, fileName = 'index.json') {
|
|
19
|
+
await _fs.promises.mkdir(path, {
|
|
20
|
+
recursive: true
|
|
21
|
+
});
|
|
22
|
+
const pathFile = (0, _path.join)(path, fileName);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
await _fs.promises.writeFile(pathFile, data);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log("".concat(pathFile, " saved."));
|
|
31
|
+
return pathFile;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function writeFileForSlpk(path, data, fileName = 'index.json', compress = true) {
|
|
35
|
+
const pathFile = await writeFile(path, data, fileName);
|
|
36
|
+
|
|
37
|
+
if (compress) {
|
|
38
|
+
const pathGzFile = await (0, _compressUtil.compressFileWithGzip)(pathFile);
|
|
39
|
+
await removeFile(pathFile);
|
|
40
|
+
return pathGzFile;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return pathFile;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function removeDir(path) {
|
|
47
|
+
return _fs.promises.rmdir(path, {
|
|
48
|
+
recursive: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function removeFile(path) {
|
|
53
|
+
return _fs.promises.unlink(path);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getAbsoluteFilePath(filePath) {
|
|
57
|
+
return (0, _path.isAbsolute)(filePath) ? filePath : (0, _path.join)(process.cwd(), filePath);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=file-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/utils/file-utils.js"],"names":["writeFile","path","data","fileName","fs","mkdir","recursive","pathFile","err","console","log","writeFileForSlpk","compress","pathGzFile","removeFile","removeDir","rmdir","unlink","getAbsoluteFilePath","filePath","process","cwd"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAEO,eAAeA,SAAf,CAAyBC,IAAzB,EAA+BC,IAA/B,EAAqCC,QAAQ,GAAG,YAAhD,EAA8D;AACnE,QAAMC,aAAGC,KAAH,CAASJ,IAAT,EAAe;AAACK,IAAAA,SAAS,EAAE;AAAZ,GAAf,CAAN;AACA,QAAMC,QAAQ,GAAG,gBAAKN,IAAL,EAAWE,QAAX,CAAjB;;AACA,MAAI;AACF,UAAMC,aAAGJ,SAAH,CAAaO,QAAb,EAAuBL,IAAvB,CAAN;AACD,GAFD,CAEE,OAAOM,GAAP,EAAY;AACZ,UAAMA,GAAN;AACD;;AACDC,EAAAA,OAAO,CAACC,GAAR,WAAeH,QAAf;AACA,SAAOA,QAAP;AACD;;AAEM,eAAeI,gBAAf,CAAgCV,IAAhC,EAAsCC,IAAtC,EAA4CC,QAAQ,GAAG,YAAvD,EAAqES,QAAQ,GAAG,IAAhF,EAAsF;AAC3F,QAAML,QAAQ,GAAG,MAAMP,SAAS,CAACC,IAAD,EAAOC,IAAP,EAAaC,QAAb,CAAhC;;AACA,MAAIS,QAAJ,EAAc;AACZ,UAAMC,UAAU,GAAG,MAAM,wCAAqBN,QAArB,CAAzB;AAEA,UAAMO,UAAU,CAACP,QAAD,CAAhB;AACA,WAAOM,UAAP;AACD;;AACD,SAAON,QAAP;AACD;;AAEM,SAASQ,SAAT,CAAmBd,IAAnB,EAAyB;AAC9B,SAAOG,aAAGY,KAAH,CAASf,IAAT,EAAe;AAACK,IAAAA,SAAS,EAAE;AAAZ,GAAf,CAAP;AACD;;AAEM,SAASQ,UAAT,CAAoBb,IAApB,EAA0B;AAC/B,SAAOG,aAAGa,MAAH,CAAUhB,IAAV,CAAP;AACD;;AAEM,SAASiB,mBAAT,CAA6BC,QAA7B,EAAuC;AAC5C,SAAO,sBAAWA,QAAX,IAAuBA,QAAvB,GAAkC,gBAAKC,OAAO,CAACC,GAAR,EAAL,EAAoBF,QAApB,CAAzC;AACD","sourcesContent":["import {promises as fs} from 'fs';\nimport {isAbsolute, join} from 'path';\nimport {compressFileWithGzip} from './compress-util';\n\nexport async function writeFile(path, data, fileName = 'index.json') {\n await fs.mkdir(path, {recursive: true});\n const pathFile = join(path, fileName);\n try {\n await fs.writeFile(pathFile, data);\n } catch (err) {\n throw err;\n }\n console.log(`${pathFile} saved.`); // eslint-disable-line\n return pathFile;\n}\n\nexport async function writeFileForSlpk(path, data, fileName = 'index.json', compress = true) {\n const pathFile = await writeFile(path, data, fileName);\n if (compress) {\n const pathGzFile = await compressFileWithGzip(pathFile);\n // After compression, we don't need an uncompressed file\n await removeFile(pathFile);\n return pathGzFile;\n }\n return pathFile;\n}\n\nexport function removeDir(path) {\n return fs.rmdir(path, {recursive: true});\n}\n\nexport function removeFile(path) {\n return fs.unlink(path);\n}\n\nexport function getAbsoluteFilePath(filePath) {\n return isAbsolute(filePath) ? filePath : join(process.cwd(), filePath); // eslint-disable-line no-undef\n}\n"],"file":"file-utils.js"}
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.convertGeometricErrorToScreenThreshold = convertGeometricErrorToScreenThreshold;
|
|
7
|
+
exports.convertScreenThresholdToGeometricError = convertScreenThresholdToGeometricError;
|
|
8
|
+
const DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR = 16;
|
|
9
|
+
|
|
10
|
+
function convertGeometricErrorToScreenThreshold(tile, coordinates) {
|
|
11
|
+
const lodSelection = [];
|
|
12
|
+
const boundingVolume = tile.boundingVolume;
|
|
13
|
+
const lodMetricValue = tile.lodMetricValue || 0.1;
|
|
14
|
+
const maxScreenThreshold = {
|
|
15
|
+
metricType: 'maxScreenThreshold',
|
|
16
|
+
maxError: coordinates.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR / lodMetricValue
|
|
17
|
+
};
|
|
18
|
+
const maxScreenThresholdSQ = {
|
|
19
|
+
metricType: 'maxScreenThresholdSQ',
|
|
20
|
+
maxError: Math.PI * 0.25 * maxScreenThreshold.maxError * maxScreenThreshold.maxError
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (boundingVolume.constructor.name === 'OrientedBoundingBox') {
|
|
24
|
+
lodSelection.push(maxScreenThresholdSQ);
|
|
25
|
+
lodSelection.push(maxScreenThreshold);
|
|
26
|
+
} else {
|
|
27
|
+
lodSelection.push(maxScreenThreshold);
|
|
28
|
+
lodSelection.push(maxScreenThresholdSQ);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return lodSelection;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function convertScreenThresholdToGeometricError(node) {
|
|
35
|
+
const metricData = node.header.lodSelection.maxScreenThreshold || {};
|
|
36
|
+
let maxError = metricData.maxError;
|
|
37
|
+
|
|
38
|
+
if (!maxError) {
|
|
39
|
+
const sqMetricData = node.header.lodSelection.maxScreenThresholdSQ;
|
|
40
|
+
|
|
41
|
+
if (sqMetricData) {
|
|
42
|
+
maxError = Math.sqrt(sqMetricData.maxError / (Math.PI * 0.25));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!maxError) {
|
|
47
|
+
maxError = DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return node.header.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR / maxError;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=lod-conversion-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/utils/lod-conversion-utils.js"],"names":["DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR","convertGeometricErrorToScreenThreshold","tile","coordinates","lodSelection","boundingVolume","lodMetricValue","maxScreenThreshold","metricType","maxError","mbs","maxScreenThresholdSQ","Math","PI","constructor","name","push","convertScreenThresholdToGeometricError","node","metricData","header","sqMetricData","sqrt"],"mappings":";;;;;;;AACA,MAAMA,kCAAkC,GAAG,EAA3C;;AAeO,SAASC,sCAAT,CAAgDC,IAAhD,EAAsDC,WAAtD,EAAmE;AACxE,QAAMC,YAAY,GAAG,EAArB;AACA,QAAMC,cAAc,GAAGH,IAAI,CAACG,cAA5B;AACA,QAAMC,cAAc,GAAGJ,IAAI,CAACI,cAAL,IAAuB,GAA9C;AACA,QAAMC,kBAAkB,GAAG;AACzBC,IAAAA,UAAU,EAAE,oBADa;AAEzBC,IAAAA,QAAQ,EAAGN,WAAW,CAACO,GAAZ,CAAgB,CAAhB,IAAqB,CAArB,GAAyBV,kCAA1B,GAAgEM;AAFjD,GAA3B;AAIA,QAAMK,oBAAoB,GAAG;AAC3BH,IAAAA,UAAU,EAAE,sBADe;AAE3BC,IAAAA,QAAQ,EAAEG,IAAI,CAACC,EAAL,GAAU,IAAV,GAAiBN,kBAAkB,CAACE,QAApC,GAA+CF,kBAAkB,CAACE;AAFjD,GAA7B;;AAKA,MAAIJ,cAAc,CAACS,WAAf,CAA2BC,IAA3B,KAAoC,qBAAxC,EAA+D;AAC7DX,IAAAA,YAAY,CAACY,IAAb,CAAkBL,oBAAlB;AACAP,IAAAA,YAAY,CAACY,IAAb,CAAkBT,kBAAlB;AACD,GAHD,MAGO;AACLH,IAAAA,YAAY,CAACY,IAAb,CAAkBT,kBAAlB;AACAH,IAAAA,YAAY,CAACY,IAAb,CAAkBL,oBAAlB;AACD;;AAED,SAAOP,YAAP;AACD;;AAEM,SAASa,sCAAT,CAAgDC,IAAhD,EAAsD;AAC3D,QAAMC,UAAU,GAAGD,IAAI,CAACE,MAAL,CAAYhB,YAAZ,CAAyBG,kBAAzB,IAA+C,EAAlE;AACA,MAAIE,QAAQ,GAAGU,UAAU,CAACV,QAA1B;;AACA,MAAI,CAACA,QAAL,EAAe;AACb,UAAMY,YAAY,GAAGH,IAAI,CAACE,MAAL,CAAYhB,YAAZ,CAAyBO,oBAA9C;;AACA,QAAIU,YAAJ,EAAkB;AAChBZ,MAAAA,QAAQ,GAAGG,IAAI,CAACU,IAAL,CAAUD,YAAY,CAACZ,QAAb,IAAyBG,IAAI,CAACC,EAAL,GAAU,IAAnC,CAAV,CAAX;AACD;AACF;;AAED,MAAI,CAACJ,QAAL,EAAe;AACbA,IAAAA,QAAQ,GAAGT,kCAAX;AACD;;AAED,SAAQkB,IAAI,CAACE,MAAL,CAAYV,GAAZ,CAAgB,CAAhB,IAAqB,CAArB,GAAyBV,kCAA1B,GAAgES,QAAvE;AACD","sourcesContent":["// https://cesium.com/docs/cesiumjs-ref-doc/Cesium3DTileset.html\nconst DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR = 16;\n/**\n * Do conversion from geometric error to screen threshold\n * @param {Object} tile\n * @param {Object} coordinates\n * In 3DTiles we have HLOD logic and parent tile also has bigger lodMetric value then its children.\n * In I3s we have reverse logic related to maxError. Parent has lower maxError than its child.\n * In nodes where are no children tile.lodMetricValue is 0. This is because of logic of HLOD in 3DTiles\n * 3DTiles spec:\n * https://github.com/CesiumGS/3d-tiles/tree/master/specification#geometric-error\n * I3S spec:\n * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/lodSelection.cmn.md\n * To avoid infinity values when we do calculations of maxError we shold replace 0 with value which allows us\n * to make child maxError bigger than his parent maxError.\n */\nexport function convertGeometricErrorToScreenThreshold(tile, coordinates) {\n const lodSelection = [];\n const boundingVolume = tile.boundingVolume;\n const lodMetricValue = tile.lodMetricValue || 0.1;\n const maxScreenThreshold = {\n metricType: 'maxScreenThreshold',\n maxError: (coordinates.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / lodMetricValue\n };\n const maxScreenThresholdSQ = {\n metricType: 'maxScreenThresholdSQ',\n maxError: Math.PI * 0.25 * maxScreenThreshold.maxError * maxScreenThreshold.maxError\n };\n\n if (boundingVolume.constructor.name === 'OrientedBoundingBox') {\n lodSelection.push(maxScreenThresholdSQ);\n lodSelection.push(maxScreenThreshold);\n } else {\n lodSelection.push(maxScreenThreshold);\n lodSelection.push(maxScreenThresholdSQ);\n }\n\n return lodSelection;\n}\n\nexport function convertScreenThresholdToGeometricError(node) {\n const metricData = node.header.lodSelection.maxScreenThreshold || {};\n let maxError = metricData.maxError;\n if (!maxError) {\n const sqMetricData = node.header.lodSelection.maxScreenThresholdSQ;\n if (sqMetricData) {\n maxError = Math.sqrt(sqMetricData.maxError / (Math.PI * 0.25));\n }\n }\n\n if (!maxError) {\n maxError = DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR;\n }\n\n return (node.header.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / maxError;\n}\n"],"file":"lod-conversion-utils.js"}
|
|
File without changes
|