@loaders.gl/kml 4.0.0-alpha.4 → 4.0.0-alpha.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.
Files changed (45) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/dist.min.js +1926 -0
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/gpx-loader.js +81 -0
  8. package/dist/es5/gpx-loader.js.map +1 -0
  9. package/dist/es5/index.js +27 -0
  10. package/dist/es5/index.js.map +1 -0
  11. package/dist/es5/kml-loader.js +81 -0
  12. package/dist/es5/kml-loader.js.map +1 -0
  13. package/dist/es5/tcx-loader.js +81 -0
  14. package/dist/es5/tcx-loader.js.map +1 -0
  15. package/dist/esm/bundle.js +4 -0
  16. package/dist/esm/bundle.js.map +1 -0
  17. package/dist/esm/gpx-loader.js +54 -0
  18. package/dist/esm/gpx-loader.js.map +1 -0
  19. package/dist/esm/index.js +4 -0
  20. package/dist/esm/index.js.map +1 -0
  21. package/dist/esm/kml-loader.js +54 -0
  22. package/dist/esm/kml-loader.js.map +1 -0
  23. package/dist/esm/tcx-loader.js +54 -0
  24. package/dist/esm/tcx-loader.js.map +1 -0
  25. package/dist/gpx-loader.d.ts +36 -0
  26. package/dist/gpx-loader.d.ts.map +1 -0
  27. package/dist/gpx-loader.js +57 -49
  28. package/dist/index.d.ts +7 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +9 -4
  31. package/dist/kml-loader.d.ts +36 -0
  32. package/dist/kml-loader.d.ts.map +1 -0
  33. package/dist/kml-loader.js +58 -49
  34. package/dist/tcx-loader.d.ts +36 -0
  35. package/dist/tcx-loader.d.ts.map +1 -0
  36. package/dist/tcx-loader.js +59 -50
  37. package/package.json +9 -12
  38. package/src/gpx-loader.ts +34 -14
  39. package/src/kml-loader.ts +33 -13
  40. package/src/tcx-loader.ts +33 -12
  41. package/dist/bundle.js.map +0 -1
  42. package/dist/gpx-loader.js.map +0 -1
  43. package/dist/index.js.map +0 -1
  44. package/dist/kml-loader.js.map +0 -1
  45. package/dist/tcx-loader.js.map +0 -1
@@ -0,0 +1,1926 @@
1
+ (() => {
2
+ var __defProp = Object.defineProperty;
3
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
6
+ };
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __export = (target, all) => {
11
+ __markAsModule(target);
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+
16
+ // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
17
+ var init_typeof = __esm({
18
+ "../../node_modules/@babel/runtime/helpers/esm/typeof.js"() {
19
+ }
20
+ });
21
+
22
+ // ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
23
+ var init_toPrimitive = __esm({
24
+ "../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js"() {
25
+ init_typeof();
26
+ }
27
+ });
28
+
29
+ // ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
30
+ var init_toPropertyKey = __esm({
31
+ "../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js"() {
32
+ init_typeof();
33
+ init_toPrimitive();
34
+ }
35
+ });
36
+
37
+ // ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
38
+ var init_defineProperty = __esm({
39
+ "../../node_modules/@babel/runtime/helpers/esm/defineProperty.js"() {
40
+ init_toPropertyKey();
41
+ }
42
+ });
43
+
44
+ // ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
45
+ function getPolygonSignedArea(points, options = {}) {
46
+ const {
47
+ start = 0,
48
+ end = points.length
49
+ } = options;
50
+ const dim = options.size || 2;
51
+ let area2 = 0;
52
+ for (let i = start, j = end - dim; i < end; i += dim) {
53
+ area2 += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
54
+ j = i;
55
+ }
56
+ return area2 / 2;
57
+ }
58
+ var init_polygon_utils = __esm({
59
+ "../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
60
+ }
61
+ });
62
+
63
+ // ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
64
+ var init_polygon = __esm({
65
+ "../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
66
+ init_defineProperty();
67
+ init_polygon_utils();
68
+ }
69
+ });
70
+
71
+ // ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
72
+ function earcut(positions, holeIndices, dim = 2, areas) {
73
+ const hasHoles = holeIndices && holeIndices.length;
74
+ const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
75
+ let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0]);
76
+ const triangles = [];
77
+ if (!outerNode || outerNode.next === outerNode.prev)
78
+ return triangles;
79
+ let invSize;
80
+ let maxX;
81
+ let maxY;
82
+ let minX;
83
+ let minY;
84
+ let x;
85
+ let y;
86
+ if (hasHoles)
87
+ outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas);
88
+ if (positions.length > 80 * dim) {
89
+ minX = maxX = positions[0];
90
+ minY = maxY = positions[1];
91
+ for (let i = dim; i < outerLen; i += dim) {
92
+ x = positions[i];
93
+ y = positions[i + 1];
94
+ if (x < minX)
95
+ minX = x;
96
+ if (y < minY)
97
+ minY = y;
98
+ if (x > maxX)
99
+ maxX = x;
100
+ if (y > maxY)
101
+ maxY = y;
102
+ }
103
+ invSize = Math.max(maxX - minX, maxY - minY);
104
+ invSize = invSize !== 0 ? 1 / invSize : 0;
105
+ }
106
+ earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
107
+ return triangles;
108
+ }
109
+ function linkedList(data, start, end, dim, clockwise, area2) {
110
+ let i;
111
+ let last;
112
+ if (area2 === void 0) {
113
+ area2 = getPolygonSignedArea(data, {
114
+ start,
115
+ end,
116
+ size: dim
117
+ });
118
+ }
119
+ if (clockwise === area2 < 0) {
120
+ for (i = start; i < end; i += dim)
121
+ last = insertNode(i, data[i], data[i + 1], last);
122
+ } else {
123
+ for (i = end - dim; i >= start; i -= dim)
124
+ last = insertNode(i, data[i], data[i + 1], last);
125
+ }
126
+ if (last && equals(last, last.next)) {
127
+ removeNode(last);
128
+ last = last.next;
129
+ }
130
+ return last;
131
+ }
132
+ function filterPoints(start, end) {
133
+ if (!start)
134
+ return start;
135
+ if (!end)
136
+ end = start;
137
+ let p = start;
138
+ let again;
139
+ do {
140
+ again = false;
141
+ if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
142
+ removeNode(p);
143
+ p = end = p.prev;
144
+ if (p === p.next)
145
+ break;
146
+ again = true;
147
+ } else {
148
+ p = p.next;
149
+ }
150
+ } while (again || p !== end);
151
+ return end;
152
+ }
153
+ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
154
+ if (!ear)
155
+ return;
156
+ if (!pass && invSize)
157
+ indexCurve(ear, minX, minY, invSize);
158
+ let stop = ear;
159
+ let prev;
160
+ let next;
161
+ while (ear.prev !== ear.next) {
162
+ prev = ear.prev;
163
+ next = ear.next;
164
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
165
+ triangles.push(prev.i / dim);
166
+ triangles.push(ear.i / dim);
167
+ triangles.push(next.i / dim);
168
+ removeNode(ear);
169
+ ear = next.next;
170
+ stop = next.next;
171
+ continue;
172
+ }
173
+ ear = next;
174
+ if (ear === stop) {
175
+ if (!pass) {
176
+ earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
177
+ } else if (pass === 1) {
178
+ ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
179
+ earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
180
+ } else if (pass === 2) {
181
+ splitEarcut(ear, triangles, dim, minX, minY, invSize);
182
+ }
183
+ break;
184
+ }
185
+ }
186
+ }
187
+ function isEar(ear) {
188
+ const a = ear.prev;
189
+ const b = ear;
190
+ const c = ear.next;
191
+ if (area(a, b, c) >= 0)
192
+ return false;
193
+ let p = ear.next.next;
194
+ while (p !== ear.prev) {
195
+ if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
196
+ return false;
197
+ p = p.next;
198
+ }
199
+ return true;
200
+ }
201
+ function isEarHashed(ear, minX, minY, invSize) {
202
+ const a = ear.prev;
203
+ const b = ear;
204
+ const c = ear.next;
205
+ if (area(a, b, c) >= 0)
206
+ return false;
207
+ const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
208
+ const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
209
+ const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
210
+ const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
211
+ const minZ = zOrder(minTX, minTY, minX, minY, invSize);
212
+ const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
213
+ let p = ear.prevZ;
214
+ let n = ear.nextZ;
215
+ while (p && p.z >= minZ && n && n.z <= maxZ) {
216
+ if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
217
+ return false;
218
+ p = p.prevZ;
219
+ if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
220
+ return false;
221
+ n = n.nextZ;
222
+ }
223
+ while (p && p.z >= minZ) {
224
+ if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
225
+ return false;
226
+ p = p.prevZ;
227
+ }
228
+ while (n && n.z <= maxZ) {
229
+ if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
230
+ return false;
231
+ n = n.nextZ;
232
+ }
233
+ return true;
234
+ }
235
+ function cureLocalIntersections(start, triangles, dim) {
236
+ let p = start;
237
+ do {
238
+ const a = p.prev;
239
+ const b = p.next.next;
240
+ if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
241
+ triangles.push(a.i / dim);
242
+ triangles.push(p.i / dim);
243
+ triangles.push(b.i / dim);
244
+ removeNode(p);
245
+ removeNode(p.next);
246
+ p = start = b;
247
+ }
248
+ p = p.next;
249
+ } while (p !== start);
250
+ return filterPoints(p);
251
+ }
252
+ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
253
+ let a = start;
254
+ do {
255
+ let b = a.next.next;
256
+ while (b !== a.prev) {
257
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
258
+ let c = splitPolygon(a, b);
259
+ a = filterPoints(a, a.next);
260
+ c = filterPoints(c, c.next);
261
+ earcutLinked(a, triangles, dim, minX, minY, invSize);
262
+ earcutLinked(c, triangles, dim, minX, minY, invSize);
263
+ return;
264
+ }
265
+ b = b.next;
266
+ }
267
+ a = a.next;
268
+ } while (a !== start);
269
+ }
270
+ function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
271
+ const queue = [];
272
+ let i;
273
+ let len;
274
+ let start;
275
+ let end;
276
+ let list;
277
+ for (i = 0, len = holeIndices.length; i < len; i++) {
278
+ start = holeIndices[i] * dim;
279
+ end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
280
+ list = linkedList(data, start, end, dim, false, areas && areas[i + 1]);
281
+ if (list === list.next)
282
+ list.steiner = true;
283
+ queue.push(getLeftmost(list));
284
+ }
285
+ queue.sort(compareX);
286
+ for (i = 0; i < queue.length; i++) {
287
+ eliminateHole(queue[i], outerNode);
288
+ outerNode = filterPoints(outerNode, outerNode.next);
289
+ }
290
+ return outerNode;
291
+ }
292
+ function compareX(a, b) {
293
+ return a.x - b.x;
294
+ }
295
+ function eliminateHole(hole, outerNode) {
296
+ outerNode = findHoleBridge(hole, outerNode);
297
+ if (outerNode) {
298
+ const b = splitPolygon(outerNode, hole);
299
+ filterPoints(outerNode, outerNode.next);
300
+ filterPoints(b, b.next);
301
+ }
302
+ }
303
+ function findHoleBridge(hole, outerNode) {
304
+ let p = outerNode;
305
+ const hx = hole.x;
306
+ const hy = hole.y;
307
+ let qx = -Infinity;
308
+ let m;
309
+ do {
310
+ if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
311
+ const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
312
+ if (x <= hx && x > qx) {
313
+ qx = x;
314
+ if (x === hx) {
315
+ if (hy === p.y)
316
+ return p;
317
+ if (hy === p.next.y)
318
+ return p.next;
319
+ }
320
+ m = p.x < p.next.x ? p : p.next;
321
+ }
322
+ }
323
+ p = p.next;
324
+ } while (p !== outerNode);
325
+ if (!m)
326
+ return null;
327
+ if (hx === qx)
328
+ return m;
329
+ const stop = m;
330
+ const mx = m.x;
331
+ const my = m.y;
332
+ let tanMin = Infinity;
333
+ let tan;
334
+ p = m;
335
+ do {
336
+ if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
337
+ tan = Math.abs(hy - p.y) / (hx - p.x);
338
+ if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
339
+ m = p;
340
+ tanMin = tan;
341
+ }
342
+ }
343
+ p = p.next;
344
+ } while (p !== stop);
345
+ return m;
346
+ }
347
+ function sectorContainsSector(m, p) {
348
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
349
+ }
350
+ function indexCurve(start, minX, minY, invSize) {
351
+ let p = start;
352
+ do {
353
+ if (p.z === null)
354
+ p.z = zOrder(p.x, p.y, minX, minY, invSize);
355
+ p.prevZ = p.prev;
356
+ p.nextZ = p.next;
357
+ p = p.next;
358
+ } while (p !== start);
359
+ p.prevZ.nextZ = null;
360
+ p.prevZ = null;
361
+ sortLinked(p);
362
+ }
363
+ function sortLinked(list) {
364
+ let e;
365
+ let i;
366
+ let inSize = 1;
367
+ let numMerges;
368
+ let p;
369
+ let pSize;
370
+ let q;
371
+ let qSize;
372
+ let tail;
373
+ do {
374
+ p = list;
375
+ list = null;
376
+ tail = null;
377
+ numMerges = 0;
378
+ while (p) {
379
+ numMerges++;
380
+ q = p;
381
+ pSize = 0;
382
+ for (i = 0; i < inSize; i++) {
383
+ pSize++;
384
+ q = q.nextZ;
385
+ if (!q)
386
+ break;
387
+ }
388
+ qSize = inSize;
389
+ while (pSize > 0 || qSize > 0 && q) {
390
+ if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
391
+ e = p;
392
+ p = p.nextZ;
393
+ pSize--;
394
+ } else {
395
+ e = q;
396
+ q = q.nextZ;
397
+ qSize--;
398
+ }
399
+ if (tail)
400
+ tail.nextZ = e;
401
+ else
402
+ list = e;
403
+ e.prevZ = tail;
404
+ tail = e;
405
+ }
406
+ p = q;
407
+ }
408
+ tail.nextZ = null;
409
+ inSize *= 2;
410
+ } while (numMerges > 1);
411
+ return list;
412
+ }
413
+ function zOrder(x, y, minX, minY, invSize) {
414
+ x = 32767 * (x - minX) * invSize;
415
+ y = 32767 * (y - minY) * invSize;
416
+ x = (x | x << 8) & 16711935;
417
+ x = (x | x << 4) & 252645135;
418
+ x = (x | x << 2) & 858993459;
419
+ x = (x | x << 1) & 1431655765;
420
+ y = (y | y << 8) & 16711935;
421
+ y = (y | y << 4) & 252645135;
422
+ y = (y | y << 2) & 858993459;
423
+ y = (y | y << 1) & 1431655765;
424
+ return x | y << 1;
425
+ }
426
+ function getLeftmost(start) {
427
+ let p = start;
428
+ let leftmost = start;
429
+ do {
430
+ if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
431
+ leftmost = p;
432
+ p = p.next;
433
+ } while (p !== start);
434
+ return leftmost;
435
+ }
436
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
437
+ return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
438
+ }
439
+ function isValidDiagonal(a, b) {
440
+ return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
441
+ }
442
+ function area(p, q, r) {
443
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
444
+ }
445
+ function equals(p1, p2) {
446
+ return p1.x === p2.x && p1.y === p2.y;
447
+ }
448
+ function intersects(p1, q1, p2, q2) {
449
+ const o1 = sign(area(p1, q1, p2));
450
+ const o2 = sign(area(p1, q1, q2));
451
+ const o3 = sign(area(p2, q2, p1));
452
+ const o4 = sign(area(p2, q2, q1));
453
+ if (o1 !== o2 && o3 !== o4)
454
+ return true;
455
+ if (o1 === 0 && onSegment(p1, p2, q1))
456
+ return true;
457
+ if (o2 === 0 && onSegment(p1, q2, q1))
458
+ return true;
459
+ if (o3 === 0 && onSegment(p2, p1, q2))
460
+ return true;
461
+ if (o4 === 0 && onSegment(p2, q1, q2))
462
+ return true;
463
+ return false;
464
+ }
465
+ function onSegment(p, q, r) {
466
+ return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
467
+ }
468
+ function sign(num) {
469
+ return num > 0 ? 1 : num < 0 ? -1 : 0;
470
+ }
471
+ function intersectsPolygon(a, b) {
472
+ let p = a;
473
+ do {
474
+ if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
475
+ return true;
476
+ p = p.next;
477
+ } while (p !== a);
478
+ return false;
479
+ }
480
+ function locallyInside(a, b) {
481
+ return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
482
+ }
483
+ function middleInside(a, b) {
484
+ let p = a;
485
+ let inside = false;
486
+ const px = (a.x + b.x) / 2;
487
+ const py = (a.y + b.y) / 2;
488
+ do {
489
+ if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)
490
+ inside = !inside;
491
+ p = p.next;
492
+ } while (p !== a);
493
+ return inside;
494
+ }
495
+ function splitPolygon(a, b) {
496
+ const a2 = new Node(a.i, a.x, a.y);
497
+ const b2 = new Node(b.i, b.x, b.y);
498
+ const an = a.next;
499
+ const bp = b.prev;
500
+ a.next = b;
501
+ b.prev = a;
502
+ a2.next = an;
503
+ an.prev = a2;
504
+ b2.next = a2;
505
+ a2.prev = b2;
506
+ bp.next = b2;
507
+ b2.prev = bp;
508
+ return b2;
509
+ }
510
+ function insertNode(i, x, y, last) {
511
+ const p = new Node(i, x, y);
512
+ if (!last) {
513
+ p.prev = p;
514
+ p.next = p;
515
+ } else {
516
+ p.next = last.next;
517
+ p.prev = last;
518
+ last.next.prev = p;
519
+ last.next = p;
520
+ }
521
+ return p;
522
+ }
523
+ function removeNode(p) {
524
+ p.next.prev = p.prev;
525
+ p.prev.next = p.next;
526
+ if (p.prevZ)
527
+ p.prevZ.nextZ = p.nextZ;
528
+ if (p.nextZ)
529
+ p.nextZ.prevZ = p.prevZ;
530
+ }
531
+ function Node(i, x, y) {
532
+ this.i = i;
533
+ this.x = x;
534
+ this.y = y;
535
+ this.prev = null;
536
+ this.next = null;
537
+ this.z = null;
538
+ this.prevZ = null;
539
+ this.nextZ = null;
540
+ this.steiner = false;
541
+ }
542
+ var init_earcut = __esm({
543
+ "../../node_modules/@math.gl/polygon/dist/esm/earcut.js"() {
544
+ init_polygon_utils();
545
+ }
546
+ });
547
+
548
+ // ../../node_modules/@math.gl/polygon/dist/esm/utils.js
549
+ var init_utils = __esm({
550
+ "../../node_modules/@math.gl/polygon/dist/esm/utils.js"() {
551
+ }
552
+ });
553
+
554
+ // ../../node_modules/@math.gl/polygon/dist/esm/lineclip.js
555
+ var init_lineclip = __esm({
556
+ "../../node_modules/@math.gl/polygon/dist/esm/lineclip.js"() {
557
+ init_utils();
558
+ }
559
+ });
560
+
561
+ // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js
562
+ var init_cut_by_grid = __esm({
563
+ "../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js"() {
564
+ init_lineclip();
565
+ init_utils();
566
+ }
567
+ });
568
+
569
+ // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js
570
+ var init_cut_by_mercator_bounds = __esm({
571
+ "../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js"() {
572
+ init_cut_by_grid();
573
+ init_utils();
574
+ }
575
+ });
576
+
577
+ // ../../node_modules/@math.gl/polygon/dist/esm/index.js
578
+ var init_esm = __esm({
579
+ "../../node_modules/@math.gl/polygon/dist/esm/index.js"() {
580
+ init_polygon();
581
+ init_polygon_utils();
582
+ init_earcut();
583
+ init_lineclip();
584
+ init_cut_by_grid();
585
+ init_cut_by_mercator_bounds();
586
+ init_polygon();
587
+ }
588
+ });
589
+
590
+ // ../gis/src/lib/flat-geojson-to-binary.ts
591
+ function flatGeojsonToBinary(features, geometryInfo, options) {
592
+ const propArrayTypes = extractNumericPropTypes(features);
593
+ const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
594
+ return fillArrays(features, {
595
+ propArrayTypes,
596
+ ...geometryInfo
597
+ }, {
598
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
599
+ PositionDataType: options ? options.PositionDataType : Float32Array
600
+ });
601
+ }
602
+ function extractNumericPropTypes(features) {
603
+ const propArrayTypes = {};
604
+ for (const feature of features) {
605
+ if (feature.properties) {
606
+ for (const key in feature.properties) {
607
+ const val = feature.properties[key];
608
+ propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
609
+ }
610
+ }
611
+ }
612
+ return propArrayTypes;
613
+ }
614
+ function fillArrays(features, geometryInfo, options) {
615
+ const {
616
+ pointPositionsCount,
617
+ pointFeaturesCount,
618
+ linePositionsCount,
619
+ linePathsCount,
620
+ lineFeaturesCount,
621
+ polygonPositionsCount,
622
+ polygonObjectsCount,
623
+ polygonRingsCount,
624
+ polygonFeaturesCount,
625
+ propArrayTypes,
626
+ coordLength
627
+ } = geometryInfo;
628
+ const { numericPropKeys = [], PositionDataType = Float32Array } = options;
629
+ const hasGlobalId = features[0] && "id" in features[0];
630
+ const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
631
+ const points = {
632
+ type: "Point",
633
+ positions: new PositionDataType(pointPositionsCount * coordLength),
634
+ globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
635
+ featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
636
+ numericProps: {},
637
+ properties: [],
638
+ fields: []
639
+ };
640
+ const lines = {
641
+ type: "LineString",
642
+ pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
643
+ positions: new PositionDataType(linePositionsCount * coordLength),
644
+ globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
645
+ featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
646
+ numericProps: {},
647
+ properties: [],
648
+ fields: []
649
+ };
650
+ const polygons = {
651
+ type: "Polygon",
652
+ polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
653
+ primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
654
+ positions: new PositionDataType(polygonPositionsCount * coordLength),
655
+ triangles: [],
656
+ globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
657
+ featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
658
+ numericProps: {},
659
+ properties: [],
660
+ fields: []
661
+ };
662
+ for (const object of [points, lines, polygons]) {
663
+ for (const propName of numericPropKeys) {
664
+ const T = propArrayTypes[propName];
665
+ object.numericProps[propName] = new T(object.positions.length / coordLength);
666
+ }
667
+ }
668
+ lines.pathIndices[linePathsCount] = linePositionsCount;
669
+ polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
670
+ polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
671
+ const indexMap = {
672
+ pointPosition: 0,
673
+ pointFeature: 0,
674
+ linePosition: 0,
675
+ linePath: 0,
676
+ lineFeature: 0,
677
+ polygonPosition: 0,
678
+ polygonObject: 0,
679
+ polygonRing: 0,
680
+ polygonFeature: 0,
681
+ feature: 0
682
+ };
683
+ for (const feature of features) {
684
+ const geometry = feature.geometry;
685
+ const properties = feature.properties || {};
686
+ switch (geometry.type) {
687
+ case "Point":
688
+ handlePoint(geometry, points, indexMap, coordLength, properties);
689
+ points.properties.push(keepStringProperties(properties, numericPropKeys));
690
+ if (hasGlobalId) {
691
+ points.fields.push({ id: feature.id });
692
+ }
693
+ indexMap.pointFeature++;
694
+ break;
695
+ case "LineString":
696
+ handleLineString(geometry, lines, indexMap, coordLength, properties);
697
+ lines.properties.push(keepStringProperties(properties, numericPropKeys));
698
+ if (hasGlobalId) {
699
+ lines.fields.push({ id: feature.id });
700
+ }
701
+ indexMap.lineFeature++;
702
+ break;
703
+ case "Polygon":
704
+ handlePolygon(geometry, polygons, indexMap, coordLength, properties);
705
+ polygons.properties.push(keepStringProperties(properties, numericPropKeys));
706
+ if (hasGlobalId) {
707
+ polygons.fields.push({ id: feature.id });
708
+ }
709
+ indexMap.polygonFeature++;
710
+ break;
711
+ default:
712
+ throw new Error("Invalid geometry type");
713
+ }
714
+ indexMap.feature++;
715
+ }
716
+ return makeAccessorObjects(points, lines, polygons, coordLength);
717
+ }
718
+ function handlePoint(geometry, points, indexMap, coordLength, properties) {
719
+ points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
720
+ const nPositions = geometry.data.length / coordLength;
721
+ fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
722
+ points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
723
+ points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
724
+ indexMap.pointPosition += nPositions;
725
+ }
726
+ function handleLineString(geometry, lines, indexMap, coordLength, properties) {
727
+ lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
728
+ const nPositions = geometry.data.length / coordLength;
729
+ fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
730
+ lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
731
+ lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
732
+ for (let i = 0, il = geometry.indices.length; i < il; ++i) {
733
+ const start = geometry.indices[i];
734
+ const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
735
+ lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
736
+ indexMap.linePosition += (end - start) / coordLength;
737
+ }
738
+ }
739
+ function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
740
+ polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
741
+ const nPositions = geometry.data.length / coordLength;
742
+ fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
743
+ polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
744
+ polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
745
+ for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
746
+ const startPosition = indexMap.polygonPosition;
747
+ polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
748
+ const areas = geometry.areas[l];
749
+ const indices = geometry.indices[l];
750
+ const nextIndices = geometry.indices[l + 1];
751
+ for (let i = 0, il = indices.length; i < il; ++i) {
752
+ const start = indices[i];
753
+ const end = i === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i + 1];
754
+ polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
755
+ indexMap.polygonPosition += (end - start) / coordLength;
756
+ }
757
+ const endPosition = indexMap.polygonPosition;
758
+ triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
759
+ }
760
+ }
761
+ function triangulatePolygon(polygons, areas, indices, {
762
+ startPosition,
763
+ endPosition,
764
+ coordLength
765
+ }) {
766
+ const start = startPosition * coordLength;
767
+ const end = endPosition * coordLength;
768
+ const polygonPositions = polygons.positions.subarray(start, end);
769
+ const offset = indices[0];
770
+ const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
771
+ const triangles = earcut(polygonPositions, holes, coordLength, areas);
772
+ for (let t = 0, tl = triangles.length; t < tl; ++t) {
773
+ polygons.triangles.push(startPosition + triangles[t]);
774
+ }
775
+ }
776
+ function wrapProps(obj, size) {
777
+ const returnObj = {};
778
+ for (const key in obj) {
779
+ returnObj[key] = { value: obj[key], size };
780
+ }
781
+ return returnObj;
782
+ }
783
+ function makeAccessorObjects(points, lines, polygons, coordLength) {
784
+ return {
785
+ points: {
786
+ ...points,
787
+ positions: { value: points.positions, size: coordLength },
788
+ globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
789
+ featureIds: { value: points.featureIds, size: 1 },
790
+ numericProps: wrapProps(points.numericProps, 1)
791
+ },
792
+ lines: {
793
+ ...lines,
794
+ positions: { value: lines.positions, size: coordLength },
795
+ pathIndices: { value: lines.pathIndices, size: 1 },
796
+ globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
797
+ featureIds: { value: lines.featureIds, size: 1 },
798
+ numericProps: wrapProps(lines.numericProps, 1)
799
+ },
800
+ polygons: {
801
+ ...polygons,
802
+ positions: { value: polygons.positions, size: coordLength },
803
+ polygonIndices: { value: polygons.polygonIndices, size: 1 },
804
+ primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
805
+ triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
806
+ globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
807
+ featureIds: { value: polygons.featureIds, size: 1 },
808
+ numericProps: wrapProps(polygons.numericProps, 1)
809
+ }
810
+ };
811
+ }
812
+ function fillNumericProperties(object, properties, index, length) {
813
+ for (const numericPropName in object.numericProps) {
814
+ if (numericPropName in properties) {
815
+ const value = properties[numericPropName];
816
+ object.numericProps[numericPropName].fill(value, index, index + length);
817
+ }
818
+ }
819
+ }
820
+ function keepStringProperties(properties, numericKeys) {
821
+ const props = {};
822
+ for (const key in properties) {
823
+ if (!numericKeys.includes(key)) {
824
+ props[key] = properties[key];
825
+ }
826
+ }
827
+ return props;
828
+ }
829
+ function deduceArrayType(x, constructor) {
830
+ if (constructor === Array || !Number.isFinite(x)) {
831
+ return Array;
832
+ }
833
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
834
+ }
835
+ var init_flat_geojson_to_binary = __esm({
836
+ "../gis/src/lib/flat-geojson-to-binary.ts"() {
837
+ init_esm();
838
+ }
839
+ });
840
+
841
+ // ../gis/src/lib/extract-geometry-info.ts
842
+ function extractGeometryInfo(features) {
843
+ let pointPositionsCount = 0;
844
+ let pointFeaturesCount = 0;
845
+ let linePositionsCount = 0;
846
+ let linePathsCount = 0;
847
+ let lineFeaturesCount = 0;
848
+ let polygonPositionsCount = 0;
849
+ let polygonObjectsCount = 0;
850
+ let polygonRingsCount = 0;
851
+ let polygonFeaturesCount = 0;
852
+ const coordLengths = new Set();
853
+ for (const feature of features) {
854
+ const geometry = feature.geometry;
855
+ switch (geometry.type) {
856
+ case "Point":
857
+ pointFeaturesCount++;
858
+ pointPositionsCount++;
859
+ coordLengths.add(geometry.coordinates.length);
860
+ break;
861
+ case "MultiPoint":
862
+ pointFeaturesCount++;
863
+ pointPositionsCount += geometry.coordinates.length;
864
+ for (const point of geometry.coordinates) {
865
+ coordLengths.add(point.length);
866
+ }
867
+ break;
868
+ case "LineString":
869
+ lineFeaturesCount++;
870
+ linePositionsCount += geometry.coordinates.length;
871
+ linePathsCount++;
872
+ for (const coord2 of geometry.coordinates) {
873
+ coordLengths.add(coord2.length);
874
+ }
875
+ break;
876
+ case "MultiLineString":
877
+ lineFeaturesCount++;
878
+ for (const line of geometry.coordinates) {
879
+ linePositionsCount += line.length;
880
+ linePathsCount++;
881
+ for (const coord2 of line) {
882
+ coordLengths.add(coord2.length);
883
+ }
884
+ }
885
+ break;
886
+ case "Polygon":
887
+ polygonFeaturesCount++;
888
+ polygonObjectsCount++;
889
+ polygonRingsCount += geometry.coordinates.length;
890
+ const flattened = geometry.coordinates.flat();
891
+ polygonPositionsCount += flattened.length;
892
+ for (const coord2 of flattened) {
893
+ coordLengths.add(coord2.length);
894
+ }
895
+ break;
896
+ case "MultiPolygon":
897
+ polygonFeaturesCount++;
898
+ for (const polygon of geometry.coordinates) {
899
+ polygonObjectsCount++;
900
+ polygonRingsCount += polygon.length;
901
+ const flattened2 = polygon.flat();
902
+ polygonPositionsCount += flattened2.length;
903
+ for (const coord2 of flattened2) {
904
+ coordLengths.add(coord2.length);
905
+ }
906
+ }
907
+ break;
908
+ default:
909
+ throw new Error(`Unsupported geometry type: ${geometry.type}`);
910
+ }
911
+ }
912
+ return {
913
+ coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
914
+ pointPositionsCount,
915
+ pointFeaturesCount,
916
+ linePositionsCount,
917
+ linePathsCount,
918
+ lineFeaturesCount,
919
+ polygonPositionsCount,
920
+ polygonObjectsCount,
921
+ polygonRingsCount,
922
+ polygonFeaturesCount
923
+ };
924
+ }
925
+ var init_extract_geometry_info = __esm({
926
+ "../gis/src/lib/extract-geometry-info.ts"() {
927
+ }
928
+ });
929
+
930
+ // ../gis/src/lib/geojson-to-flat-geojson.ts
931
+ function geojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
932
+ return features.map((feature) => flattenFeature(feature, options));
933
+ }
934
+ function flattenPoint(coordinates, data, indices, options) {
935
+ indices.push(data.length);
936
+ data.push(...coordinates);
937
+ for (let i = coordinates.length; i < options.coordLength; i++) {
938
+ data.push(0);
939
+ }
940
+ }
941
+ function flattenLineString(coordinates, data, indices, options) {
942
+ indices.push(data.length);
943
+ for (const c of coordinates) {
944
+ data.push(...c);
945
+ for (let i = c.length; i < options.coordLength; i++) {
946
+ data.push(0);
947
+ }
948
+ }
949
+ }
950
+ function flattenPolygon(coordinates, data, indices, areas, options) {
951
+ let count = 0;
952
+ const ringAreas = [];
953
+ const polygons = [];
954
+ for (const lineString of coordinates) {
955
+ const lineString2d = lineString.map((p) => p.slice(0, 2));
956
+ let area2 = getPolygonSignedArea(lineString2d.flat());
957
+ const ccw = area2 < 0;
958
+ if (options.fixRingWinding && (count === 0 && !ccw || count > 0 && ccw)) {
959
+ lineString.reverse();
960
+ area2 = -area2;
961
+ }
962
+ ringAreas.push(area2);
963
+ flattenLineString(lineString, data, polygons, options);
964
+ count++;
965
+ }
966
+ if (count > 0) {
967
+ areas.push(ringAreas);
968
+ indices.push(polygons);
969
+ }
970
+ }
971
+ function flattenFeature(feature, options) {
972
+ const { geometry } = feature;
973
+ if (geometry.type === "GeometryCollection") {
974
+ throw new Error("GeometryCollection type not supported");
975
+ }
976
+ const data = [];
977
+ const indices = [];
978
+ let areas;
979
+ let type;
980
+ switch (geometry.type) {
981
+ case "Point":
982
+ type = "Point";
983
+ flattenPoint(geometry.coordinates, data, indices, options);
984
+ break;
985
+ case "MultiPoint":
986
+ type = "Point";
987
+ geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));
988
+ break;
989
+ case "LineString":
990
+ type = "LineString";
991
+ flattenLineString(geometry.coordinates, data, indices, options);
992
+ break;
993
+ case "MultiLineString":
994
+ type = "LineString";
995
+ geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));
996
+ break;
997
+ case "Polygon":
998
+ type = "Polygon";
999
+ areas = [];
1000
+ flattenPolygon(geometry.coordinates, data, indices, areas, options);
1001
+ break;
1002
+ case "MultiPolygon":
1003
+ type = "Polygon";
1004
+ areas = [];
1005
+ geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));
1006
+ break;
1007
+ default:
1008
+ throw new Error(`Unknown type: ${type}`);
1009
+ }
1010
+ return { ...feature, geometry: { type, indices, data, areas } };
1011
+ }
1012
+ var init_geojson_to_flat_geojson = __esm({
1013
+ "../gis/src/lib/geojson-to-flat-geojson.ts"() {
1014
+ init_esm();
1015
+ }
1016
+ });
1017
+
1018
+ // ../gis/src/lib/geojson-to-binary.ts
1019
+ function geojsonToBinary(features, options = { fixRingWinding: true }) {
1020
+ const geometryInfo = extractGeometryInfo(features);
1021
+ const coordLength = geometryInfo.coordLength;
1022
+ const { fixRingWinding } = options;
1023
+ const flatFeatures = geojsonToFlatGeojson(features, { coordLength, fixRingWinding });
1024
+ return flatGeojsonToBinary(flatFeatures, geometryInfo, {
1025
+ numericPropKeys: options.numericPropKeys,
1026
+ PositionDataType: options.PositionDataType || Float32Array
1027
+ });
1028
+ }
1029
+ var init_geojson_to_binary = __esm({
1030
+ "../gis/src/lib/geojson-to-binary.ts"() {
1031
+ init_extract_geometry_info();
1032
+ init_geojson_to_flat_geojson();
1033
+ init_flat_geojson_to_binary();
1034
+ }
1035
+ });
1036
+
1037
+ // ../gis/src/index.ts
1038
+ var init_src = __esm({
1039
+ "../gis/src/index.ts"() {
1040
+ init_geojson_to_binary();
1041
+ }
1042
+ });
1043
+
1044
+ // ../../node_modules/@tmcw/togeojson/dist/togeojson.es.js
1045
+ function nodeVal(x) {
1046
+ if (x && x.normalize) {
1047
+ x.normalize();
1048
+ }
1049
+ return x && x.textContent || "";
1050
+ }
1051
+ function get1(x, y) {
1052
+ const n = x.getElementsByTagName(y);
1053
+ return n.length ? n[0] : null;
1054
+ }
1055
+ function getLineStyle(extensions) {
1056
+ const style = {};
1057
+ if (extensions) {
1058
+ const lineStyle = get1(extensions, "line");
1059
+ if (lineStyle) {
1060
+ const color = nodeVal(get1(lineStyle, "color")), opacity = parseFloat(nodeVal(get1(lineStyle, "opacity"))), width = parseFloat(nodeVal(get1(lineStyle, "width")));
1061
+ if (color)
1062
+ style.stroke = color;
1063
+ if (!isNaN(opacity))
1064
+ style["stroke-opacity"] = opacity;
1065
+ if (!isNaN(width))
1066
+ style["stroke-width"] = width * 96 / 25.4;
1067
+ }
1068
+ }
1069
+ return style;
1070
+ }
1071
+ function getExtensions(node) {
1072
+ let values = [];
1073
+ if (node !== null) {
1074
+ for (let i = 0; i < node.childNodes.length; i++) {
1075
+ const child = node.childNodes[i];
1076
+ if (child.nodeType !== 1)
1077
+ continue;
1078
+ const name = ["heart", "gpxtpx:hr", "hr"].includes(child.nodeName) ? "heart" : child.nodeName;
1079
+ if (name === "gpxtpx:TrackPointExtension") {
1080
+ values = values.concat(getExtensions(child));
1081
+ } else {
1082
+ const val = nodeVal(child);
1083
+ values.push([name, isNaN(val) ? val : parseFloat(val)]);
1084
+ }
1085
+ }
1086
+ }
1087
+ return values;
1088
+ }
1089
+ function getMulti(x, ys) {
1090
+ const o = {};
1091
+ let n;
1092
+ let k;
1093
+ for (k = 0; k < ys.length; k++) {
1094
+ n = get1(x, ys[k]);
1095
+ if (n)
1096
+ o[ys[k]] = nodeVal(n);
1097
+ }
1098
+ return o;
1099
+ }
1100
+ function getProperties$1(node) {
1101
+ const prop = getMulti(node, [
1102
+ "name",
1103
+ "cmt",
1104
+ "desc",
1105
+ "type",
1106
+ "time",
1107
+ "keywords"
1108
+ ]);
1109
+ const extensions = node.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/GpxExtensions/v3", "*");
1110
+ for (let i = 0; i < extensions.length; i++) {
1111
+ const extension = extensions[i];
1112
+ if (extension.parentNode.parentNode === node) {
1113
+ prop[extension.tagName.replace(":", "_")] = nodeVal(extension);
1114
+ }
1115
+ }
1116
+ const links = node.getElementsByTagName("link");
1117
+ if (links.length)
1118
+ prop.links = [];
1119
+ for (let i = 0; i < links.length; i++) {
1120
+ prop.links.push(Object.assign({ href: links[i].getAttribute("href") }, getMulti(links[i], ["text", "type"])));
1121
+ }
1122
+ return prop;
1123
+ }
1124
+ function coordPair$1(x) {
1125
+ const ll = [
1126
+ parseFloat(x.getAttribute("lon")),
1127
+ parseFloat(x.getAttribute("lat"))
1128
+ ];
1129
+ const ele = get1(x, "ele");
1130
+ const time = get1(x, "time");
1131
+ if (ele) {
1132
+ const e = parseFloat(nodeVal(ele));
1133
+ if (!isNaN(e)) {
1134
+ ll.push(e);
1135
+ }
1136
+ }
1137
+ return {
1138
+ coordinates: ll,
1139
+ time: time ? nodeVal(time) : null,
1140
+ extendedValues: getExtensions(get1(x, "extensions"))
1141
+ };
1142
+ }
1143
+ function getRoute(node) {
1144
+ const line = getPoints$1(node, "rtept");
1145
+ if (!line)
1146
+ return;
1147
+ return {
1148
+ type: "Feature",
1149
+ properties: Object.assign(getProperties$1(node), getLineStyle(get1(node, "extensions")), { _gpxType: "rte" }),
1150
+ geometry: {
1151
+ type: "LineString",
1152
+ coordinates: line.line
1153
+ }
1154
+ };
1155
+ }
1156
+ function getPoints$1(node, pointname) {
1157
+ const pts = node.getElementsByTagName(pointname);
1158
+ if (pts.length < 2)
1159
+ return;
1160
+ const line = [];
1161
+ const times = [];
1162
+ const extendedValues = {};
1163
+ for (let i = 0; i < pts.length; i++) {
1164
+ const c = coordPair$1(pts[i]);
1165
+ line.push(c.coordinates);
1166
+ if (c.time)
1167
+ times.push(c.time);
1168
+ for (let j = 0; j < c.extendedValues.length; j++) {
1169
+ const [name, val] = c.extendedValues[j];
1170
+ const plural = name === "heart" ? name : name.replace("gpxtpx:", "") + "s";
1171
+ if (!extendedValues[plural]) {
1172
+ extendedValues[plural] = Array(pts.length).fill(null);
1173
+ }
1174
+ extendedValues[plural][i] = val;
1175
+ }
1176
+ }
1177
+ return {
1178
+ line,
1179
+ times,
1180
+ extendedValues
1181
+ };
1182
+ }
1183
+ function getTrack(node) {
1184
+ const segments = node.getElementsByTagName("trkseg");
1185
+ const track = [];
1186
+ const times = [];
1187
+ const extractedLines = [];
1188
+ for (let i = 0; i < segments.length; i++) {
1189
+ const line = getPoints$1(segments[i], "trkpt");
1190
+ if (line) {
1191
+ extractedLines.push(line);
1192
+ if (line.times && line.times.length)
1193
+ times.push(line.times);
1194
+ }
1195
+ }
1196
+ if (extractedLines.length === 0)
1197
+ return;
1198
+ const multi = extractedLines.length > 1;
1199
+ const properties = Object.assign(getProperties$1(node), getLineStyle(get1(node, "extensions")), { _gpxType: "trk" }, times.length ? {
1200
+ coordinateProperties: {
1201
+ times: multi ? times : times[0]
1202
+ }
1203
+ } : {});
1204
+ for (let i = 0; i < extractedLines.length; i++) {
1205
+ const line = extractedLines[i];
1206
+ track.push(line.line);
1207
+ for (const [name, val] of Object.entries(line.extendedValues)) {
1208
+ if (!properties.coordinateProperties) {
1209
+ properties.coordinateProperties = {};
1210
+ }
1211
+ const props = properties.coordinateProperties;
1212
+ if (multi) {
1213
+ if (!props[name])
1214
+ props[name] = extractedLines.map((line2) => new Array(line2.line.length).fill(null));
1215
+ props[name][i] = val;
1216
+ } else {
1217
+ props[name] = val;
1218
+ }
1219
+ }
1220
+ }
1221
+ return {
1222
+ type: "Feature",
1223
+ properties,
1224
+ geometry: multi ? {
1225
+ type: "MultiLineString",
1226
+ coordinates: track
1227
+ } : {
1228
+ type: "LineString",
1229
+ coordinates: track[0]
1230
+ }
1231
+ };
1232
+ }
1233
+ function getPoint(node) {
1234
+ return {
1235
+ type: "Feature",
1236
+ properties: Object.assign(getProperties$1(node), getMulti(node, ["sym"])),
1237
+ geometry: {
1238
+ type: "Point",
1239
+ coordinates: coordPair$1(node).coordinates
1240
+ }
1241
+ };
1242
+ }
1243
+ function* gpxGen(doc) {
1244
+ const tracks = doc.getElementsByTagName("trk");
1245
+ const routes = doc.getElementsByTagName("rte");
1246
+ const waypoints = doc.getElementsByTagName("wpt");
1247
+ for (let i = 0; i < tracks.length; i++) {
1248
+ const feature = getTrack(tracks[i]);
1249
+ if (feature)
1250
+ yield feature;
1251
+ }
1252
+ for (let i = 0; i < routes.length; i++) {
1253
+ const feature = getRoute(routes[i]);
1254
+ if (feature)
1255
+ yield feature;
1256
+ }
1257
+ for (let i = 0; i < waypoints.length; i++) {
1258
+ yield getPoint(waypoints[i]);
1259
+ }
1260
+ }
1261
+ function gpx(doc) {
1262
+ return {
1263
+ type: "FeatureCollection",
1264
+ features: Array.from(gpxGen(doc))
1265
+ };
1266
+ }
1267
+ function fromEntries(arr) {
1268
+ const obj = {};
1269
+ for (const [key, value] of arr) {
1270
+ obj[key] = value;
1271
+ }
1272
+ return obj;
1273
+ }
1274
+ function getProperties(node, attributeNames) {
1275
+ const properties = [];
1276
+ for (const [tag, alias] of attributeNames) {
1277
+ let elem = get1(node, tag);
1278
+ if (!elem) {
1279
+ const elements = node.getElementsByTagNameNS(EXTENSIONS_NS, tag);
1280
+ if (elements.length) {
1281
+ elem = elements[0];
1282
+ }
1283
+ }
1284
+ const val = parseFloat(nodeVal(elem));
1285
+ if (!isNaN(val)) {
1286
+ properties.push([alias, val]);
1287
+ }
1288
+ }
1289
+ return properties;
1290
+ }
1291
+ function coordPair(x) {
1292
+ const lon = nodeVal(get1(x, "LongitudeDegrees"));
1293
+ const lat = nodeVal(get1(x, "LatitudeDegrees"));
1294
+ if (!lon.length || !lat.length) {
1295
+ return null;
1296
+ }
1297
+ const ll = [parseFloat(lon), parseFloat(lat)];
1298
+ const alt = get1(x, "AltitudeMeters");
1299
+ const heartRate = get1(x, "HeartRateBpm");
1300
+ const time = get1(x, "Time");
1301
+ let a;
1302
+ if (alt) {
1303
+ a = parseFloat(nodeVal(alt));
1304
+ if (!isNaN(a)) {
1305
+ ll.push(a);
1306
+ }
1307
+ }
1308
+ return {
1309
+ coordinates: ll,
1310
+ time: time ? nodeVal(time) : null,
1311
+ heartRate: heartRate ? parseFloat(nodeVal(heartRate)) : null,
1312
+ extensions: getProperties(x, TRACKPOINT_ATTRIBUTES)
1313
+ };
1314
+ }
1315
+ function getPoints(node, pointname) {
1316
+ const pts = node.getElementsByTagName(pointname);
1317
+ const line = [];
1318
+ const times = [];
1319
+ const heartRates = [];
1320
+ if (pts.length < 2)
1321
+ return null;
1322
+ const result = { extendedProperties: {} };
1323
+ for (let i = 0; i < pts.length; i++) {
1324
+ const c = coordPair(pts[i]);
1325
+ if (c === null)
1326
+ continue;
1327
+ line.push(c.coordinates);
1328
+ if (c.time)
1329
+ times.push(c.time);
1330
+ if (c.heartRate)
1331
+ heartRates.push(c.heartRate);
1332
+ for (const [alias, value] of c.extensions) {
1333
+ if (!result.extendedProperties[alias]) {
1334
+ result.extendedProperties[alias] = Array(pts.length).fill(null);
1335
+ }
1336
+ result.extendedProperties[alias][i] = value;
1337
+ }
1338
+ }
1339
+ return Object.assign(result, {
1340
+ line,
1341
+ times,
1342
+ heartRates
1343
+ });
1344
+ }
1345
+ function getLap(node) {
1346
+ const segments = node.getElementsByTagName("Track");
1347
+ const track = [];
1348
+ const times = [];
1349
+ const heartRates = [];
1350
+ const allExtendedProperties = [];
1351
+ let line;
1352
+ const properties = fromEntries(getProperties(node, LAP_ATTRIBUTES));
1353
+ const nameElement = get1(node, "Name");
1354
+ if (nameElement) {
1355
+ properties.name = nodeVal(nameElement);
1356
+ }
1357
+ for (let i = 0; i < segments.length; i++) {
1358
+ line = getPoints(segments[i], "Trackpoint");
1359
+ if (line) {
1360
+ track.push(line.line);
1361
+ if (line.times.length)
1362
+ times.push(line.times);
1363
+ if (line.heartRates.length)
1364
+ heartRates.push(line.heartRates);
1365
+ allExtendedProperties.push(line.extendedProperties);
1366
+ }
1367
+ }
1368
+ for (let i = 0; i < allExtendedProperties.length; i++) {
1369
+ const extendedProperties = allExtendedProperties[i];
1370
+ for (const property in extendedProperties) {
1371
+ if (segments.length === 1) {
1372
+ properties[property] = line.extendedProperties[property];
1373
+ } else {
1374
+ if (!properties[property]) {
1375
+ properties[property] = track.map((track2) => Array(track2.length).fill(null));
1376
+ }
1377
+ properties[property][i] = extendedProperties[property];
1378
+ }
1379
+ }
1380
+ }
1381
+ if (track.length === 0)
1382
+ return;
1383
+ if (times.length || heartRates.length) {
1384
+ properties.coordinateProperties = Object.assign(times.length ? {
1385
+ times: track.length === 1 ? times[0] : times
1386
+ } : {}, heartRates.length ? {
1387
+ heart: track.length === 1 ? heartRates[0] : heartRates
1388
+ } : {});
1389
+ }
1390
+ return {
1391
+ type: "Feature",
1392
+ properties,
1393
+ geometry: {
1394
+ type: track.length === 1 ? "LineString" : "MultiLineString",
1395
+ coordinates: track.length === 1 ? track[0] : track
1396
+ }
1397
+ };
1398
+ }
1399
+ function* tcxGen(doc) {
1400
+ const laps = doc.getElementsByTagName("Lap");
1401
+ for (let i = 0; i < laps.length; i++) {
1402
+ const feature = getLap(laps[i]);
1403
+ if (feature)
1404
+ yield feature;
1405
+ }
1406
+ const courses = doc.getElementsByTagName("Courses");
1407
+ for (let i = 0; i < courses.length; i++) {
1408
+ const feature = getLap(courses[i]);
1409
+ if (feature)
1410
+ yield feature;
1411
+ }
1412
+ }
1413
+ function tcx(doc) {
1414
+ return {
1415
+ type: "FeatureCollection",
1416
+ features: Array.from(tcxGen(doc))
1417
+ };
1418
+ }
1419
+ function okhash(x) {
1420
+ if (!x || !x.length)
1421
+ return 0;
1422
+ let h = 0;
1423
+ for (let i = 0; i < x.length; i++) {
1424
+ h = (h << 5) - h + x.charCodeAt(i) | 0;
1425
+ }
1426
+ return h;
1427
+ }
1428
+ function coord1(v) {
1429
+ return v.replace(removeSpace, "").split(",").map(parseFloat);
1430
+ }
1431
+ function coord(v) {
1432
+ return v.replace(trimSpace, "").split(splitSpace).map(coord1);
1433
+ }
1434
+ function xml2str(node) {
1435
+ if (node.xml !== void 0)
1436
+ return node.xml;
1437
+ if (node.tagName) {
1438
+ let output = node.tagName;
1439
+ for (let i = 0; i < node.attributes.length; i++) {
1440
+ output += node.attributes[i].name + node.attributes[i].value;
1441
+ }
1442
+ for (let i = 0; i < node.childNodes.length; i++) {
1443
+ output += xml2str(node.childNodes[i]);
1444
+ }
1445
+ return output;
1446
+ }
1447
+ if (node.nodeName === "#text") {
1448
+ return (node.nodeValue || node.value || "").trim();
1449
+ }
1450
+ if (node.nodeName === "#cdata-section") {
1451
+ return node.nodeValue;
1452
+ }
1453
+ return "";
1454
+ }
1455
+ function kmlColor(properties, elem, prefix) {
1456
+ let v = nodeVal(get1(elem, "color")) || "";
1457
+ const colorProp = prefix == "stroke" || prefix === "fill" ? prefix : prefix + "-color";
1458
+ if (v.substr(0, 1) === "#") {
1459
+ v = v.substr(1);
1460
+ }
1461
+ if (v.length === 6 || v.length === 3) {
1462
+ properties[colorProp] = v;
1463
+ } else if (v.length === 8) {
1464
+ properties[prefix + "-opacity"] = parseInt(v.substr(0, 2), 16) / 255;
1465
+ properties[colorProp] = "#" + v.substr(6, 2) + v.substr(4, 2) + v.substr(2, 2);
1466
+ }
1467
+ }
1468
+ function numericProperty(properties, elem, source, target) {
1469
+ const val = parseFloat(nodeVal(get1(elem, source)));
1470
+ if (!isNaN(val))
1471
+ properties[target] = val;
1472
+ }
1473
+ function gxCoords(root) {
1474
+ let elems = root.getElementsByTagName("coord");
1475
+ const coords = [];
1476
+ const times = [];
1477
+ if (elems.length === 0)
1478
+ elems = root.getElementsByTagName("gx:coord");
1479
+ for (let i = 0; i < elems.length; i++) {
1480
+ coords.push(nodeVal(elems[i]).split(" ").map(parseFloat));
1481
+ }
1482
+ const timeElems = root.getElementsByTagName("when");
1483
+ for (let j = 0; j < timeElems.length; j++)
1484
+ times.push(nodeVal(timeElems[j]));
1485
+ return {
1486
+ coords,
1487
+ times
1488
+ };
1489
+ }
1490
+ function getGeometry(root) {
1491
+ let geomNode;
1492
+ let geomNodes;
1493
+ let i;
1494
+ let j;
1495
+ let k;
1496
+ const geoms = [];
1497
+ const coordTimes = [];
1498
+ if (get1(root, "MultiGeometry")) {
1499
+ return getGeometry(get1(root, "MultiGeometry"));
1500
+ }
1501
+ if (get1(root, "MultiTrack")) {
1502
+ return getGeometry(get1(root, "MultiTrack"));
1503
+ }
1504
+ if (get1(root, "gx:MultiTrack")) {
1505
+ return getGeometry(get1(root, "gx:MultiTrack"));
1506
+ }
1507
+ for (i = 0; i < geotypes.length; i++) {
1508
+ geomNodes = root.getElementsByTagName(geotypes[i]);
1509
+ if (geomNodes) {
1510
+ for (j = 0; j < geomNodes.length; j++) {
1511
+ geomNode = geomNodes[j];
1512
+ if (geotypes[i] === "Point") {
1513
+ geoms.push({
1514
+ type: "Point",
1515
+ coordinates: coord1(nodeVal(get1(geomNode, "coordinates")))
1516
+ });
1517
+ } else if (geotypes[i] === "LineString") {
1518
+ geoms.push({
1519
+ type: "LineString",
1520
+ coordinates: coord(nodeVal(get1(geomNode, "coordinates")))
1521
+ });
1522
+ } else if (geotypes[i] === "Polygon") {
1523
+ const rings = geomNode.getElementsByTagName("LinearRing"), coords = [];
1524
+ for (k = 0; k < rings.length; k++) {
1525
+ coords.push(coord(nodeVal(get1(rings[k], "coordinates"))));
1526
+ }
1527
+ geoms.push({
1528
+ type: "Polygon",
1529
+ coordinates: coords
1530
+ });
1531
+ } else if (geotypes[i] === "Track" || geotypes[i] === "gx:Track") {
1532
+ const track = gxCoords(geomNode);
1533
+ geoms.push({
1534
+ type: "LineString",
1535
+ coordinates: track.coords
1536
+ });
1537
+ if (track.times.length)
1538
+ coordTimes.push(track.times);
1539
+ }
1540
+ }
1541
+ }
1542
+ }
1543
+ return {
1544
+ geoms,
1545
+ coordTimes
1546
+ };
1547
+ }
1548
+ function getPlacemark(root, styleIndex, styleMapIndex, styleByHash) {
1549
+ const geomsAndTimes = getGeometry(root);
1550
+ let i;
1551
+ const properties = {};
1552
+ const name = nodeVal(get1(root, "name"));
1553
+ const address = nodeVal(get1(root, "address"));
1554
+ let styleUrl = nodeVal(get1(root, "styleUrl"));
1555
+ const description = nodeVal(get1(root, "description"));
1556
+ const timeSpan = get1(root, "TimeSpan");
1557
+ const timeStamp = get1(root, "TimeStamp");
1558
+ const extendedData = get1(root, "ExtendedData");
1559
+ let iconStyle = get1(root, "IconStyle");
1560
+ let labelStyle = get1(root, "LabelStyle");
1561
+ let lineStyle = get1(root, "LineStyle");
1562
+ let polyStyle = get1(root, "PolyStyle");
1563
+ const visibility = get1(root, "visibility");
1564
+ if (name)
1565
+ properties.name = name;
1566
+ if (address)
1567
+ properties.address = address;
1568
+ if (styleUrl) {
1569
+ if (styleUrl[0] !== "#") {
1570
+ styleUrl = "#" + styleUrl;
1571
+ }
1572
+ properties.styleUrl = styleUrl;
1573
+ if (styleIndex[styleUrl]) {
1574
+ properties.styleHash = styleIndex[styleUrl];
1575
+ }
1576
+ if (styleMapIndex[styleUrl]) {
1577
+ properties.styleMapHash = styleMapIndex[styleUrl];
1578
+ properties.styleHash = styleIndex[styleMapIndex[styleUrl].normal];
1579
+ }
1580
+ const style = styleByHash[properties.styleHash];
1581
+ if (style) {
1582
+ if (!iconStyle)
1583
+ iconStyle = get1(style, "IconStyle");
1584
+ if (!labelStyle)
1585
+ labelStyle = get1(style, "LabelStyle");
1586
+ if (!lineStyle)
1587
+ lineStyle = get1(style, "LineStyle");
1588
+ if (!polyStyle)
1589
+ polyStyle = get1(style, "PolyStyle");
1590
+ }
1591
+ }
1592
+ if (description)
1593
+ properties.description = description;
1594
+ if (timeSpan) {
1595
+ const begin = nodeVal(get1(timeSpan, "begin"));
1596
+ const end = nodeVal(get1(timeSpan, "end"));
1597
+ properties.timespan = { begin, end };
1598
+ }
1599
+ if (timeStamp) {
1600
+ properties.timestamp = nodeVal(get1(timeStamp, "when"));
1601
+ }
1602
+ if (iconStyle) {
1603
+ kmlColor(properties, iconStyle, "icon");
1604
+ numericProperty(properties, iconStyle, "scale", "icon-scale");
1605
+ numericProperty(properties, iconStyle, "heading", "icon-heading");
1606
+ const hotspot = get1(iconStyle, "hotSpot");
1607
+ if (hotspot) {
1608
+ const left = parseFloat(hotspot.getAttribute("x"));
1609
+ const top = parseFloat(hotspot.getAttribute("y"));
1610
+ if (!isNaN(left) && !isNaN(top))
1611
+ properties["icon-offset"] = [left, top];
1612
+ }
1613
+ const icon = get1(iconStyle, "Icon");
1614
+ if (icon) {
1615
+ const href = nodeVal(get1(icon, "href"));
1616
+ if (href)
1617
+ properties.icon = href;
1618
+ }
1619
+ }
1620
+ if (labelStyle) {
1621
+ kmlColor(properties, labelStyle, "label");
1622
+ numericProperty(properties, labelStyle, "scale", "label-scale");
1623
+ }
1624
+ if (lineStyle) {
1625
+ kmlColor(properties, lineStyle, "stroke");
1626
+ numericProperty(properties, lineStyle, "width", "stroke-width");
1627
+ }
1628
+ if (polyStyle) {
1629
+ kmlColor(properties, polyStyle, "fill");
1630
+ const fill = nodeVal(get1(polyStyle, "fill"));
1631
+ const outline = nodeVal(get1(polyStyle, "outline"));
1632
+ if (fill)
1633
+ properties["fill-opacity"] = fill === "1" ? properties["fill-opacity"] || 1 : 0;
1634
+ if (outline)
1635
+ properties["stroke-opacity"] = outline === "1" ? properties["stroke-opacity"] || 1 : 0;
1636
+ }
1637
+ if (extendedData) {
1638
+ const datas = extendedData.getElementsByTagName("Data"), simpleDatas = extendedData.getElementsByTagName("SimpleData");
1639
+ for (i = 0; i < datas.length; i++) {
1640
+ properties[datas[i].getAttribute("name")] = nodeVal(get1(datas[i], "value"));
1641
+ }
1642
+ for (i = 0; i < simpleDatas.length; i++) {
1643
+ properties[simpleDatas[i].getAttribute("name")] = nodeVal(simpleDatas[i]);
1644
+ }
1645
+ }
1646
+ if (visibility) {
1647
+ properties.visibility = nodeVal(visibility);
1648
+ }
1649
+ if (geomsAndTimes.coordTimes.length) {
1650
+ properties.coordinateProperties = {
1651
+ times: geomsAndTimes.coordTimes.length === 1 ? geomsAndTimes.coordTimes[0] : geomsAndTimes.coordTimes
1652
+ };
1653
+ }
1654
+ const feature = {
1655
+ type: "Feature",
1656
+ geometry: geomsAndTimes.geoms.length === 0 ? null : geomsAndTimes.geoms.length === 1 ? geomsAndTimes.geoms[0] : {
1657
+ type: "GeometryCollection",
1658
+ geometries: geomsAndTimes.geoms
1659
+ },
1660
+ properties
1661
+ };
1662
+ if (root.getAttribute("id"))
1663
+ feature.id = root.getAttribute("id");
1664
+ return feature;
1665
+ }
1666
+ function* kmlGen(doc) {
1667
+ const styleIndex = {};
1668
+ const styleByHash = {};
1669
+ const styleMapIndex = {};
1670
+ const placemarks = doc.getElementsByTagName("Placemark");
1671
+ const styles = doc.getElementsByTagName("Style");
1672
+ const styleMaps = doc.getElementsByTagName("StyleMap");
1673
+ for (let k = 0; k < styles.length; k++) {
1674
+ const style = styles[k];
1675
+ const hash = okhash(xml2str(style)).toString(16);
1676
+ let id = style.getAttribute("id");
1677
+ if (!id && style.parentNode.tagName.replace("gx:", "") === "CascadingStyle") {
1678
+ id = style.parentNode.getAttribute("kml:id") || style.parentNode.getAttribute("id");
1679
+ }
1680
+ styleIndex["#" + id] = hash;
1681
+ styleByHash[hash] = style;
1682
+ }
1683
+ for (let l = 0; l < styleMaps.length; l++) {
1684
+ styleIndex["#" + styleMaps[l].getAttribute("id")] = okhash(xml2str(styleMaps[l])).toString(16);
1685
+ const pairs = styleMaps[l].getElementsByTagName("Pair");
1686
+ const pairsMap = {};
1687
+ for (let m = 0; m < pairs.length; m++) {
1688
+ pairsMap[nodeVal(get1(pairs[m], "key"))] = nodeVal(get1(pairs[m], "styleUrl"));
1689
+ }
1690
+ styleMapIndex["#" + styleMaps[l].getAttribute("id")] = pairsMap;
1691
+ }
1692
+ for (let j = 0; j < placemarks.length; j++) {
1693
+ const feature = getPlacemark(placemarks[j], styleIndex, styleMapIndex, styleByHash);
1694
+ if (feature)
1695
+ yield feature;
1696
+ }
1697
+ }
1698
+ function kml(doc) {
1699
+ return {
1700
+ type: "FeatureCollection",
1701
+ features: Array.from(kmlGen(doc))
1702
+ };
1703
+ }
1704
+ var EXTENSIONS_NS, TRACKPOINT_ATTRIBUTES, LAP_ATTRIBUTES, removeSpace, trimSpace, splitSpace, geotypes;
1705
+ var init_togeojson_es = __esm({
1706
+ "../../node_modules/@tmcw/togeojson/dist/togeojson.es.js"() {
1707
+ EXTENSIONS_NS = "http://www.garmin.com/xmlschemas/ActivityExtension/v2";
1708
+ TRACKPOINT_ATTRIBUTES = [
1709
+ ["heartRate", "heartRates"],
1710
+ ["Cadence", "cadences"],
1711
+ ["Speed", "speeds"],
1712
+ ["Watts", "watts"]
1713
+ ];
1714
+ LAP_ATTRIBUTES = [
1715
+ ["TotalTimeSeconds", "totalTimeSeconds"],
1716
+ ["DistanceMeters", "distanceMeters"],
1717
+ ["MaximumSpeed", "maxSpeed"],
1718
+ ["AverageHeartRateBpm", "avgHeartRate"],
1719
+ ["MaximumHeartRateBpm", "maxHeartRate"],
1720
+ ["AvgSpeed", "avgSpeed"],
1721
+ ["AvgWatts", "avgWatts"],
1722
+ ["MaxWatts", "maxWatts"]
1723
+ ];
1724
+ removeSpace = /\s*/g;
1725
+ trimSpace = /^\s*|\s*$/g;
1726
+ splitSpace = /\s+/;
1727
+ geotypes = ["Polygon", "LineString", "Point", "Track", "gx:Track"];
1728
+ }
1729
+ });
1730
+
1731
+ // src/gpx-loader.ts
1732
+ function parseTextSync(text, options) {
1733
+ const doc = new DOMParser().parseFromString(text, "text/xml");
1734
+ const geojson = gpx(doc);
1735
+ const shape = options?.gis?.format || options?.gpx?.type || options?.gpx?.shape;
1736
+ switch (shape) {
1737
+ case "object-row-table": {
1738
+ const table = {
1739
+ shape: "object-row-table",
1740
+ data: geojson.features
1741
+ };
1742
+ return table;
1743
+ }
1744
+ case "geojson-row-table": {
1745
+ const table = {
1746
+ shape: "geojson-row-table",
1747
+ data: geojson.features
1748
+ };
1749
+ return table;
1750
+ }
1751
+ case "geojson":
1752
+ return geojson;
1753
+ case "binary":
1754
+ return geojsonToBinary(geojson.features);
1755
+ case "raw":
1756
+ return doc;
1757
+ default:
1758
+ return geojson;
1759
+ }
1760
+ }
1761
+ var VERSION, GPX_HEADER, GPXLoader;
1762
+ var init_gpx_loader = __esm({
1763
+ "src/gpx-loader.ts"() {
1764
+ init_src();
1765
+ init_togeojson_es();
1766
+ VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1767
+ GPX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1768
+ <gpx`;
1769
+ GPXLoader = {
1770
+ name: "GPX (GPS exchange format)",
1771
+ id: "gpx",
1772
+ module: "kml",
1773
+ version: VERSION,
1774
+ extensions: ["gpx"],
1775
+ mimeTypes: ["application/gpx+xml"],
1776
+ text: true,
1777
+ tests: [GPX_HEADER],
1778
+ parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
1779
+ parseTextSync,
1780
+ options: {
1781
+ gpx: {},
1782
+ gis: {}
1783
+ }
1784
+ };
1785
+ }
1786
+ });
1787
+
1788
+ // src/kml-loader.ts
1789
+ function parseTextSync2(text, options) {
1790
+ const doc = new DOMParser().parseFromString(text, "text/xml");
1791
+ const geojson = kml(doc);
1792
+ const shape = options?.gis?.format || options?.kml?.type || options?.kml?.shape;
1793
+ switch (shape) {
1794
+ case "object-row-table": {
1795
+ const table = {
1796
+ shape: "object-row-table",
1797
+ data: geojson.features
1798
+ };
1799
+ return table;
1800
+ }
1801
+ case "geojson-row-table": {
1802
+ const table = {
1803
+ shape: "geojson-row-table",
1804
+ data: geojson.features
1805
+ };
1806
+ return table;
1807
+ }
1808
+ case "geojson":
1809
+ return geojson;
1810
+ case "binary":
1811
+ return geojsonToBinary(geojson.features);
1812
+ case "raw":
1813
+ return doc;
1814
+ default:
1815
+ return geojson;
1816
+ }
1817
+ }
1818
+ var VERSION2, KML_HEADER, KMLLoader;
1819
+ var init_kml_loader = __esm({
1820
+ "src/kml-loader.ts"() {
1821
+ init_src();
1822
+ init_togeojson_es();
1823
+ VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1824
+ KML_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1825
+ <kml xmlns="http://www.opengis.net/kml/2.2">`;
1826
+ KMLLoader = {
1827
+ name: "KML (Keyhole Markup Language)",
1828
+ id: "kml",
1829
+ module: "kml",
1830
+ version: VERSION2,
1831
+ extensions: ["kml"],
1832
+ mimeTypes: ["application/vnd.google-earth.kml+xml"],
1833
+ text: true,
1834
+ tests: [KML_HEADER],
1835
+ parse: async (arrayBuffer, options) => parseTextSync2(new TextDecoder().decode(arrayBuffer), options),
1836
+ parseTextSync: parseTextSync2,
1837
+ options: {
1838
+ kml: {},
1839
+ gis: {}
1840
+ }
1841
+ };
1842
+ }
1843
+ });
1844
+
1845
+ // src/tcx-loader.ts
1846
+ function parseTextSync3(text, options) {
1847
+ const doc = new DOMParser().parseFromString(text, "text/xml");
1848
+ const geojson = tcx(doc);
1849
+ const shape = options?.gis?.format || options?.tcx?.type || options?.tcx?.shape;
1850
+ switch (shape) {
1851
+ case "object-row-table": {
1852
+ const table = {
1853
+ shape: "object-row-table",
1854
+ data: geojson.features
1855
+ };
1856
+ return table;
1857
+ }
1858
+ case "geojson-row-table": {
1859
+ const table = {
1860
+ shape: "geojson-row-table",
1861
+ data: geojson.features
1862
+ };
1863
+ return table;
1864
+ }
1865
+ case "geojson":
1866
+ return geojson;
1867
+ case "binary":
1868
+ return geojsonToBinary(geojson.features);
1869
+ case "raw":
1870
+ return doc;
1871
+ default:
1872
+ return geojson;
1873
+ }
1874
+ }
1875
+ var VERSION3, TCX_HEADER, TCXLoader;
1876
+ var init_tcx_loader = __esm({
1877
+ "src/tcx-loader.ts"() {
1878
+ init_src();
1879
+ init_togeojson_es();
1880
+ VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1881
+ TCX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1882
+ <TrainingCenterDatabase`;
1883
+ TCXLoader = {
1884
+ name: "TCX (Training Center XML)",
1885
+ id: "tcx",
1886
+ module: "kml",
1887
+ version: VERSION3,
1888
+ extensions: ["tcx"],
1889
+ mimeTypes: ["application/vnd.garmin.tcx+xml"],
1890
+ text: true,
1891
+ tests: [TCX_HEADER],
1892
+ parse: async (arrayBuffer, options) => parseTextSync3(new TextDecoder().decode(arrayBuffer), options),
1893
+ parseTextSync: parseTextSync3,
1894
+ options: {
1895
+ tcx: {},
1896
+ gis: {}
1897
+ }
1898
+ };
1899
+ }
1900
+ });
1901
+
1902
+ // src/index.ts
1903
+ var src_exports = {};
1904
+ __export(src_exports, {
1905
+ GPXLoader: () => GPXLoader,
1906
+ KMLLoader: () => KMLLoader,
1907
+ TCXLoader: () => TCXLoader
1908
+ });
1909
+ var init_src2 = __esm({
1910
+ "src/index.ts"() {
1911
+ init_gpx_loader();
1912
+ init_kml_loader();
1913
+ init_tcx_loader();
1914
+ }
1915
+ });
1916
+
1917
+ // src/bundle.ts
1918
+ var require_bundle = __commonJS({
1919
+ "src/bundle.ts"(exports, module) {
1920
+ var moduleExports = (init_src2(), src_exports);
1921
+ globalThis.loaders = globalThis.loaders || {};
1922
+ module.exports = Object.assign(globalThis.loaders, moduleExports);
1923
+ }
1924
+ });
1925
+ require_bundle();
1926
+ })();