@loaders.gl/kml 3.1.0-beta.5 → 3.1.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/dist/bundle.js CHANGED
@@ -1,853 +1,5 @@
1
- (() => {
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
9
- var __esm = (fn, res) => function __init() {
10
- return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
11
- };
12
- var __commonJS = (cb, mod) => function __require() {
13
- return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
- };
15
- var __export = (target, all) => {
16
- __markAsModule(target);
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __reExport = (target, module, desc) => {
21
- if (module && typeof module === "object" || typeof module === "function") {
22
- for (let key of __getOwnPropNames(module))
23
- if (!__hasOwnProp.call(target, key) && key !== "default")
24
- __defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
25
- }
26
- return target;
27
- };
28
- var __toModule = (module) => {
29
- return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
30
- };
31
-
32
- // ../gis/src/lib/geojson-to-binary.ts
33
- function geojsonToBinary(features, options = {}) {
34
- const firstPassData = firstPass(features);
35
- return secondPass(features, firstPassData, {
36
- coordLength: options.coordLength || firstPassData.coordLength,
37
- numericPropKeys: options.numericPropKeys || firstPassData.numericPropKeys,
38
- PositionDataType: options.PositionDataType || Float32Array
39
- });
40
- }
41
- function firstPass(features) {
42
- let pointPositionsCount = 0;
43
- let pointFeaturesCount = 0;
44
- let linePositionsCount = 0;
45
- let linePathsCount = 0;
46
- let lineFeaturesCount = 0;
47
- let polygonPositionsCount = 0;
48
- let polygonObjectsCount = 0;
49
- let polygonRingsCount = 0;
50
- let polygonFeaturesCount = 0;
51
- const coordLengths = new Set();
52
- const numericPropKeys = {};
53
- for (const feature of features) {
54
- const geometry = feature.geometry;
55
- switch (geometry.type) {
56
- case "Point":
57
- pointFeaturesCount++;
58
- pointPositionsCount++;
59
- coordLengths.add(geometry.coordinates.length);
60
- break;
61
- case "MultiPoint":
62
- pointFeaturesCount++;
63
- pointPositionsCount += geometry.coordinates.length;
64
- for (const point of geometry.coordinates) {
65
- coordLengths.add(point.length);
66
- }
67
- break;
68
- case "LineString":
69
- lineFeaturesCount++;
70
- linePositionsCount += geometry.coordinates.length;
71
- linePathsCount++;
72
- for (const coord of geometry.coordinates) {
73
- coordLengths.add(coord.length);
74
- }
75
- break;
76
- case "MultiLineString":
77
- lineFeaturesCount++;
78
- for (const line of geometry.coordinates) {
79
- linePositionsCount += line.length;
80
- linePathsCount++;
81
- for (const coord of line) {
82
- coordLengths.add(coord.length);
83
- }
84
- }
85
- break;
86
- case "Polygon":
87
- polygonFeaturesCount++;
88
- polygonObjectsCount++;
89
- polygonRingsCount += geometry.coordinates.length;
90
- polygonPositionsCount += flatten(geometry.coordinates).length;
91
- for (const coord of flatten(geometry.coordinates)) {
92
- coordLengths.add(coord.length);
93
- }
94
- break;
95
- case "MultiPolygon":
96
- polygonFeaturesCount++;
97
- for (const polygon of geometry.coordinates) {
98
- polygonObjectsCount++;
99
- polygonRingsCount += polygon.length;
100
- polygonPositionsCount += flatten(polygon).length;
101
- for (const coord of flatten(polygon)) {
102
- coordLengths.add(coord.length);
103
- }
104
- }
105
- break;
106
- default:
107
- throw new Error(`Unsupported geometry type: ${geometry.type}`);
108
- }
109
- if (feature.properties) {
110
- for (const key in feature.properties) {
111
- const val = feature.properties[key];
112
- numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === void 0 ? isNumeric(val) : numericPropKeys[key];
113
- }
114
- }
115
- }
116
- return {
117
- coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
118
- pointPositionsCount,
119
- pointFeaturesCount,
120
- linePositionsCount,
121
- linePathsCount,
122
- lineFeaturesCount,
123
- polygonPositionsCount,
124
- polygonObjectsCount,
125
- polygonRingsCount,
126
- polygonFeaturesCount,
127
- numericPropKeys: Object.keys(numericPropKeys).filter((k) => numericPropKeys[k])
128
- };
129
- }
130
- function secondPass(features, firstPassData, options) {
131
- const {
132
- pointPositionsCount,
133
- pointFeaturesCount,
134
- linePositionsCount,
135
- linePathsCount,
136
- lineFeaturesCount,
137
- polygonPositionsCount,
138
- polygonObjectsCount,
139
- polygonRingsCount,
140
- polygonFeaturesCount
141
- } = firstPassData;
142
- const { coordLength, numericPropKeys, PositionDataType = Float32Array } = options;
143
- const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
144
- const points = {
145
- positions: new PositionDataType(pointPositionsCount * coordLength),
146
- globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
147
- featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
148
- numericProps: {},
149
- properties: Array(),
150
- fields: Array()
151
- };
152
- const lines = {
153
- positions: new PositionDataType(linePositionsCount * coordLength),
154
- pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
155
- globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
156
- featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
157
- numericProps: {},
158
- properties: Array(),
159
- fields: Array()
160
- };
161
- const polygons = {
162
- positions: new PositionDataType(polygonPositionsCount * coordLength),
163
- polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
164
- primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
165
- globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
166
- featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
167
- numericProps: {},
168
- properties: Array(),
169
- fields: Array()
170
- };
171
- for (const object of [points, lines, polygons]) {
172
- for (const propName of numericPropKeys || []) {
173
- object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
174
- }
175
- }
176
- lines.pathIndices[linePathsCount] = linePositionsCount;
177
- polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
178
- polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
179
- const indexMap = {
180
- pointPosition: 0,
181
- pointFeature: 0,
182
- linePosition: 0,
183
- linePath: 0,
184
- lineFeature: 0,
185
- polygonPosition: 0,
186
- polygonObject: 0,
187
- polygonRing: 0,
188
- polygonFeature: 0,
189
- feature: 0
190
- };
191
- for (const feature of features) {
192
- const geometry = feature.geometry;
193
- const properties = feature.properties || {};
194
- switch (geometry.type) {
195
- case "Point":
196
- handlePoint(geometry.coordinates, points, indexMap, coordLength, properties);
197
- points.properties.push(keepStringProperties(properties, numericPropKeys));
198
- indexMap.pointFeature++;
199
- break;
200
- case "MultiPoint":
201
- handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);
202
- points.properties.push(keepStringProperties(properties, numericPropKeys));
203
- indexMap.pointFeature++;
204
- break;
205
- case "LineString":
206
- handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
207
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
208
- indexMap.lineFeature++;
209
- break;
210
- case "MultiLineString":
211
- handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
212
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
213
- indexMap.lineFeature++;
214
- break;
215
- case "Polygon":
216
- handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
217
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
218
- indexMap.polygonFeature++;
219
- break;
220
- case "MultiPolygon":
221
- handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
222
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
223
- indexMap.polygonFeature++;
224
- break;
225
- default:
226
- throw new Error("Invalid geometry type");
227
- }
228
- indexMap.feature++;
229
- }
230
- return makeAccessorObjects(points, lines, polygons, coordLength);
231
- }
232
- function handlePoint(coords, points, indexMap, coordLength, properties) {
233
- points.positions.set(coords, indexMap.pointPosition * coordLength);
234
- points.globalFeatureIds[indexMap.pointPosition] = indexMap.feature;
235
- points.featureIds[indexMap.pointPosition] = indexMap.pointFeature;
236
- fillNumericProperties(points, properties, indexMap.pointPosition, 1);
237
- indexMap.pointPosition++;
238
- }
239
- function handleMultiPoint(coords, points, indexMap, coordLength, properties) {
240
- for (const point of coords) {
241
- handlePoint(point, points, indexMap, coordLength, properties);
242
- }
243
- }
244
- function handleLineString(coords, lines, indexMap, coordLength, properties) {
245
- lines.pathIndices[indexMap.linePath] = indexMap.linePosition;
246
- indexMap.linePath++;
247
- fillCoords(lines.positions, coords, indexMap.linePosition, coordLength);
248
- const nPositions = coords.length;
249
- fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
250
- lines.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.linePosition);
251
- lines.featureIds.set(new Uint32Array(nPositions).fill(indexMap.lineFeature), indexMap.linePosition);
252
- indexMap.linePosition += nPositions;
253
- }
254
- function handleMultiLineString(coords, lines, indexMap, coordLength, properties) {
255
- for (const line of coords) {
256
- handleLineString(line, lines, indexMap, coordLength, properties);
257
- }
258
- }
259
- function handlePolygon(coords, polygons, indexMap, coordLength, properties) {
260
- polygons.polygonIndices[indexMap.polygonObject] = indexMap.polygonPosition;
261
- indexMap.polygonObject++;
262
- for (const ring of coords) {
263
- polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition;
264
- indexMap.polygonRing++;
265
- fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength);
266
- const nPositions = ring.length;
267
- fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
268
- polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition);
269
- polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition);
270
- indexMap.polygonPosition += nPositions;
271
- }
272
- }
273
- function handleMultiPolygon(coords, polygons, indexMap, coordLength, properties) {
274
- for (const polygon of coords) {
275
- handlePolygon(polygon, polygons, indexMap, coordLength, properties);
276
- }
277
- }
278
- function makeAccessorObjects(points, lines, polygons, coordLength) {
279
- const returnObj = {
280
- points: {
281
- ...points,
282
- positions: { value: points.positions, size: coordLength },
283
- globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
284
- featureIds: { value: points.featureIds, size: 1 },
285
- type: "Point"
286
- },
287
- lines: {
288
- ...lines,
289
- pathIndices: { value: lines.pathIndices, size: 1 },
290
- positions: { value: lines.positions, size: coordLength },
291
- globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
292
- featureIds: { value: lines.featureIds, size: 1 },
293
- type: "LineString"
294
- },
295
- polygons: {
296
- ...polygons,
297
- polygonIndices: { value: polygons.polygonIndices, size: 1 },
298
- primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
299
- positions: { value: polygons.positions, size: coordLength },
300
- globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
301
- featureIds: { value: polygons.featureIds, size: 1 },
302
- type: "Polygon"
303
- }
304
- };
305
- for (const geomType in returnObj) {
306
- for (const numericProp in returnObj[geomType].numericProps) {
307
- returnObj[geomType].numericProps[numericProp] = {
308
- value: returnObj[geomType].numericProps[numericProp],
309
- size: 1
310
- };
311
- }
312
- }
313
- return returnObj;
314
- }
315
- function fillNumericProperties(object, properties, index, length) {
316
- for (const numericPropName in object.numericProps) {
317
- if (numericPropName in properties) {
318
- object.numericProps[numericPropName].set(new Array(length).fill(properties[numericPropName]), index);
319
- }
320
- }
321
- }
322
- function keepStringProperties(properties, numericKeys) {
323
- const props = {};
324
- for (const key in properties) {
325
- if (!numericKeys.includes(key)) {
326
- props[key] = properties[key];
327
- }
328
- }
329
- return props;
330
- }
331
- function fillCoords(array, coords, startVertex, coordLength) {
332
- let index = startVertex * coordLength;
333
- for (const coord of coords) {
334
- array.set(coord, index);
335
- index += coordLength;
336
- }
337
- }
338
- function flatten(arrays) {
339
- return [].concat(...arrays);
340
- }
341
- function isNumeric(x) {
342
- return Number.isFinite(x);
343
- }
344
- var init_geojson_to_binary = __esm({
345
- "../gis/src/lib/geojson-to-binary.ts"() {
346
- }
347
- });
348
-
349
- // ../gis/src/index.ts
350
- var init_src = __esm({
351
- "../gis/src/index.ts"() {
352
- init_geojson_to_binary();
353
- }
354
- });
355
-
356
- // ../../node_modules/@tmcw/togeojson/dist/togeojson.umd.js
357
- var require_togeojson_umd = __commonJS({
358
- "../../node_modules/@tmcw/togeojson/dist/togeojson.umd.js"(exports, module) {
359
- !function(e, t) {
360
- typeof exports == "object" && typeof module != "undefined" ? t(exports) : typeof define == "function" && define.amd ? define(["exports"], t) : t((e = typeof globalThis != "undefined" ? globalThis : e || self).toGeoJSON = {});
361
- }(exports, function(e) {
362
- "use strict";
363
- function t(e2) {
364
- return e2 && e2.normalize && e2.normalize(), e2 && e2.textContent || "";
365
- }
366
- function n(e2, t2) {
367
- const n2 = e2.getElementsByTagName(t2);
368
- return n2.length ? n2[0] : null;
369
- }
370
- function o(e2) {
371
- const o2 = {};
372
- if (e2) {
373
- const s2 = n(e2, "line");
374
- if (s2) {
375
- const e3 = t(n(s2, "color")), r2 = parseFloat(t(n(s2, "opacity"))), i2 = parseFloat(t(n(s2, "width")));
376
- e3 && (o2.stroke = e3), isNaN(r2) || (o2["stroke-opacity"] = r2), isNaN(i2) || (o2["stroke-width"] = 96 * i2 / 25.4);
377
- }
378
- }
379
- return o2;
380
- }
381
- function s(e2, o2) {
382
- const s2 = {};
383
- let r2, i2;
384
- for (i2 = 0; i2 < o2.length; i2++)
385
- r2 = n(e2, o2[i2]), r2 && (s2[o2[i2]] = t(r2));
386
- return s2;
387
- }
388
- function r(e2) {
389
- const n2 = s(e2, ["name", "cmt", "desc", "type", "time", "keywords"]), o2 = e2.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/GpxExtensions/v3", "*");
390
- for (let s2 = 0; s2 < o2.length; s2++) {
391
- const r3 = o2[s2];
392
- r3.parentNode.parentNode === e2 && (n2[r3.tagName.replace(":", "_")] = t(r3));
393
- }
394
- const r2 = e2.getElementsByTagName("link");
395
- r2.length && (n2.links = []);
396
- for (let e3 = 0; e3 < r2.length; e3++)
397
- n2.links.push(Object.assign({ href: r2[e3].getAttribute("href") }, s(r2[e3], ["text", "type"])));
398
- return n2;
399
- }
400
- function i(e2) {
401
- const o2 = [parseFloat(e2.getAttribute("lon")), parseFloat(e2.getAttribute("lat"))], s2 = n(e2, "ele"), r2 = n(e2, "gpxtpx:hr") || n(e2, "hr"), i2 = n(e2, "time");
402
- let l2;
403
- s2 && (l2 = parseFloat(t(s2)), isNaN(l2) || o2.push(l2));
404
- const a2 = { coordinates: o2, time: i2 ? t(i2) : null, extendedValues: [] };
405
- r2 && a2.extendedValues.push(["heart", parseFloat(t(r2))]);
406
- const c2 = n(e2, "extensions");
407
- if (c2 !== null)
408
- for (const e3 of ["speed", "course", "hAcc", "vAcc"]) {
409
- const o3 = parseFloat(t(n(c2, e3)));
410
- isNaN(o3) || a2.extendedValues.push([e3, o3]);
411
- }
412
- return a2;
413
- }
414
- function l(e2) {
415
- const t2 = a(e2, "rtept");
416
- if (t2)
417
- return { type: "Feature", properties: Object.assign(r(e2), o(n(e2, "extensions")), { _gpxType: "rte" }), geometry: { type: "LineString", coordinates: t2.line } };
418
- }
419
- function a(e2, t2) {
420
- const n2 = e2.getElementsByTagName(t2);
421
- if (n2.length < 2)
422
- return;
423
- const o2 = [], s2 = [], r2 = {};
424
- for (let e3 = 0; e3 < n2.length; e3++) {
425
- const t3 = i(n2[e3]);
426
- o2.push(t3.coordinates), t3.time && s2.push(t3.time);
427
- for (let o3 = 0; o3 < t3.extendedValues.length; o3++) {
428
- const [s3, i2] = t3.extendedValues[o3], l2 = s3 === "heart" ? s3 : s3 + "s";
429
- r2[l2] || (r2[l2] = Array(n2.length).fill(null)), r2[l2][e3] = i2;
430
- }
431
- }
432
- return { line: o2, times: s2, extendedValues: r2 };
433
- }
434
- function c(e2) {
435
- const t2 = e2.getElementsByTagName("trkseg"), s2 = [], i2 = [], l2 = [];
436
- for (let e3 = 0; e3 < t2.length; e3++) {
437
- const n2 = a(t2[e3], "trkpt");
438
- n2 && (l2.push(n2), n2.times && n2.times.length && i2.push(n2.times));
439
- }
440
- if (l2.length === 0)
441
- return;
442
- const c2 = l2.length > 1, g2 = Object.assign(r(e2), o(n(e2, "extensions")), { _gpxType: "trk" }, i2.length ? { coordinateProperties: { times: c2 ? i2 : i2[0] } } : {});
443
- for (let e3 = 0; e3 < l2.length; e3++) {
444
- const t3 = l2[e3];
445
- s2.push(t3.line);
446
- for (const [n2, o2] of Object.entries(t3.extendedValues)) {
447
- let t4 = g2;
448
- n2 === "heart" && (g2.coordinateProperties || (g2.coordinateProperties = {}), t4 = g2.coordinateProperties), c2 ? (t4[n2] || (t4[n2] = l2.map((e4) => new Array(e4.line.length).fill(null))), t4[n2][e3] = o2) : t4[n2] = o2;
449
- }
450
- }
451
- return { type: "Feature", properties: g2, geometry: c2 ? { type: "MultiLineString", coordinates: s2 } : { type: "LineString", coordinates: s2[0] } };
452
- }
453
- function* g(e2) {
454
- const t2 = e2.getElementsByTagName("trk"), n2 = e2.getElementsByTagName("rte"), o2 = e2.getElementsByTagName("wpt");
455
- for (let e3 = 0; e3 < t2.length; e3++) {
456
- const n3 = c(t2[e3]);
457
- n3 && (yield n3);
458
- }
459
- for (let e3 = 0; e3 < n2.length; e3++) {
460
- const t3 = l(n2[e3]);
461
- t3 && (yield t3);
462
- }
463
- for (let e3 = 0; e3 < o2.length; e3++)
464
- yield (a2 = o2[e3], { type: "Feature", properties: Object.assign(r(a2), s(a2, ["sym"])), geometry: { type: "Point", coordinates: i(a2).coordinates } });
465
- var a2;
466
- }
467
- const u = [["heartRate", "heartRates"], ["Cadence", "cadences"], ["Speed", "speeds"], ["Watts", "watts"]], m = [["TotalTimeSeconds", "totalTimeSeconds"], ["DistanceMeters", "distanceMeters"], ["MaximumSpeed", "maxSpeed"], ["AverageHeartRateBpm", "avgHeartRate"], ["MaximumHeartRateBpm", "maxHeartRate"], ["AvgSpeed", "avgSpeed"], ["AvgWatts", "avgWatts"], ["MaxWatts", "maxWatts"]];
468
- function p(e2, o2) {
469
- const s2 = [];
470
- for (const [r2, i2] of o2) {
471
- let o3 = n(e2, r2);
472
- if (!o3) {
473
- const t2 = e2.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/ActivityExtension/v2", r2);
474
- t2.length && (o3 = t2[0]);
475
- }
476
- const l2 = parseFloat(t(o3));
477
- isNaN(l2) || s2.push([i2, l2]);
478
- }
479
- return s2;
480
- }
481
- function h(e2) {
482
- const o2 = t(n(e2, "LongitudeDegrees")), s2 = t(n(e2, "LatitudeDegrees"));
483
- if (!o2.length || !s2.length)
484
- return null;
485
- const r2 = [parseFloat(o2), parseFloat(s2)], i2 = n(e2, "AltitudeMeters"), l2 = n(e2, "HeartRateBpm"), a2 = n(e2, "Time");
486
- let c2;
487
- return i2 && (c2 = parseFloat(t(i2)), isNaN(c2) || r2.push(c2)), { coordinates: r2, time: a2 ? t(a2) : null, heartRate: l2 ? parseFloat(t(l2)) : null, extensions: p(e2, u) };
488
- }
489
- function f(e2, t2) {
490
- const n2 = e2.getElementsByTagName(t2), o2 = [], s2 = [], r2 = [];
491
- if (n2.length < 2)
492
- return null;
493
- const i2 = { extendedProperties: {} };
494
- for (let e3 = 0; e3 < n2.length; e3++) {
495
- const t3 = h(n2[e3]);
496
- if (t3 !== null) {
497
- o2.push(t3.coordinates), t3.time && s2.push(t3.time), t3.heartRate && r2.push(t3.heartRate);
498
- for (const [o3, s3] of t3.extensions)
499
- i2.extendedProperties[o3] || (i2.extendedProperties[o3] = Array(n2.length).fill(null)), i2.extendedProperties[o3][e3] = s3;
500
- }
501
- }
502
- return Object.assign(i2, { line: o2, times: s2, heartRates: r2 });
503
- }
504
- function d(e2) {
505
- const o2 = e2.getElementsByTagName("Track"), s2 = [], r2 = [], i2 = [], l2 = [];
506
- let a2;
507
- const c2 = function(e3) {
508
- const t2 = {};
509
- for (const [n2, o3] of e3)
510
- t2[n2] = o3;
511
- return t2;
512
- }(p(e2, m)), g2 = n(e2, "Name");
513
- g2 && (c2.name = t(g2));
514
- for (let e3 = 0; e3 < o2.length; e3++)
515
- a2 = f(o2[e3], "Trackpoint"), a2 && (s2.push(a2.line), a2.times.length && r2.push(a2.times), a2.heartRates.length && i2.push(a2.heartRates), l2.push(a2.extendedProperties));
516
- for (let e3 = 0; e3 < l2.length; e3++) {
517
- const t2 = l2[e3];
518
- for (const n2 in t2)
519
- o2.length === 1 ? c2[n2] = a2.extendedProperties[n2] : (c2[n2] || (c2[n2] = s2.map((e4) => Array(e4.length).fill(null))), c2[n2][e3] = t2[n2]);
520
- }
521
- if (s2.length !== 0)
522
- return (r2.length || i2.length) && (c2.coordinateProperties = Object.assign(r2.length ? { times: s2.length === 1 ? r2[0] : r2 } : {}, i2.length ? { heart: s2.length === 1 ? i2[0] : i2 } : {})), { type: "Feature", properties: c2, geometry: { type: s2.length === 1 ? "LineString" : "MultiLineString", coordinates: s2.length === 1 ? s2[0] : s2 } };
523
- }
524
- function* y(e2) {
525
- const t2 = e2.getElementsByTagName("Lap");
526
- for (let e3 = 0; e3 < t2.length; e3++) {
527
- const n3 = d(t2[e3]);
528
- n3 && (yield n3);
529
- }
530
- const n2 = e2.getElementsByTagName("Courses");
531
- for (let e3 = 0; e3 < n2.length; e3++) {
532
- const t3 = d(n2[e3]);
533
- t3 && (yield t3);
534
- }
535
- }
536
- const N = /\s*/g, x = /^\s*|\s*$/g, T = /\s+/;
537
- function b(e2) {
538
- if (!e2 || !e2.length)
539
- return 0;
540
- let t2 = 0;
541
- for (let n2 = 0; n2 < e2.length; n2++)
542
- t2 = (t2 << 5) - t2 + e2.charCodeAt(n2) | 0;
543
- return t2;
544
- }
545
- function S(e2) {
546
- return e2.replace(N, "").split(",").map(parseFloat);
547
- }
548
- function k(e2) {
549
- return e2.replace(x, "").split(T).map(S);
550
- }
551
- function A(e2) {
552
- if (e2.xml !== void 0)
553
- return e2.xml;
554
- if (e2.tagName) {
555
- let t2 = e2.tagName;
556
- for (let n2 = 0; n2 < e2.attributes.length; n2++)
557
- t2 += e2.attributes[n2].name + e2.attributes[n2].value;
558
- for (let n2 = 0; n2 < e2.childNodes.length; n2++)
559
- t2 += A(e2.childNodes[n2]);
560
- return t2;
561
- }
562
- return e2.nodeName === "#text" ? (e2.nodeValue || e2.value || "").trim() : e2.nodeName === "#cdata-section" ? e2.nodeValue : "";
563
- }
564
- const B = ["Polygon", "LineString", "Point", "Track", "gx:Track"];
565
- function E(e2, o2, s2) {
566
- let r2 = t(n(o2, "color")) || "";
567
- const i2 = s2 == "stroke" || s2 === "fill" ? s2 : s2 + "-color";
568
- r2.substr(0, 1) === "#" && (r2 = r2.substr(1)), r2.length === 6 || r2.length === 3 ? e2[i2] = r2 : r2.length === 8 && (e2[s2 + "-opacity"] = parseInt(r2.substr(0, 2), 16) / 255, e2[i2] = "#" + r2.substr(6, 2) + r2.substr(4, 2) + r2.substr(2, 2));
569
- }
570
- function F(e2, o2, s2, r2) {
571
- const i2 = parseFloat(t(n(o2, s2)));
572
- isNaN(i2) || (e2[r2] = i2);
573
- }
574
- function P(e2) {
575
- let n2 = e2.getElementsByTagName("coord");
576
- const o2 = [], s2 = [];
577
- n2.length === 0 && (n2 = e2.getElementsByTagName("gx:coord"));
578
- for (let e3 = 0; e3 < n2.length; e3++)
579
- o2.push(t(n2[e3]).split(" ").map(parseFloat));
580
- const r2 = e2.getElementsByTagName("when");
581
- for (let e3 = 0; e3 < r2.length; e3++)
582
- s2.push(t(r2[e3]));
583
- return { coords: o2, times: s2 };
584
- }
585
- function v(e2) {
586
- let o2, s2, r2, i2, l2;
587
- const a2 = [], c2 = [];
588
- if (n(e2, "MultiGeometry"))
589
- return v(n(e2, "MultiGeometry"));
590
- if (n(e2, "MultiTrack"))
591
- return v(n(e2, "MultiTrack"));
592
- if (n(e2, "gx:MultiTrack"))
593
- return v(n(e2, "gx:MultiTrack"));
594
- for (r2 = 0; r2 < B.length; r2++)
595
- if (s2 = e2.getElementsByTagName(B[r2]), s2) {
596
- for (i2 = 0; i2 < s2.length; i2++)
597
- if (o2 = s2[i2], B[r2] === "Point")
598
- a2.push({ type: "Point", coordinates: S(t(n(o2, "coordinates"))) });
599
- else if (B[r2] === "LineString")
600
- a2.push({ type: "LineString", coordinates: k(t(n(o2, "coordinates"))) });
601
- else if (B[r2] === "Polygon") {
602
- const e3 = o2.getElementsByTagName("LinearRing"), s3 = [];
603
- for (l2 = 0; l2 < e3.length; l2++)
604
- s3.push(k(t(n(e3[l2], "coordinates"))));
605
- a2.push({ type: "Polygon", coordinates: s3 });
606
- } else if (B[r2] === "Track" || B[r2] === "gx:Track") {
607
- const e3 = P(o2);
608
- a2.push({ type: "LineString", coordinates: e3.coords }), e3.times.length && c2.push(e3.times);
609
- }
610
- }
611
- return { geoms: a2, coordTimes: c2 };
612
- }
613
- function L(e2, o2, s2, r2) {
614
- const i2 = v(e2);
615
- let l2;
616
- const a2 = {}, c2 = t(n(e2, "name")), g2 = t(n(e2, "address"));
617
- let u2 = t(n(e2, "styleUrl"));
618
- const m2 = t(n(e2, "description")), p2 = n(e2, "TimeSpan"), h2 = n(e2, "TimeStamp"), f2 = n(e2, "ExtendedData");
619
- let d2 = n(e2, "IconStyle"), y2 = n(e2, "LabelStyle"), N2 = n(e2, "LineStyle"), x2 = n(e2, "PolyStyle");
620
- const T2 = n(e2, "visibility");
621
- if (c2 && (a2.name = c2), g2 && (a2.address = g2), u2) {
622
- u2[0] !== "#" && (u2 = "#" + u2), a2.styleUrl = u2, o2[u2] && (a2.styleHash = o2[u2]), s2[u2] && (a2.styleMapHash = s2[u2], a2.styleHash = o2[s2[u2].normal]);
623
- const e3 = r2[a2.styleHash];
624
- e3 && (d2 || (d2 = n(e3, "IconStyle")), y2 || (y2 = n(e3, "LabelStyle")), N2 || (N2 = n(e3, "LineStyle")), x2 || (x2 = n(e3, "PolyStyle")));
625
- }
626
- if (m2 && (a2.description = m2), p2) {
627
- const e3 = t(n(p2, "begin")), o3 = t(n(p2, "end"));
628
- a2.timespan = { begin: e3, end: o3 };
629
- }
630
- if (h2 && (a2.timestamp = t(n(h2, "when"))), d2) {
631
- E(a2, d2, "icon"), F(a2, d2, "scale", "icon-scale"), F(a2, d2, "heading", "icon-heading");
632
- const e3 = n(d2, "hotSpot");
633
- if (e3) {
634
- const t2 = parseFloat(e3.getAttribute("x")), n2 = parseFloat(e3.getAttribute("y"));
635
- isNaN(t2) || isNaN(n2) || (a2["icon-offset"] = [t2, n2]);
636
- }
637
- const o3 = n(d2, "Icon");
638
- if (o3) {
639
- const e4 = t(n(o3, "href"));
640
- e4 && (a2.icon = e4);
641
- }
642
- }
643
- if (y2 && (E(a2, y2, "label"), F(a2, y2, "scale", "label-scale")), N2 && (E(a2, N2, "stroke"), F(a2, N2, "width", "stroke-width")), x2) {
644
- E(a2, x2, "fill");
645
- const e3 = t(n(x2, "fill")), o3 = t(n(x2, "outline"));
646
- e3 && (a2["fill-opacity"] = e3 === "1" ? a2["fill-opacity"] || 1 : 0), o3 && (a2["stroke-opacity"] = o3 === "1" ? a2["stroke-opacity"] || 1 : 0);
647
- }
648
- if (f2) {
649
- const e3 = f2.getElementsByTagName("Data"), o3 = f2.getElementsByTagName("SimpleData");
650
- for (l2 = 0; l2 < e3.length; l2++)
651
- a2[e3[l2].getAttribute("name")] = t(n(e3[l2], "value"));
652
- for (l2 = 0; l2 < o3.length; l2++)
653
- a2[o3[l2].getAttribute("name")] = t(o3[l2]);
654
- }
655
- T2 && (a2.visibility = t(T2)), i2.coordTimes.length && (a2.coordinateProperties = { times: i2.coordTimes.length === 1 ? i2.coordTimes[0] : i2.coordTimes });
656
- const b2 = { type: "Feature", geometry: i2.geoms.length === 0 ? null : i2.geoms.length === 1 ? i2.geoms[0] : { type: "GeometryCollection", geometries: i2.geoms }, properties: a2 };
657
- return e2.getAttribute("id") && (b2.id = e2.getAttribute("id")), b2;
658
- }
659
- function* M(e2) {
660
- const o2 = {}, s2 = {}, r2 = {}, i2 = e2.getElementsByTagName("Placemark"), l2 = e2.getElementsByTagName("Style"), a2 = e2.getElementsByTagName("StyleMap");
661
- for (let e3 = 0; e3 < l2.length; e3++) {
662
- const t2 = b(A(l2[e3])).toString(16);
663
- o2["#" + l2[e3].getAttribute("id")] = t2, s2[t2] = l2[e3];
664
- }
665
- for (let e3 = 0; e3 < a2.length; e3++) {
666
- o2["#" + a2[e3].getAttribute("id")] = b(A(a2[e3])).toString(16);
667
- const s3 = a2[e3].getElementsByTagName("Pair"), i3 = {};
668
- for (let e4 = 0; e4 < s3.length; e4++)
669
- i3[t(n(s3[e4], "key"))] = t(n(s3[e4], "styleUrl"));
670
- r2["#" + a2[e3].getAttribute("id")] = i3;
671
- }
672
- for (let e3 = 0; e3 < i2.length; e3++) {
673
- const t2 = L(i2[e3], o2, r2, s2);
674
- t2 && (yield t2);
675
- }
676
- }
677
- e.gpx = function(e2) {
678
- return { type: "FeatureCollection", features: Array.from(g(e2)) };
679
- }, e.gpxGen = g, e.kml = function(e2) {
680
- return { type: "FeatureCollection", features: Array.from(M(e2)) };
681
- }, e.kmlGen = M, e.tcx = function(e2) {
682
- return { type: "FeatureCollection", features: Array.from(y(e2)) };
683
- }, e.tcxGen = y, Object.defineProperty(e, "__esModule", { value: true });
684
- });
685
- }
686
- });
687
-
688
- // src/gpx-loader.ts
689
- function parseTextSync(text, options) {
690
- const doc = new DOMParser().parseFromString(text, "text/xml");
691
- const geojson = (0, import_togeojson.gpx)(doc);
692
- switch (options?.gpx?.type) {
693
- case "object-row-table":
694
- return geojson.features;
695
- default:
696
- }
697
- switch (options?.gis?.format) {
698
- case "geojson":
699
- return geojson;
700
- case "binary":
701
- return geojsonToBinary(geojson.features);
702
- case "raw":
703
- return doc;
704
- default:
705
- throw new Error();
706
- }
707
- }
708
- var import_togeojson, VERSION, GPX_HEADER, GPXLoader;
709
- var init_gpx_loader = __esm({
710
- "src/gpx-loader.ts"() {
711
- init_src();
712
- import_togeojson = __toModule(require_togeojson_umd());
713
- VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
714
- GPX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
715
- <gpx`;
716
- GPXLoader = {
717
- name: "GPX (GPS exchange format)",
718
- id: "gpx",
719
- module: "kml",
720
- version: VERSION,
721
- extensions: ["gpx"],
722
- mimeTypes: ["application/gpx+xml"],
723
- text: true,
724
- tests: [GPX_HEADER],
725
- parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
726
- parseTextSync,
727
- options: {
728
- gpx: {},
729
- gis: { format: "geojson" }
730
- }
731
- };
732
- }
733
- });
734
-
735
- // src/kml-loader.ts
736
- function parseTextSync2(text, options) {
737
- const doc = new DOMParser().parseFromString(text, "text/xml");
738
- const geojson = (0, import_togeojson2.kml)(doc);
739
- switch (options?.kml?.type) {
740
- case "object-row-table":
741
- return geojson.features;
742
- default:
743
- }
744
- switch (options?.gis?.format) {
745
- case "geojson":
746
- return geojson;
747
- case "binary":
748
- return geojsonToBinary(geojson.features);
749
- case "raw":
750
- return doc;
751
- default:
752
- throw new Error();
753
- }
754
- }
755
- var import_togeojson2, VERSION2, KML_HEADER, KMLLoader;
756
- var init_kml_loader = __esm({
757
- "src/kml-loader.ts"() {
758
- init_src();
759
- import_togeojson2 = __toModule(require_togeojson_umd());
760
- VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
761
- KML_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
762
- <kml xmlns="http://www.opengis.net/kml/2.2">`;
763
- KMLLoader = {
764
- name: "KML (Keyhole Markup Language)",
765
- id: "kml",
766
- module: "kml",
767
- version: VERSION2,
768
- extensions: ["kml"],
769
- mimeTypes: ["application/vnd.google-earth.kml+xml"],
770
- text: true,
771
- tests: [KML_HEADER],
772
- parse: async (arrayBuffer, options) => parseTextSync2(new TextDecoder().decode(arrayBuffer), options),
773
- parseTextSync: parseTextSync2,
774
- options: {
775
- kml: {},
776
- gis: { format: "geojson" }
777
- }
778
- };
779
- }
780
- });
781
-
782
- // src/tcx-loader.ts
783
- function parseTextSync3(text, options = {}) {
784
- const doc = new DOMParser().parseFromString(text, "text/xml");
785
- const geojson = (0, import_togeojson3.tcx)(doc);
786
- switch (options?.tcx?.type) {
787
- case "object-row-table":
788
- return geojson.features;
789
- default:
790
- }
791
- switch (options?.gis?.format) {
792
- case "geojson":
793
- return geojson;
794
- case "binary":
795
- return geojsonToBinary(geojson.features);
796
- case "raw":
797
- return doc;
798
- default:
799
- throw new Error();
800
- }
801
- }
802
- var import_togeojson3, VERSION3, TCX_HEADER, TCXLoader;
803
- var init_tcx_loader = __esm({
804
- "src/tcx-loader.ts"() {
805
- init_src();
806
- import_togeojson3 = __toModule(require_togeojson_umd());
807
- VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
808
- TCX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
809
- <TrainingCenterDatabase`;
810
- TCXLoader = {
811
- name: "TCX (Training Center XML)",
812
- id: "tcx",
813
- module: "kml",
814
- version: VERSION3,
815
- extensions: ["tcx"],
816
- mimeTypes: ["application/vnd.garmin.tcx+xml"],
817
- text: true,
818
- tests: [TCX_HEADER],
819
- parse: async (arrayBuffer, options) => parseTextSync3(new TextDecoder().decode(arrayBuffer), options),
820
- parseTextSync: parseTextSync3,
821
- options: {
822
- tcx: {},
823
- gis: { format: "geojson" }
824
- }
825
- };
826
- }
827
- });
828
-
829
- // src/index.ts
830
- var src_exports = {};
831
- __export(src_exports, {
832
- GPXLoader: () => GPXLoader,
833
- KMLLoader: () => KMLLoader,
834
- TCXLoader: () => TCXLoader
835
- });
836
- var init_src2 = __esm({
837
- "src/index.ts"() {
838
- init_gpx_loader();
839
- init_kml_loader();
840
- init_tcx_loader();
841
- }
842
- });
843
-
844
- // src/bundle.ts
845
- var require_bundle = __commonJS({
846
- "src/bundle.ts"(exports, module) {
847
- var moduleExports = (init_src2(), src_exports);
848
- globalThis.loaders = globalThis.loaders || {};
849
- module.exports = Object.assign(globalThis.loaders, moduleExports);
850
- }
851
- });
852
- require_bundle();
853
- })();
1
+ "use strict";
2
+ // @ts-nocheck
3
+ const moduleExports = require('./index');
4
+ globalThis.loaders = globalThis.loaders || {};
5
+ module.exports = Object.assign(globalThis.loaders, moduleExports);