landxml 0.6.0 → 0.6.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/CHANGELOG.md +12 -0
- package/dist/index.js +139 -71
- package/dist/{index.cjs → index.mjs} +103 -107
- package/package.json +1 -2
- /package/dist/{index.d.cts → index.d.mts} +0 -0
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
1
3
|
var __defProp = Object.defineProperty;
|
|
2
4
|
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
6
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
8
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
10
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
11
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
12
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -29,6 +34,27 @@ var __objRest = (source, exclude) => {
|
|
|
29
34
|
}
|
|
30
35
|
return target;
|
|
31
36
|
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
+
mod
|
|
56
|
+
));
|
|
57
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
58
|
var __async = (__this, __arguments, generator) => {
|
|
33
59
|
return new Promise((resolve, reject) => {
|
|
34
60
|
var fulfilled = (value) => {
|
|
@@ -50,6 +76,15 @@ var __async = (__this, __arguments, generator) => {
|
|
|
50
76
|
});
|
|
51
77
|
};
|
|
52
78
|
|
|
79
|
+
// src/index.ts
|
|
80
|
+
var src_exports = {};
|
|
81
|
+
__export(src_exports, {
|
|
82
|
+
reprojectGeoJson: () => reproject_geojson_default,
|
|
83
|
+
toGeojsonContours: () => to_geojson_contours_default,
|
|
84
|
+
toGlb: () => to_glb_default
|
|
85
|
+
});
|
|
86
|
+
module.exports = __toCommonJS(src_exports);
|
|
87
|
+
|
|
53
88
|
// src/private/filter-by-surfaceId.ts
|
|
54
89
|
var filterBySurfaceId = (parsedSurfaces, surfaceId) => {
|
|
55
90
|
let filtered = [...parsedSurfaces];
|
|
@@ -68,7 +103,7 @@ var filterBySurfaceId = (parsedSurfaces, surfaceId) => {
|
|
|
68
103
|
var filter_by_surfaceId_default = filterBySurfaceId;
|
|
69
104
|
|
|
70
105
|
// src/private/get-glb.ts
|
|
71
|
-
|
|
106
|
+
var import_core = require("@gltf-transform/core");
|
|
72
107
|
var findXYAxisMedians = (vertices) => {
|
|
73
108
|
var _a, _b;
|
|
74
109
|
vertices = vertices.slice().filter(Boolean);
|
|
@@ -83,7 +118,7 @@ var getGlb = (data, customCenter) => __async(void 0, null, function* () {
|
|
|
83
118
|
return [x - center[0], z, -(y - center[1])];
|
|
84
119
|
}).reduce((prev, curr) => prev.concat(curr), []);
|
|
85
120
|
const triangles = data.surfaceDefinition.faces.reduce((prev, curr) => prev.concat(curr), []);
|
|
86
|
-
const doc = new Document();
|
|
121
|
+
const doc = new import_core.Document();
|
|
87
122
|
const buffer = doc.createBuffer();
|
|
88
123
|
const position = doc.createAccessor().setType("VEC3").setArray(new Float32Array(vertices)).setBuffer(buffer);
|
|
89
124
|
const indices = doc.createAccessor().setType("SCALAR").setArray(new Uint32Array(triangles)).setBuffer(buffer);
|
|
@@ -91,7 +126,7 @@ var getGlb = (data, customCenter) => __async(void 0, null, function* () {
|
|
|
91
126
|
const mesh = doc.createMesh().addPrimitive(prim);
|
|
92
127
|
const node = doc.createNode().setMesh(mesh);
|
|
93
128
|
const scene = doc.createScene().addChild(node);
|
|
94
|
-
const glb = yield new WebIO().writeBinary(doc);
|
|
129
|
+
const glb = yield new import_core.WebIO().writeBinary(doc);
|
|
95
130
|
return { glb, center };
|
|
96
131
|
});
|
|
97
132
|
var get_glb_default = getGlb;
|
|
@@ -110,36 +145,53 @@ var downloadGlb = (glbData, fileName) => {
|
|
|
110
145
|
var download_glb_default = downloadGlb;
|
|
111
146
|
|
|
112
147
|
// src/private/parse-xml.ts
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var surfaceDefWorker = createEasyWebWorker(
|
|
148
|
+
var import_easy_web_worker = require("easy-web-worker");
|
|
149
|
+
var import_xml_js = __toESM(require("xml-js"));
|
|
150
|
+
var surfaceDefWorker = (0, import_easy_web_worker.createEasyWebWorker)(
|
|
116
151
|
({ onMessage }) => {
|
|
117
152
|
onMessage((message) => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
153
|
+
try {
|
|
154
|
+
const { task } = message.payload;
|
|
155
|
+
if (task === "parse-surface-points") {
|
|
156
|
+
const { points } = message.payload;
|
|
157
|
+
message.resolve(
|
|
158
|
+
points.map((pt) => [pt.attr.id, pt.content.split(" ").map(Number)]).map((v) => [v[0], [v[1][1], v[1][0], v[1][2]]])
|
|
159
|
+
);
|
|
160
|
+
} else if (task === "parse-surface-faces") {
|
|
161
|
+
const { faces, idMap } = message.payload;
|
|
162
|
+
message.resolve(
|
|
163
|
+
faces.flatMap((f) => {
|
|
164
|
+
var _a;
|
|
165
|
+
if (typeof f === "string")
|
|
166
|
+
return [f.split(" ").map((id) => idMap == null ? void 0 : idMap.indexOf(id))];
|
|
167
|
+
if (((_a = f == null ? void 0 : f.attr) == null ? void 0 : _a.i) === "1")
|
|
168
|
+
return [];
|
|
169
|
+
return [f.content.split(" ").map((id) => idMap == null ? void 0 : idMap.indexOf(id))];
|
|
170
|
+
})
|
|
171
|
+
);
|
|
172
|
+
} else if (task === "find-neighboring-faces") {
|
|
173
|
+
const { faces, range: { start, end } } = message.payload;
|
|
174
|
+
const faceNeighbors = [];
|
|
175
|
+
for (let i = start; i < end; i++) {
|
|
176
|
+
const sourceFace = faces[i];
|
|
177
|
+
const neighborA = faces.findIndex((f, j) => f.findIndex((v) => v === sourceFace[0]) >= 0 && f.findIndex((v) => v === sourceFace[1]) >= 0 && j !== i);
|
|
178
|
+
const neighborB = faces.findIndex((f, j) => f.findIndex((v) => v === sourceFace[1]) >= 0 && f.findIndex((v) => v === sourceFace[2]) >= 0 && j !== i);
|
|
179
|
+
const neighborC = faces.findIndex((f, j) => f.findIndex((v) => v === sourceFace[0]) >= 0 && f.findIndex((v) => v === sourceFace[2]) >= 0 && j !== i);
|
|
180
|
+
faceNeighbors.push([neighborA, neighborB, neighborC]);
|
|
181
|
+
}
|
|
182
|
+
message.resolve(faceNeighbors);
|
|
183
|
+
}
|
|
184
|
+
} catch (e) {
|
|
185
|
+
message.reject(e);
|
|
134
186
|
}
|
|
135
187
|
});
|
|
136
188
|
},
|
|
137
|
-
{ maxWorkers:
|
|
189
|
+
{ maxWorkers: 16 }
|
|
138
190
|
);
|
|
139
191
|
var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
140
192
|
return new Promise((resolve, reject) => __async(void 0, null, function* () {
|
|
141
193
|
var _a, _b, _c, _d, _e;
|
|
142
|
-
const parsed =
|
|
194
|
+
const parsed = import_xml_js.default.xml2js(xmlString, {
|
|
143
195
|
compact: true,
|
|
144
196
|
attributesKey: "attr",
|
|
145
197
|
textKey: "content"
|
|
@@ -162,21 +214,22 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
162
214
|
const Faces = surface.Definition.Faces.F;
|
|
163
215
|
let ptsIdArray = [];
|
|
164
216
|
let faces = [];
|
|
217
|
+
let faceNeighbors = [];
|
|
165
218
|
if (Pnts.length > 1e4) {
|
|
166
219
|
const sliceIndexes = [...Array(20).keys()].map((i) => Math.round(Pnts.length / 20 * i));
|
|
167
220
|
ptsIdArray = (yield Promise.all(
|
|
168
221
|
sliceIndexes.map(
|
|
169
222
|
(v, i, a) => new Promise((resolve3, reject3) => __async(void 0, null, function* () {
|
|
170
223
|
const pts = yield surfaceDefWorker.send({
|
|
171
|
-
|
|
172
|
-
|
|
224
|
+
task: "parse-surface-points",
|
|
225
|
+
points: Pnts.slice(a[i], a[i + 1] || Pnts.length)
|
|
173
226
|
});
|
|
174
227
|
resolve3(pts);
|
|
175
228
|
}))
|
|
176
229
|
)
|
|
177
230
|
)).reduce((prev, curr) => [...prev, ...curr], []);
|
|
178
231
|
} else {
|
|
179
|
-
ptsIdArray = yield surfaceDefWorker.send({
|
|
232
|
+
ptsIdArray = yield surfaceDefWorker.send({ task: "parse-surface-points", points: Pnts });
|
|
180
233
|
}
|
|
181
234
|
const points = ptsIdArray.map((v) => v[1]);
|
|
182
235
|
const pointsIdMap = ptsIdArray.map((v) => v[0]);
|
|
@@ -186,8 +239,8 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
186
239
|
sliceIndexes.map(
|
|
187
240
|
(v, i, a) => new Promise((resolve3, reject3) => __async(void 0, null, function* () {
|
|
188
241
|
const fcs = yield surfaceDefWorker.send({
|
|
189
|
-
|
|
190
|
-
|
|
242
|
+
task: "parse-surface-faces",
|
|
243
|
+
faces: Faces.slice(a[i], a[i + 1] || Faces.length),
|
|
191
244
|
idMap: pointsIdMap
|
|
192
245
|
});
|
|
193
246
|
resolve3(fcs);
|
|
@@ -195,7 +248,38 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
195
248
|
)
|
|
196
249
|
)).reduce((prev, curr) => [...prev, ...curr], []);
|
|
197
250
|
} else {
|
|
198
|
-
faces = yield surfaceDefWorker.send({
|
|
251
|
+
faces = yield surfaceDefWorker.send({
|
|
252
|
+
task: "parse-surface-faces",
|
|
253
|
+
faces: Faces,
|
|
254
|
+
idMap: pointsIdMap
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
if (Faces.length > 1e4) {
|
|
258
|
+
const sliceIndexes = [...Array(20).keys()].map((i) => Math.round(Faces.length / 20 * i));
|
|
259
|
+
faceNeighbors = (yield Promise.all(
|
|
260
|
+
sliceIndexes.map(
|
|
261
|
+
(v, i, a) => new Promise((resolve3, reject3) => __async(void 0, null, function* () {
|
|
262
|
+
const fcs = yield surfaceDefWorker.send({
|
|
263
|
+
task: "find-neighboring-faces",
|
|
264
|
+
faces,
|
|
265
|
+
range: {
|
|
266
|
+
start: a[i],
|
|
267
|
+
end: a[i + 1] || faces.length
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
resolve3(fcs);
|
|
271
|
+
}))
|
|
272
|
+
)
|
|
273
|
+
)).reduce((prev, curr) => [...prev, ...curr], []);
|
|
274
|
+
} else {
|
|
275
|
+
faceNeighbors = yield surfaceDefWorker.send({
|
|
276
|
+
task: "find-neighboring-faces",
|
|
277
|
+
faces,
|
|
278
|
+
range: {
|
|
279
|
+
start: 0,
|
|
280
|
+
end: faces.length
|
|
281
|
+
}
|
|
282
|
+
});
|
|
199
283
|
}
|
|
200
284
|
resolve2({
|
|
201
285
|
sourceFile,
|
|
@@ -205,7 +289,8 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
205
289
|
wktString,
|
|
206
290
|
surfaceDefinition: {
|
|
207
291
|
points,
|
|
208
|
-
faces
|
|
292
|
+
faces,
|
|
293
|
+
faceNeighbors
|
|
209
294
|
}
|
|
210
295
|
});
|
|
211
296
|
}));
|
|
@@ -244,8 +329,8 @@ var toGlb = (landXmlString, center = "auto", surfaceId = -1) => __async(void 0,
|
|
|
244
329
|
var to_glb_default = toGlb;
|
|
245
330
|
|
|
246
331
|
// src/private/get-contours.ts
|
|
247
|
-
|
|
248
|
-
var contoursWorker =
|
|
332
|
+
var import_easy_web_worker2 = require("easy-web-worker");
|
|
333
|
+
var contoursWorker = (0, import_easy_web_worker2.createEasyWebWorker)(
|
|
249
334
|
({ onMessage }) => {
|
|
250
335
|
const contourLineOnFace = (face, z) => {
|
|
251
336
|
let vertsAtElevation = 0;
|
|
@@ -443,39 +528,21 @@ var get_contours_default = getContours;
|
|
|
443
528
|
|
|
444
529
|
// src/private/get-outline.ts
|
|
445
530
|
var getOutline = (surface) => {
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
[
|
|
452
|
-
[f[
|
|
453
|
-
|
|
454
|
-
[f[
|
|
455
|
-
].forEach(([a, b]) => {
|
|
456
|
-
if (a < b) {
|
|
457
|
-
pairs.push(`${a};${b}`);
|
|
458
|
-
} else {
|
|
459
|
-
pairs.push(`${b};${a}`);
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
pairs.forEach((pair) => {
|
|
463
|
-
i = triangleVertexIdEdgePairs.indexOf(pair);
|
|
464
|
-
if (i >= 0) {
|
|
465
|
-
triangleVertexIdEdgePairs.splice(i, 1);
|
|
466
|
-
} else {
|
|
467
|
-
triangleVertexIdEdgePairs.push(pair);
|
|
468
|
-
}
|
|
469
|
-
});
|
|
531
|
+
const vertexIndexPairEdges = [];
|
|
532
|
+
surface.surfaceDefinition.faces.forEach((f, i) => {
|
|
533
|
+
const neighbors = surface.surfaceDefinition.faceNeighbors[i];
|
|
534
|
+
if (neighbors[0] === -1)
|
|
535
|
+
vertexIndexPairEdges.push([f[0], f[1]]);
|
|
536
|
+
if (neighbors[1] === -1)
|
|
537
|
+
vertexIndexPairEdges.push([f[1], f[2]]);
|
|
538
|
+
if (neighbors[2] === -1)
|
|
539
|
+
vertexIndexPairEdges.push([f[0], f[2]]);
|
|
470
540
|
});
|
|
471
541
|
const edges = [];
|
|
472
|
-
|
|
473
|
-
const [v1, v2] = pair.
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
});
|
|
477
|
-
if (v1 && v2)
|
|
478
|
-
edges.push([v1, v2]);
|
|
542
|
+
vertexIndexPairEdges.map((pair) => {
|
|
543
|
+
const [v1, v2] = pair.map((vertexIndex) => surface.surfaceDefinition.points[vertexIndex]);
|
|
544
|
+
if (typeof v1 !== "undefined" && typeof v2 !== "undefined")
|
|
545
|
+
edges.push([v1.slice(0, 2), v2.slice(0, 2)]);
|
|
479
546
|
});
|
|
480
547
|
return constructGeojson([{ elevation: 0, polylines: linesToPolyLines(edges) }]);
|
|
481
548
|
};
|
|
@@ -508,7 +575,7 @@ var toGeojsonContours = (landXmlString, contourInterval = 2, generateOutline = t
|
|
|
508
575
|
var to_geojson_contours_default = toGeojsonContours;
|
|
509
576
|
|
|
510
577
|
// src/public/reproject-geojson.ts
|
|
511
|
-
|
|
578
|
+
var import_proj4 = __toESM(require("proj4"));
|
|
512
579
|
var reprojectGeoJson = (geojson, sourceProjection, targetProjection = "WGS84", keepOriginalGeometryAsFeatureProperty = true) => {
|
|
513
580
|
const transformCoordinates = (coordinates, sourceProjection2, targetProjection2) => {
|
|
514
581
|
if (Array.isArray(coordinates[0])) {
|
|
@@ -516,7 +583,7 @@ var reprojectGeoJson = (geojson, sourceProjection, targetProjection = "WGS84", k
|
|
|
516
583
|
(subCoordinates) => transformCoordinates(subCoordinates, sourceProjection2, targetProjection2)
|
|
517
584
|
);
|
|
518
585
|
} else {
|
|
519
|
-
coordinates =
|
|
586
|
+
coordinates = (0, import_proj4.default)(sourceProjection2, targetProjection2, coordinates);
|
|
520
587
|
}
|
|
521
588
|
return coordinates;
|
|
522
589
|
};
|
|
@@ -541,8 +608,9 @@ var reprojectGeoJson = (geojson, sourceProjection, targetProjection = "WGS84", k
|
|
|
541
608
|
return geojson;
|
|
542
609
|
};
|
|
543
610
|
var reproject_geojson_default = reprojectGeoJson;
|
|
544
|
-
export
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
611
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
612
|
+
0 && (module.exports = {
|
|
613
|
+
reprojectGeoJson,
|
|
614
|
+
toGeojsonContours,
|
|
615
|
+
toGlb
|
|
616
|
+
});
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
1
|
var __defProp = Object.defineProperty;
|
|
4
2
|
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -34,27 +29,6 @@ var __objRest = (source, exclude) => {
|
|
|
34
29
|
}
|
|
35
30
|
return target;
|
|
36
31
|
};
|
|
37
|
-
var __export = (target, all) => {
|
|
38
|
-
for (var name in all)
|
|
39
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
-
};
|
|
41
|
-
var __copyProps = (to, from, except, desc) => {
|
|
42
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
-
for (let key of __getOwnPropNames(from))
|
|
44
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
-
}
|
|
47
|
-
return to;
|
|
48
|
-
};
|
|
49
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
-
mod
|
|
56
|
-
));
|
|
57
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
32
|
var __async = (__this, __arguments, generator) => {
|
|
59
33
|
return new Promise((resolve, reject) => {
|
|
60
34
|
var fulfilled = (value) => {
|
|
@@ -76,15 +50,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
76
50
|
});
|
|
77
51
|
};
|
|
78
52
|
|
|
79
|
-
// src/index.ts
|
|
80
|
-
var src_exports = {};
|
|
81
|
-
__export(src_exports, {
|
|
82
|
-
reprojectGeoJson: () => reproject_geojson_default,
|
|
83
|
-
toGeojsonContours: () => to_geojson_contours_default,
|
|
84
|
-
toGlb: () => to_glb_default
|
|
85
|
-
});
|
|
86
|
-
module.exports = __toCommonJS(src_exports);
|
|
87
|
-
|
|
88
53
|
// src/private/filter-by-surfaceId.ts
|
|
89
54
|
var filterBySurfaceId = (parsedSurfaces, surfaceId) => {
|
|
90
55
|
let filtered = [...parsedSurfaces];
|
|
@@ -103,7 +68,7 @@ var filterBySurfaceId = (parsedSurfaces, surfaceId) => {
|
|
|
103
68
|
var filter_by_surfaceId_default = filterBySurfaceId;
|
|
104
69
|
|
|
105
70
|
// src/private/get-glb.ts
|
|
106
|
-
|
|
71
|
+
import { Document, WebIO } from "@gltf-transform/core";
|
|
107
72
|
var findXYAxisMedians = (vertices) => {
|
|
108
73
|
var _a, _b;
|
|
109
74
|
vertices = vertices.slice().filter(Boolean);
|
|
@@ -118,7 +83,7 @@ var getGlb = (data, customCenter) => __async(void 0, null, function* () {
|
|
|
118
83
|
return [x - center[0], z, -(y - center[1])];
|
|
119
84
|
}).reduce((prev, curr) => prev.concat(curr), []);
|
|
120
85
|
const triangles = data.surfaceDefinition.faces.reduce((prev, curr) => prev.concat(curr), []);
|
|
121
|
-
const doc = new
|
|
86
|
+
const doc = new Document();
|
|
122
87
|
const buffer = doc.createBuffer();
|
|
123
88
|
const position = doc.createAccessor().setType("VEC3").setArray(new Float32Array(vertices)).setBuffer(buffer);
|
|
124
89
|
const indices = doc.createAccessor().setType("SCALAR").setArray(new Uint32Array(triangles)).setBuffer(buffer);
|
|
@@ -126,7 +91,7 @@ var getGlb = (data, customCenter) => __async(void 0, null, function* () {
|
|
|
126
91
|
const mesh = doc.createMesh().addPrimitive(prim);
|
|
127
92
|
const node = doc.createNode().setMesh(mesh);
|
|
128
93
|
const scene = doc.createScene().addChild(node);
|
|
129
|
-
const glb = yield new
|
|
94
|
+
const glb = yield new WebIO().writeBinary(doc);
|
|
130
95
|
return { glb, center };
|
|
131
96
|
});
|
|
132
97
|
var get_glb_default = getGlb;
|
|
@@ -145,36 +110,53 @@ var downloadGlb = (glbData, fileName) => {
|
|
|
145
110
|
var download_glb_default = downloadGlb;
|
|
146
111
|
|
|
147
112
|
// src/private/parse-xml.ts
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var surfaceDefWorker =
|
|
113
|
+
import { createEasyWebWorker } from "easy-web-worker";
|
|
114
|
+
import convert from "xml-js";
|
|
115
|
+
var surfaceDefWorker = createEasyWebWorker(
|
|
151
116
|
({ onMessage }) => {
|
|
152
117
|
onMessage((message) => {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
118
|
+
try {
|
|
119
|
+
const { task } = message.payload;
|
|
120
|
+
if (task === "parse-surface-points") {
|
|
121
|
+
const { points } = message.payload;
|
|
122
|
+
message.resolve(
|
|
123
|
+
points.map((pt) => [pt.attr.id, pt.content.split(" ").map(Number)]).map((v) => [v[0], [v[1][1], v[1][0], v[1][2]]])
|
|
124
|
+
);
|
|
125
|
+
} else if (task === "parse-surface-faces") {
|
|
126
|
+
const { faces, idMap } = message.payload;
|
|
127
|
+
message.resolve(
|
|
128
|
+
faces.flatMap((f) => {
|
|
129
|
+
var _a;
|
|
130
|
+
if (typeof f === "string")
|
|
131
|
+
return [f.split(" ").map((id) => idMap == null ? void 0 : idMap.indexOf(id))];
|
|
132
|
+
if (((_a = f == null ? void 0 : f.attr) == null ? void 0 : _a.i) === "1")
|
|
133
|
+
return [];
|
|
134
|
+
return [f.content.split(" ").map((id) => idMap == null ? void 0 : idMap.indexOf(id))];
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
} else if (task === "find-neighboring-faces") {
|
|
138
|
+
const { faces, range: { start, end } } = message.payload;
|
|
139
|
+
const faceNeighbors = [];
|
|
140
|
+
for (let i = start; i < end; i++) {
|
|
141
|
+
const sourceFace = faces[i];
|
|
142
|
+
const neighborA = faces.findIndex((f, j) => f.findIndex((v) => v === sourceFace[0]) >= 0 && f.findIndex((v) => v === sourceFace[1]) >= 0 && j !== i);
|
|
143
|
+
const neighborB = faces.findIndex((f, j) => f.findIndex((v) => v === sourceFace[1]) >= 0 && f.findIndex((v) => v === sourceFace[2]) >= 0 && j !== i);
|
|
144
|
+
const neighborC = faces.findIndex((f, j) => f.findIndex((v) => v === sourceFace[0]) >= 0 && f.findIndex((v) => v === sourceFace[2]) >= 0 && j !== i);
|
|
145
|
+
faceNeighbors.push([neighborA, neighborB, neighborC]);
|
|
146
|
+
}
|
|
147
|
+
message.resolve(faceNeighbors);
|
|
148
|
+
}
|
|
149
|
+
} catch (e) {
|
|
150
|
+
message.reject(e);
|
|
169
151
|
}
|
|
170
152
|
});
|
|
171
153
|
},
|
|
172
|
-
{ maxWorkers:
|
|
154
|
+
{ maxWorkers: 16 }
|
|
173
155
|
);
|
|
174
156
|
var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
175
157
|
return new Promise((resolve, reject) => __async(void 0, null, function* () {
|
|
176
158
|
var _a, _b, _c, _d, _e;
|
|
177
|
-
const parsed =
|
|
159
|
+
const parsed = convert.xml2js(xmlString, {
|
|
178
160
|
compact: true,
|
|
179
161
|
attributesKey: "attr",
|
|
180
162
|
textKey: "content"
|
|
@@ -197,21 +179,22 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
197
179
|
const Faces = surface.Definition.Faces.F;
|
|
198
180
|
let ptsIdArray = [];
|
|
199
181
|
let faces = [];
|
|
182
|
+
let faceNeighbors = [];
|
|
200
183
|
if (Pnts.length > 1e4) {
|
|
201
184
|
const sliceIndexes = [...Array(20).keys()].map((i) => Math.round(Pnts.length / 20 * i));
|
|
202
185
|
ptsIdArray = (yield Promise.all(
|
|
203
186
|
sliceIndexes.map(
|
|
204
187
|
(v, i, a) => new Promise((resolve3, reject3) => __async(void 0, null, function* () {
|
|
205
188
|
const pts = yield surfaceDefWorker.send({
|
|
206
|
-
|
|
207
|
-
|
|
189
|
+
task: "parse-surface-points",
|
|
190
|
+
points: Pnts.slice(a[i], a[i + 1] || Pnts.length)
|
|
208
191
|
});
|
|
209
192
|
resolve3(pts);
|
|
210
193
|
}))
|
|
211
194
|
)
|
|
212
195
|
)).reduce((prev, curr) => [...prev, ...curr], []);
|
|
213
196
|
} else {
|
|
214
|
-
ptsIdArray = yield surfaceDefWorker.send({
|
|
197
|
+
ptsIdArray = yield surfaceDefWorker.send({ task: "parse-surface-points", points: Pnts });
|
|
215
198
|
}
|
|
216
199
|
const points = ptsIdArray.map((v) => v[1]);
|
|
217
200
|
const pointsIdMap = ptsIdArray.map((v) => v[0]);
|
|
@@ -221,8 +204,8 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
221
204
|
sliceIndexes.map(
|
|
222
205
|
(v, i, a) => new Promise((resolve3, reject3) => __async(void 0, null, function* () {
|
|
223
206
|
const fcs = yield surfaceDefWorker.send({
|
|
224
|
-
|
|
225
|
-
|
|
207
|
+
task: "parse-surface-faces",
|
|
208
|
+
faces: Faces.slice(a[i], a[i + 1] || Faces.length),
|
|
226
209
|
idMap: pointsIdMap
|
|
227
210
|
});
|
|
228
211
|
resolve3(fcs);
|
|
@@ -230,7 +213,38 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
230
213
|
)
|
|
231
214
|
)).reduce((prev, curr) => [...prev, ...curr], []);
|
|
232
215
|
} else {
|
|
233
|
-
faces = yield surfaceDefWorker.send({
|
|
216
|
+
faces = yield surfaceDefWorker.send({
|
|
217
|
+
task: "parse-surface-faces",
|
|
218
|
+
faces: Faces,
|
|
219
|
+
idMap: pointsIdMap
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (Faces.length > 1e4) {
|
|
223
|
+
const sliceIndexes = [...Array(20).keys()].map((i) => Math.round(Faces.length / 20 * i));
|
|
224
|
+
faceNeighbors = (yield Promise.all(
|
|
225
|
+
sliceIndexes.map(
|
|
226
|
+
(v, i, a) => new Promise((resolve3, reject3) => __async(void 0, null, function* () {
|
|
227
|
+
const fcs = yield surfaceDefWorker.send({
|
|
228
|
+
task: "find-neighboring-faces",
|
|
229
|
+
faces,
|
|
230
|
+
range: {
|
|
231
|
+
start: a[i],
|
|
232
|
+
end: a[i + 1] || faces.length
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
resolve3(fcs);
|
|
236
|
+
}))
|
|
237
|
+
)
|
|
238
|
+
)).reduce((prev, curr) => [...prev, ...curr], []);
|
|
239
|
+
} else {
|
|
240
|
+
faceNeighbors = yield surfaceDefWorker.send({
|
|
241
|
+
task: "find-neighboring-faces",
|
|
242
|
+
faces,
|
|
243
|
+
range: {
|
|
244
|
+
start: 0,
|
|
245
|
+
end: faces.length
|
|
246
|
+
}
|
|
247
|
+
});
|
|
234
248
|
}
|
|
235
249
|
resolve2({
|
|
236
250
|
sourceFile,
|
|
@@ -240,7 +254,8 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
240
254
|
wktString,
|
|
241
255
|
surfaceDefinition: {
|
|
242
256
|
points,
|
|
243
|
-
faces
|
|
257
|
+
faces,
|
|
258
|
+
faceNeighbors
|
|
244
259
|
}
|
|
245
260
|
});
|
|
246
261
|
}));
|
|
@@ -279,8 +294,8 @@ var toGlb = (landXmlString, center = "auto", surfaceId = -1) => __async(void 0,
|
|
|
279
294
|
var to_glb_default = toGlb;
|
|
280
295
|
|
|
281
296
|
// src/private/get-contours.ts
|
|
282
|
-
|
|
283
|
-
var contoursWorker = (
|
|
297
|
+
import { createEasyWebWorker as createEasyWebWorker2 } from "easy-web-worker";
|
|
298
|
+
var contoursWorker = createEasyWebWorker2(
|
|
284
299
|
({ onMessage }) => {
|
|
285
300
|
const contourLineOnFace = (face, z) => {
|
|
286
301
|
let vertsAtElevation = 0;
|
|
@@ -478,39 +493,21 @@ var get_contours_default = getContours;
|
|
|
478
493
|
|
|
479
494
|
// src/private/get-outline.ts
|
|
480
495
|
var getOutline = (surface) => {
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
[
|
|
487
|
-
[f[
|
|
488
|
-
|
|
489
|
-
[f[
|
|
490
|
-
].forEach(([a, b]) => {
|
|
491
|
-
if (a < b) {
|
|
492
|
-
pairs.push(`${a};${b}`);
|
|
493
|
-
} else {
|
|
494
|
-
pairs.push(`${b};${a}`);
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
pairs.forEach((pair) => {
|
|
498
|
-
i = triangleVertexIdEdgePairs.indexOf(pair);
|
|
499
|
-
if (i >= 0) {
|
|
500
|
-
triangleVertexIdEdgePairs.splice(i, 1);
|
|
501
|
-
} else {
|
|
502
|
-
triangleVertexIdEdgePairs.push(pair);
|
|
503
|
-
}
|
|
504
|
-
});
|
|
496
|
+
const vertexIndexPairEdges = [];
|
|
497
|
+
surface.surfaceDefinition.faces.forEach((f, i) => {
|
|
498
|
+
const neighbors = surface.surfaceDefinition.faceNeighbors[i];
|
|
499
|
+
if (neighbors[0] === -1)
|
|
500
|
+
vertexIndexPairEdges.push([f[0], f[1]]);
|
|
501
|
+
if (neighbors[1] === -1)
|
|
502
|
+
vertexIndexPairEdges.push([f[1], f[2]]);
|
|
503
|
+
if (neighbors[2] === -1)
|
|
504
|
+
vertexIndexPairEdges.push([f[0], f[2]]);
|
|
505
505
|
});
|
|
506
506
|
const edges = [];
|
|
507
|
-
|
|
508
|
-
const [v1, v2] = pair.
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
});
|
|
512
|
-
if (v1 && v2)
|
|
513
|
-
edges.push([v1, v2]);
|
|
507
|
+
vertexIndexPairEdges.map((pair) => {
|
|
508
|
+
const [v1, v2] = pair.map((vertexIndex) => surface.surfaceDefinition.points[vertexIndex]);
|
|
509
|
+
if (typeof v1 !== "undefined" && typeof v2 !== "undefined")
|
|
510
|
+
edges.push([v1.slice(0, 2), v2.slice(0, 2)]);
|
|
514
511
|
});
|
|
515
512
|
return constructGeojson([{ elevation: 0, polylines: linesToPolyLines(edges) }]);
|
|
516
513
|
};
|
|
@@ -543,7 +540,7 @@ var toGeojsonContours = (landXmlString, contourInterval = 2, generateOutline = t
|
|
|
543
540
|
var to_geojson_contours_default = toGeojsonContours;
|
|
544
541
|
|
|
545
542
|
// src/public/reproject-geojson.ts
|
|
546
|
-
|
|
543
|
+
import proj4 from "proj4";
|
|
547
544
|
var reprojectGeoJson = (geojson, sourceProjection, targetProjection = "WGS84", keepOriginalGeometryAsFeatureProperty = true) => {
|
|
548
545
|
const transformCoordinates = (coordinates, sourceProjection2, targetProjection2) => {
|
|
549
546
|
if (Array.isArray(coordinates[0])) {
|
|
@@ -551,7 +548,7 @@ var reprojectGeoJson = (geojson, sourceProjection, targetProjection = "WGS84", k
|
|
|
551
548
|
(subCoordinates) => transformCoordinates(subCoordinates, sourceProjection2, targetProjection2)
|
|
552
549
|
);
|
|
553
550
|
} else {
|
|
554
|
-
coordinates = (
|
|
551
|
+
coordinates = proj4(sourceProjection2, targetProjection2, coordinates);
|
|
555
552
|
}
|
|
556
553
|
return coordinates;
|
|
557
554
|
};
|
|
@@ -576,9 +573,8 @@ var reprojectGeoJson = (geojson, sourceProjection, targetProjection = "WGS84", k
|
|
|
576
573
|
return geojson;
|
|
577
574
|
};
|
|
578
575
|
var reproject_geojson_default = reprojectGeoJson;
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
});
|
|
576
|
+
export {
|
|
577
|
+
reproject_geojson_default as reprojectGeoJson,
|
|
578
|
+
to_geojson_contours_default as toGeojsonContours,
|
|
579
|
+
to_glb_default as toGlb
|
|
580
|
+
};
|
package/package.json
CHANGED
|
File without changes
|