landxml 0.6.3 → 0.6.6
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 +13 -0
- package/dist/index.js +28 -39
- package/dist/index.mjs +25 -36
- package/package.json +10 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# landxml
|
|
2
2
|
|
|
3
|
+
## 0.6.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 33f80a2: Removed unused `xml2json` dependency
|
|
8
|
+
- 33f80a2: Bumped version
|
|
9
|
+
|
|
10
|
+
## 0.6.4
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 2fcb339: Bugfix: Parsing small Landxmls via web workers
|
|
15
|
+
|
|
3
16
|
## 0.6.3
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -77,21 +77,20 @@ var __async = (__this, __arguments, generator) => {
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
// src/index.ts
|
|
80
|
-
var
|
|
81
|
-
__export(
|
|
80
|
+
var index_exports = {};
|
|
81
|
+
__export(index_exports, {
|
|
82
82
|
reprojectGeoJson: () => reproject_geojson_default,
|
|
83
83
|
toGeojsonContours: () => to_geojson_contours_default,
|
|
84
84
|
toGlb: () => to_glb_default
|
|
85
85
|
});
|
|
86
|
-
module.exports = __toCommonJS(
|
|
86
|
+
module.exports = __toCommonJS(index_exports);
|
|
87
87
|
|
|
88
88
|
// src/private/filter-by-surfaceId.ts
|
|
89
89
|
var filterBySurfaceId = (parsedSurfaces, surfaceId) => {
|
|
90
90
|
let filtered = [...parsedSurfaces];
|
|
91
91
|
if (typeof surfaceId === "string") {
|
|
92
92
|
filtered = filtered.filter((s) => s.name === surfaceId);
|
|
93
|
-
if (filtered.length === 0)
|
|
94
|
-
throw "Provided SurfaceId doesn't exist within provided LandXML";
|
|
93
|
+
if (filtered.length === 0) throw "Provided SurfaceId doesn't exist within provided LandXML";
|
|
95
94
|
}
|
|
96
95
|
if (typeof surfaceId === "number" && surfaceId > 0) {
|
|
97
96
|
if (!filtered[surfaceId])
|
|
@@ -112,7 +111,7 @@ var findXYAxisMedians = (vertices) => {
|
|
|
112
111
|
const medianY = (_b = vertices.slice().sort((a, b) => a[1] - b[1])[middleIndex]) == null ? void 0 : _b[1];
|
|
113
112
|
return [medianX, medianY];
|
|
114
113
|
};
|
|
115
|
-
var getGlb = (data, customCenter) => __async(
|
|
114
|
+
var getGlb = (data, customCenter) => __async(null, null, function* () {
|
|
116
115
|
const center = customCenter || findXYAxisMedians(data.surfaceDefinition.points);
|
|
117
116
|
const vertices = [...data.surfaceDefinition.points].map((p) => p.slice()).map(([x, y, z]) => {
|
|
118
117
|
return [x - center[0], z, -(y - center[1])];
|
|
@@ -164,8 +163,7 @@ var surfaceDefWorker = (0, import_easy_web_worker.createEasyWebWorker)(
|
|
|
164
163
|
var _a;
|
|
165
164
|
if (typeof f === "string")
|
|
166
165
|
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 [];
|
|
166
|
+
if (((_a = f == null ? void 0 : f.attr) == null ? void 0 : _a.i) === "1") return [];
|
|
169
167
|
return [f.content.split(" ").map((id) => idMap == null ? void 0 : idMap.indexOf(id))];
|
|
170
168
|
})
|
|
171
169
|
);
|
|
@@ -188,8 +186,8 @@ var surfaceDefWorker = (0, import_easy_web_worker.createEasyWebWorker)(
|
|
|
188
186
|
},
|
|
189
187
|
{ maxWorkers: 16 }
|
|
190
188
|
);
|
|
191
|
-
var parseXML = (xmlString) => __async(
|
|
192
|
-
return new Promise((resolve, reject) => __async(
|
|
189
|
+
var parseXML = (xmlString) => __async(null, null, function* () {
|
|
190
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
193
191
|
var _a, _b, _c, _d, _e;
|
|
194
192
|
const parsed = import_xml_js.default.xml2js(xmlString, {
|
|
195
193
|
compact: true,
|
|
@@ -207,8 +205,8 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
207
205
|
let timeStamp = parsed.LandXML.Application.attr.timeStamp || "";
|
|
208
206
|
let wktString = ((_e = (_d = (_c = parsed.LandXML) == null ? void 0 : _c.CoordinateSystem) == null ? void 0 : _d.attr) == null ? void 0 : _e.ogcWktCode) || void 0;
|
|
209
207
|
const surfaces = parsed.LandXML.Surfaces.Surface.map(
|
|
210
|
-
(surface) => __async(
|
|
211
|
-
return new Promise((resolve2, reject2) => __async(
|
|
208
|
+
(surface) => __async(null, null, function* () {
|
|
209
|
+
return new Promise((resolve2, reject2) => __async(null, null, function* () {
|
|
212
210
|
const { name, desc } = surface.attr;
|
|
213
211
|
const Pnts = surface.Definition.Pnts.P;
|
|
214
212
|
const Faces = surface.Definition.Faces.F;
|
|
@@ -219,7 +217,7 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
219
217
|
const sliceIndexes = [...Array(20).keys()].map((i) => Math.round(Pnts.length / 20 * i));
|
|
220
218
|
ptsIdArray = (yield Promise.all(
|
|
221
219
|
sliceIndexes.map(
|
|
222
|
-
(v, i, a) => new Promise((resolve3, reject3) => __async(
|
|
220
|
+
(v, i, a) => new Promise((resolve3, reject3) => __async(null, null, function* () {
|
|
223
221
|
const pts = yield surfaceDefWorker.send({
|
|
224
222
|
task: "parse-surface-points",
|
|
225
223
|
points: Pnts.slice(a[i], a[i + 1] || Pnts.length)
|
|
@@ -237,7 +235,7 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
237
235
|
const sliceIndexes = [...Array(20).keys()].map((i) => Math.round(Faces.length / 20 * i));
|
|
238
236
|
faces = (yield Promise.all(
|
|
239
237
|
sliceIndexes.map(
|
|
240
|
-
(v, i, a) => new Promise((resolve3, reject3) => __async(
|
|
238
|
+
(v, i, a) => new Promise((resolve3, reject3) => __async(null, null, function* () {
|
|
241
239
|
const fcs = yield surfaceDefWorker.send({
|
|
242
240
|
task: "parse-surface-faces",
|
|
243
241
|
faces: Faces.slice(a[i], a[i + 1] || Faces.length),
|
|
@@ -258,7 +256,7 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
258
256
|
const sliceIndexes = [...Array(20).keys()].map((i) => Math.round((faces.length - 1) / 20 * i));
|
|
259
257
|
faceNeighbors = (yield Promise.all(
|
|
260
258
|
sliceIndexes.map(
|
|
261
|
-
(v, i, a) => new Promise((resolve3, reject3) => __async(
|
|
259
|
+
(v, i, a) => new Promise((resolve3, reject3) => __async(null, null, function* () {
|
|
262
260
|
const fcs = yield surfaceDefWorker.send({
|
|
263
261
|
task: "find-neighboring-faces",
|
|
264
262
|
faces,
|
|
@@ -277,7 +275,7 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
277
275
|
faces,
|
|
278
276
|
range: {
|
|
279
277
|
start: 0,
|
|
280
|
-
end: faces.length
|
|
278
|
+
end: faces.length
|
|
281
279
|
}
|
|
282
280
|
});
|
|
283
281
|
}
|
|
@@ -302,12 +300,12 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
302
300
|
var parse_xml_default = parseXML;
|
|
303
301
|
|
|
304
302
|
// src/public/to-glb.ts
|
|
305
|
-
var toGlb = (landXmlString, center = "auto", surfaceId = -1) => __async(
|
|
303
|
+
var toGlb = (landXmlString, center = "auto", surfaceId = -1) => __async(null, null, function* () {
|
|
306
304
|
const requestedCenter = center == "origin" ? [0, 0] : center === "auto" ? void 0 : center;
|
|
307
305
|
let requestedParsedSurfaces = filter_by_surfaceId_default(yield parse_xml_default(landXmlString), surfaceId);
|
|
308
306
|
const glbs = yield Promise.all(
|
|
309
307
|
requestedParsedSurfaces.map(
|
|
310
|
-
(surface) => new Promise((resolve, reject) => __async(
|
|
308
|
+
(surface) => new Promise((resolve, reject) => __async(null, null, function* () {
|
|
311
309
|
try {
|
|
312
310
|
const { glb, center: center2 } = yield get_glb_default(surface, requestedCenter);
|
|
313
311
|
const _a = surface, { surfaceDefinition } = _a, rest = __objRest(_a, ["surfaceDefinition"]);
|
|
@@ -338,15 +336,13 @@ var contoursWorker = (0, import_easy_web_worker2.createEasyWebWorker)(
|
|
|
338
336
|
for (let i = 0; i < face.length; i++) {
|
|
339
337
|
let vertex1 = face[i];
|
|
340
338
|
let vertex2 = face[(i + 1) % face.length];
|
|
341
|
-
if (vertex1[2] === z)
|
|
342
|
-
vertsAtElevation++;
|
|
339
|
+
if (vertex1[2] === z) vertsAtElevation++;
|
|
343
340
|
if ((vertex1[2] <= z && vertex2[2] >= z || vertex1[2] >= z && vertex2[2] <= z) && !Number.isNaN((z - vertex1[2]) / (vertex2[2] - vertex1[2]))) {
|
|
344
341
|
let t = (z - vertex1[2]) / (vertex2[2] - vertex1[2]);
|
|
345
342
|
line.push([vertex1[0] + t * (vertex2[0] - vertex1[0]), vertex1[1] + t * (vertex2[1] - vertex1[1])]);
|
|
346
343
|
}
|
|
347
344
|
}
|
|
348
|
-
if (vertsAtElevation >= 2 && face.map((f) => f[2]).reduce((a, b) => a + b) > z * face.length)
|
|
349
|
-
return void 0;
|
|
345
|
+
if (vertsAtElevation >= 2 && face.map((f) => f[2]).reduce((a, b) => a + b) > z * face.length) return void 0;
|
|
350
346
|
if (line.length === 2 && line[0][0] === line[1][0] && line[0][1] === line[1][1])
|
|
351
347
|
return void 0;
|
|
352
348
|
if (line.length > 2) {
|
|
@@ -368,8 +364,7 @@ var contoursWorker = (0, import_easy_web_worker2.createEasyWebWorker)(
|
|
|
368
364
|
segmentsMapIndexes[end] = segmentsMapIndexes[end] ? [...segmentsMapIndexes[end] || [], i] : [i];
|
|
369
365
|
});
|
|
370
366
|
for (let i = 0; i < lineSegmentStrings.length; i++) {
|
|
371
|
-
if (parsedSegmentIndexes.includes(i))
|
|
372
|
-
continue;
|
|
367
|
+
if (parsedSegmentIndexes.includes(i)) continue;
|
|
373
368
|
parsedSegmentIndexes.push(i);
|
|
374
369
|
let [start, end] = lineSegmentStrings[i];
|
|
375
370
|
let polyline = [start, end];
|
|
@@ -411,8 +406,7 @@ var contoursWorker = (0, import_easy_web_worker2.createEasyWebWorker)(
|
|
|
411
406
|
const { triangles, elevation } = message.payload;
|
|
412
407
|
const linesAtElevationE = triangles.reduce((prev, curr) => {
|
|
413
408
|
const line = contourLineOnFace(curr, elevation);
|
|
414
|
-
if (line)
|
|
415
|
-
prev.push(line);
|
|
409
|
+
if (line) prev.push(line);
|
|
416
410
|
return prev;
|
|
417
411
|
}, []);
|
|
418
412
|
message.resolve({
|
|
@@ -437,8 +431,7 @@ var linesToPolyLines = (lineSegments) => {
|
|
|
437
431
|
segmentsMapIndexes[end] = segmentsMapIndexes[end] ? [...segmentsMapIndexes[end] || [], i] : [i];
|
|
438
432
|
});
|
|
439
433
|
for (let i = 0; i < lineSegmentStrings.length; i++) {
|
|
440
|
-
if (parsedSegmentIndexes.includes(i))
|
|
441
|
-
continue;
|
|
434
|
+
if (parsedSegmentIndexes.includes(i)) continue;
|
|
442
435
|
parsedSegmentIndexes.push(i);
|
|
443
436
|
let [start, end] = lineSegmentStrings[i];
|
|
444
437
|
let polyline = [start, end];
|
|
@@ -512,7 +505,7 @@ var constructGeojson = (elevationData) => {
|
|
|
512
505
|
features
|
|
513
506
|
};
|
|
514
507
|
};
|
|
515
|
-
var getContours = (data, interval = 2) => __async(
|
|
508
|
+
var getContours = (data, interval = 2) => __async(null, null, function* () {
|
|
516
509
|
const triangles = data.surfaceDefinition.faces.map(
|
|
517
510
|
(face) => face.map((vert) => data.surfaceDefinition.points[vert])
|
|
518
511
|
);
|
|
@@ -531,12 +524,9 @@ var getOutline = (surface) => {
|
|
|
531
524
|
const vertexIndexPairEdges = [];
|
|
532
525
|
surface.surfaceDefinition.faces.forEach((f, i) => {
|
|
533
526
|
const neighbors = surface.surfaceDefinition.faceNeighbors[i];
|
|
534
|
-
if (neighbors[0] === -1)
|
|
535
|
-
|
|
536
|
-
if (neighbors[
|
|
537
|
-
vertexIndexPairEdges.push([f[1], f[2]]);
|
|
538
|
-
if (neighbors[2] === -1)
|
|
539
|
-
vertexIndexPairEdges.push([f[0], f[2]]);
|
|
527
|
+
if (neighbors[0] === -1) vertexIndexPairEdges.push([f[0], f[1]]);
|
|
528
|
+
if (neighbors[1] === -1) vertexIndexPairEdges.push([f[1], f[2]]);
|
|
529
|
+
if (neighbors[2] === -1) vertexIndexPairEdges.push([f[0], f[2]]);
|
|
540
530
|
});
|
|
541
531
|
const edges = [];
|
|
542
532
|
vertexIndexPairEdges.map((pair) => {
|
|
@@ -549,11 +539,11 @@ var getOutline = (surface) => {
|
|
|
549
539
|
var get_outline_default = getOutline;
|
|
550
540
|
|
|
551
541
|
// src/public/to-geojson-contours.ts
|
|
552
|
-
var toGeojsonContours = (landXmlString, contourInterval = 2, generateOutline = true, surfaceId = -1) => __async(
|
|
542
|
+
var toGeojsonContours = (landXmlString, contourInterval = 2, generateOutline = true, surfaceId = -1) => __async(null, null, function* () {
|
|
553
543
|
let requestedParsedSurfaces = filter_by_surfaceId_default(yield parse_xml_default(landXmlString), surfaceId);
|
|
554
544
|
const contours = yield Promise.all(
|
|
555
545
|
requestedParsedSurfaces.map(
|
|
556
|
-
(surface) => new Promise((resolve, reject) => __async(
|
|
546
|
+
(surface) => new Promise((resolve, reject) => __async(null, null, function* () {
|
|
557
547
|
try {
|
|
558
548
|
const geojson = yield get_contours_default(surface, contourInterval);
|
|
559
549
|
if (generateOutline) {
|
|
@@ -591,8 +581,7 @@ var reprojectGeoJson = (geojson, sourceProjection, targetProjection = "WGS84", k
|
|
|
591
581
|
throw new Error("Invalid GeoJSON or source projection.");
|
|
592
582
|
}
|
|
593
583
|
geojson.features.forEach((feature) => {
|
|
594
|
-
if (keepOriginalGeometryAsFeatureProperty)
|
|
595
|
-
feature.properties = feature.properties || {};
|
|
584
|
+
if (keepOriginalGeometryAsFeatureProperty) feature.properties = feature.properties || {};
|
|
596
585
|
if (feature.geometry) {
|
|
597
586
|
if (keepOriginalGeometryAsFeatureProperty && feature.properties)
|
|
598
587
|
feature.properties._rawGeometry = __spreadValues({}, feature.geometry);
|
package/dist/index.mjs
CHANGED
|
@@ -55,8 +55,7 @@ var filterBySurfaceId = (parsedSurfaces, surfaceId) => {
|
|
|
55
55
|
let filtered = [...parsedSurfaces];
|
|
56
56
|
if (typeof surfaceId === "string") {
|
|
57
57
|
filtered = filtered.filter((s) => s.name === surfaceId);
|
|
58
|
-
if (filtered.length === 0)
|
|
59
|
-
throw "Provided SurfaceId doesn't exist within provided LandXML";
|
|
58
|
+
if (filtered.length === 0) throw "Provided SurfaceId doesn't exist within provided LandXML";
|
|
60
59
|
}
|
|
61
60
|
if (typeof surfaceId === "number" && surfaceId > 0) {
|
|
62
61
|
if (!filtered[surfaceId])
|
|
@@ -77,7 +76,7 @@ var findXYAxisMedians = (vertices) => {
|
|
|
77
76
|
const medianY = (_b = vertices.slice().sort((a, b) => a[1] - b[1])[middleIndex]) == null ? void 0 : _b[1];
|
|
78
77
|
return [medianX, medianY];
|
|
79
78
|
};
|
|
80
|
-
var getGlb = (data, customCenter) => __async(
|
|
79
|
+
var getGlb = (data, customCenter) => __async(null, null, function* () {
|
|
81
80
|
const center = customCenter || findXYAxisMedians(data.surfaceDefinition.points);
|
|
82
81
|
const vertices = [...data.surfaceDefinition.points].map((p) => p.slice()).map(([x, y, z]) => {
|
|
83
82
|
return [x - center[0], z, -(y - center[1])];
|
|
@@ -129,8 +128,7 @@ var surfaceDefWorker = createEasyWebWorker(
|
|
|
129
128
|
var _a;
|
|
130
129
|
if (typeof f === "string")
|
|
131
130
|
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 [];
|
|
131
|
+
if (((_a = f == null ? void 0 : f.attr) == null ? void 0 : _a.i) === "1") return [];
|
|
134
132
|
return [f.content.split(" ").map((id) => idMap == null ? void 0 : idMap.indexOf(id))];
|
|
135
133
|
})
|
|
136
134
|
);
|
|
@@ -153,8 +151,8 @@ var surfaceDefWorker = createEasyWebWorker(
|
|
|
153
151
|
},
|
|
154
152
|
{ maxWorkers: 16 }
|
|
155
153
|
);
|
|
156
|
-
var parseXML = (xmlString) => __async(
|
|
157
|
-
return new Promise((resolve, reject) => __async(
|
|
154
|
+
var parseXML = (xmlString) => __async(null, null, function* () {
|
|
155
|
+
return new Promise((resolve, reject) => __async(null, null, function* () {
|
|
158
156
|
var _a, _b, _c, _d, _e;
|
|
159
157
|
const parsed = convert.xml2js(xmlString, {
|
|
160
158
|
compact: true,
|
|
@@ -172,8 +170,8 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
172
170
|
let timeStamp = parsed.LandXML.Application.attr.timeStamp || "";
|
|
173
171
|
let wktString = ((_e = (_d = (_c = parsed.LandXML) == null ? void 0 : _c.CoordinateSystem) == null ? void 0 : _d.attr) == null ? void 0 : _e.ogcWktCode) || void 0;
|
|
174
172
|
const surfaces = parsed.LandXML.Surfaces.Surface.map(
|
|
175
|
-
(surface) => __async(
|
|
176
|
-
return new Promise((resolve2, reject2) => __async(
|
|
173
|
+
(surface) => __async(null, null, function* () {
|
|
174
|
+
return new Promise((resolve2, reject2) => __async(null, null, function* () {
|
|
177
175
|
const { name, desc } = surface.attr;
|
|
178
176
|
const Pnts = surface.Definition.Pnts.P;
|
|
179
177
|
const Faces = surface.Definition.Faces.F;
|
|
@@ -184,7 +182,7 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
184
182
|
const sliceIndexes = [...Array(20).keys()].map((i) => Math.round(Pnts.length / 20 * i));
|
|
185
183
|
ptsIdArray = (yield Promise.all(
|
|
186
184
|
sliceIndexes.map(
|
|
187
|
-
(v, i, a) => new Promise((resolve3, reject3) => __async(
|
|
185
|
+
(v, i, a) => new Promise((resolve3, reject3) => __async(null, null, function* () {
|
|
188
186
|
const pts = yield surfaceDefWorker.send({
|
|
189
187
|
task: "parse-surface-points",
|
|
190
188
|
points: Pnts.slice(a[i], a[i + 1] || Pnts.length)
|
|
@@ -202,7 +200,7 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
202
200
|
const sliceIndexes = [...Array(20).keys()].map((i) => Math.round(Faces.length / 20 * i));
|
|
203
201
|
faces = (yield Promise.all(
|
|
204
202
|
sliceIndexes.map(
|
|
205
|
-
(v, i, a) => new Promise((resolve3, reject3) => __async(
|
|
203
|
+
(v, i, a) => new Promise((resolve3, reject3) => __async(null, null, function* () {
|
|
206
204
|
const fcs = yield surfaceDefWorker.send({
|
|
207
205
|
task: "parse-surface-faces",
|
|
208
206
|
faces: Faces.slice(a[i], a[i + 1] || Faces.length),
|
|
@@ -223,7 +221,7 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
223
221
|
const sliceIndexes = [...Array(20).keys()].map((i) => Math.round((faces.length - 1) / 20 * i));
|
|
224
222
|
faceNeighbors = (yield Promise.all(
|
|
225
223
|
sliceIndexes.map(
|
|
226
|
-
(v, i, a) => new Promise((resolve3, reject3) => __async(
|
|
224
|
+
(v, i, a) => new Promise((resolve3, reject3) => __async(null, null, function* () {
|
|
227
225
|
const fcs = yield surfaceDefWorker.send({
|
|
228
226
|
task: "find-neighboring-faces",
|
|
229
227
|
faces,
|
|
@@ -242,7 +240,7 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
242
240
|
faces,
|
|
243
241
|
range: {
|
|
244
242
|
start: 0,
|
|
245
|
-
end: faces.length
|
|
243
|
+
end: faces.length
|
|
246
244
|
}
|
|
247
245
|
});
|
|
248
246
|
}
|
|
@@ -267,12 +265,12 @@ var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
|
267
265
|
var parse_xml_default = parseXML;
|
|
268
266
|
|
|
269
267
|
// src/public/to-glb.ts
|
|
270
|
-
var toGlb = (landXmlString, center = "auto", surfaceId = -1) => __async(
|
|
268
|
+
var toGlb = (landXmlString, center = "auto", surfaceId = -1) => __async(null, null, function* () {
|
|
271
269
|
const requestedCenter = center == "origin" ? [0, 0] : center === "auto" ? void 0 : center;
|
|
272
270
|
let requestedParsedSurfaces = filter_by_surfaceId_default(yield parse_xml_default(landXmlString), surfaceId);
|
|
273
271
|
const glbs = yield Promise.all(
|
|
274
272
|
requestedParsedSurfaces.map(
|
|
275
|
-
(surface) => new Promise((resolve, reject) => __async(
|
|
273
|
+
(surface) => new Promise((resolve, reject) => __async(null, null, function* () {
|
|
276
274
|
try {
|
|
277
275
|
const { glb, center: center2 } = yield get_glb_default(surface, requestedCenter);
|
|
278
276
|
const _a = surface, { surfaceDefinition } = _a, rest = __objRest(_a, ["surfaceDefinition"]);
|
|
@@ -303,15 +301,13 @@ var contoursWorker = createEasyWebWorker2(
|
|
|
303
301
|
for (let i = 0; i < face.length; i++) {
|
|
304
302
|
let vertex1 = face[i];
|
|
305
303
|
let vertex2 = face[(i + 1) % face.length];
|
|
306
|
-
if (vertex1[2] === z)
|
|
307
|
-
vertsAtElevation++;
|
|
304
|
+
if (vertex1[2] === z) vertsAtElevation++;
|
|
308
305
|
if ((vertex1[2] <= z && vertex2[2] >= z || vertex1[2] >= z && vertex2[2] <= z) && !Number.isNaN((z - vertex1[2]) / (vertex2[2] - vertex1[2]))) {
|
|
309
306
|
let t = (z - vertex1[2]) / (vertex2[2] - vertex1[2]);
|
|
310
307
|
line.push([vertex1[0] + t * (vertex2[0] - vertex1[0]), vertex1[1] + t * (vertex2[1] - vertex1[1])]);
|
|
311
308
|
}
|
|
312
309
|
}
|
|
313
|
-
if (vertsAtElevation >= 2 && face.map((f) => f[2]).reduce((a, b) => a + b) > z * face.length)
|
|
314
|
-
return void 0;
|
|
310
|
+
if (vertsAtElevation >= 2 && face.map((f) => f[2]).reduce((a, b) => a + b) > z * face.length) return void 0;
|
|
315
311
|
if (line.length === 2 && line[0][0] === line[1][0] && line[0][1] === line[1][1])
|
|
316
312
|
return void 0;
|
|
317
313
|
if (line.length > 2) {
|
|
@@ -333,8 +329,7 @@ var contoursWorker = createEasyWebWorker2(
|
|
|
333
329
|
segmentsMapIndexes[end] = segmentsMapIndexes[end] ? [...segmentsMapIndexes[end] || [], i] : [i];
|
|
334
330
|
});
|
|
335
331
|
for (let i = 0; i < lineSegmentStrings.length; i++) {
|
|
336
|
-
if (parsedSegmentIndexes.includes(i))
|
|
337
|
-
continue;
|
|
332
|
+
if (parsedSegmentIndexes.includes(i)) continue;
|
|
338
333
|
parsedSegmentIndexes.push(i);
|
|
339
334
|
let [start, end] = lineSegmentStrings[i];
|
|
340
335
|
let polyline = [start, end];
|
|
@@ -376,8 +371,7 @@ var contoursWorker = createEasyWebWorker2(
|
|
|
376
371
|
const { triangles, elevation } = message.payload;
|
|
377
372
|
const linesAtElevationE = triangles.reduce((prev, curr) => {
|
|
378
373
|
const line = contourLineOnFace(curr, elevation);
|
|
379
|
-
if (line)
|
|
380
|
-
prev.push(line);
|
|
374
|
+
if (line) prev.push(line);
|
|
381
375
|
return prev;
|
|
382
376
|
}, []);
|
|
383
377
|
message.resolve({
|
|
@@ -402,8 +396,7 @@ var linesToPolyLines = (lineSegments) => {
|
|
|
402
396
|
segmentsMapIndexes[end] = segmentsMapIndexes[end] ? [...segmentsMapIndexes[end] || [], i] : [i];
|
|
403
397
|
});
|
|
404
398
|
for (let i = 0; i < lineSegmentStrings.length; i++) {
|
|
405
|
-
if (parsedSegmentIndexes.includes(i))
|
|
406
|
-
continue;
|
|
399
|
+
if (parsedSegmentIndexes.includes(i)) continue;
|
|
407
400
|
parsedSegmentIndexes.push(i);
|
|
408
401
|
let [start, end] = lineSegmentStrings[i];
|
|
409
402
|
let polyline = [start, end];
|
|
@@ -477,7 +470,7 @@ var constructGeojson = (elevationData) => {
|
|
|
477
470
|
features
|
|
478
471
|
};
|
|
479
472
|
};
|
|
480
|
-
var getContours = (data, interval = 2) => __async(
|
|
473
|
+
var getContours = (data, interval = 2) => __async(null, null, function* () {
|
|
481
474
|
const triangles = data.surfaceDefinition.faces.map(
|
|
482
475
|
(face) => face.map((vert) => data.surfaceDefinition.points[vert])
|
|
483
476
|
);
|
|
@@ -496,12 +489,9 @@ var getOutline = (surface) => {
|
|
|
496
489
|
const vertexIndexPairEdges = [];
|
|
497
490
|
surface.surfaceDefinition.faces.forEach((f, i) => {
|
|
498
491
|
const neighbors = surface.surfaceDefinition.faceNeighbors[i];
|
|
499
|
-
if (neighbors[0] === -1)
|
|
500
|
-
|
|
501
|
-
if (neighbors[
|
|
502
|
-
vertexIndexPairEdges.push([f[1], f[2]]);
|
|
503
|
-
if (neighbors[2] === -1)
|
|
504
|
-
vertexIndexPairEdges.push([f[0], f[2]]);
|
|
492
|
+
if (neighbors[0] === -1) vertexIndexPairEdges.push([f[0], f[1]]);
|
|
493
|
+
if (neighbors[1] === -1) vertexIndexPairEdges.push([f[1], f[2]]);
|
|
494
|
+
if (neighbors[2] === -1) vertexIndexPairEdges.push([f[0], f[2]]);
|
|
505
495
|
});
|
|
506
496
|
const edges = [];
|
|
507
497
|
vertexIndexPairEdges.map((pair) => {
|
|
@@ -514,11 +504,11 @@ var getOutline = (surface) => {
|
|
|
514
504
|
var get_outline_default = getOutline;
|
|
515
505
|
|
|
516
506
|
// src/public/to-geojson-contours.ts
|
|
517
|
-
var toGeojsonContours = (landXmlString, contourInterval = 2, generateOutline = true, surfaceId = -1) => __async(
|
|
507
|
+
var toGeojsonContours = (landXmlString, contourInterval = 2, generateOutline = true, surfaceId = -1) => __async(null, null, function* () {
|
|
518
508
|
let requestedParsedSurfaces = filter_by_surfaceId_default(yield parse_xml_default(landXmlString), surfaceId);
|
|
519
509
|
const contours = yield Promise.all(
|
|
520
510
|
requestedParsedSurfaces.map(
|
|
521
|
-
(surface) => new Promise((resolve, reject) => __async(
|
|
511
|
+
(surface) => new Promise((resolve, reject) => __async(null, null, function* () {
|
|
522
512
|
try {
|
|
523
513
|
const geojson = yield get_contours_default(surface, contourInterval);
|
|
524
514
|
if (generateOutline) {
|
|
@@ -556,8 +546,7 @@ var reprojectGeoJson = (geojson, sourceProjection, targetProjection = "WGS84", k
|
|
|
556
546
|
throw new Error("Invalid GeoJSON or source projection.");
|
|
557
547
|
}
|
|
558
548
|
geojson.features.forEach((feature) => {
|
|
559
|
-
if (keepOriginalGeometryAsFeatureProperty)
|
|
560
|
-
feature.properties = feature.properties || {};
|
|
549
|
+
if (keepOriginalGeometryAsFeatureProperty) feature.properties = feature.properties || {};
|
|
561
550
|
if (feature.geometry) {
|
|
562
551
|
if (keepOriginalGeometryAsFeatureProperty && feature.properties)
|
|
563
552
|
feature.properties._rawGeometry = __spreadValues({}, feature.geometry);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "landxml",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "Parse LandXML surfaces on the modern web.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"homepage": "https://github.com/abrman/landxml#readme",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/abrman/landxml"
|
|
12
|
+
"url": "git+https://github.com/abrman/landxml.git"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"dev": "vitest --config ./vitest.config.ts --slow-test-threshold=0",
|
|
@@ -27,23 +27,22 @@
|
|
|
27
27
|
"author": "Matthew Abrman",
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@changesets/cli": "^2.
|
|
31
|
-
"@types/geojson": "^7946.0.
|
|
32
|
-
"@types/proj4": "^2.5.
|
|
30
|
+
"@changesets/cli": "^2.29.6",
|
|
31
|
+
"@types/geojson": "^7946.0.16",
|
|
32
|
+
"@types/proj4": "^2.5.6",
|
|
33
33
|
"@types/sax": "^1.2.7",
|
|
34
34
|
"@types/xml2json": "^0.11.6",
|
|
35
35
|
"jsdom": "^24.0.0",
|
|
36
36
|
"tsup": "^8.0.0",
|
|
37
37
|
"typescript": "^5.2.2",
|
|
38
|
-
"vitest": "^
|
|
38
|
+
"vitest": "^3.2.4"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@gltf-transform/core": "^3.9.0",
|
|
42
|
-
"@vitest/web-worker": "^
|
|
42
|
+
"@vitest/web-worker": "^3.2.4",
|
|
43
43
|
"easy-web-worker": "^6.2.0",
|
|
44
44
|
"proj4": "^2.9.2",
|
|
45
|
-
"sax": "^1.
|
|
46
|
-
"xml-js": "^1.6.11"
|
|
47
|
-
"xml2json": "^0.12.0"
|
|
45
|
+
"sax": "^1.4.1",
|
|
46
|
+
"xml-js": "^1.6.11"
|
|
48
47
|
}
|
|
49
|
-
}
|
|
48
|
+
}
|