@loaders.gl/kml 4.0.0-alpha.4 → 4.0.0-alpha.5

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.
@@ -0,0 +1,1529 @@
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
+ // ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
33
+ function getPolygonSignedArea(points, options = {}) {
34
+ const {
35
+ start = 0,
36
+ end = points.length
37
+ } = options;
38
+ const dim = options.size || 2;
39
+ let area2 = 0;
40
+ for (let i = start, j = end - dim; i < end; i += dim) {
41
+ area2 += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
42
+ j = i;
43
+ }
44
+ return area2 / 2;
45
+ }
46
+ var init_polygon_utils = __esm({
47
+ "../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
48
+ }
49
+ });
50
+
51
+ // ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
52
+ var init_polygon = __esm({
53
+ "../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
54
+ init_polygon_utils();
55
+ }
56
+ });
57
+
58
+ // ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
59
+ function earcut(data, holeIndices, dim, areas) {
60
+ dim = dim || 2;
61
+ const hasHoles = holeIndices && holeIndices.length;
62
+ const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
63
+ let outerNode = linkedList(data, 0, outerLen, dim, true, areas && areas[0]);
64
+ const triangles = [];
65
+ if (!outerNode || outerNode.next === outerNode.prev)
66
+ return triangles;
67
+ let invSize;
68
+ let maxX;
69
+ let maxY;
70
+ let minX;
71
+ let minY;
72
+ let x;
73
+ let y;
74
+ if (hasHoles)
75
+ outerNode = eliminateHoles(data, holeIndices, outerNode, dim, areas);
76
+ if (data.length > 80 * dim) {
77
+ minX = maxX = data[0];
78
+ minY = maxY = data[1];
79
+ for (let i = dim; i < outerLen; i += dim) {
80
+ x = data[i];
81
+ y = data[i + 1];
82
+ if (x < minX)
83
+ minX = x;
84
+ if (y < minY)
85
+ minY = y;
86
+ if (x > maxX)
87
+ maxX = x;
88
+ if (y > maxY)
89
+ maxY = y;
90
+ }
91
+ invSize = Math.max(maxX - minX, maxY - minY);
92
+ invSize = invSize !== 0 ? 1 / invSize : 0;
93
+ }
94
+ earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
95
+ return triangles;
96
+ }
97
+ function linkedList(data, start, end, dim, clockwise, area2) {
98
+ let i;
99
+ let last;
100
+ if (area2 === void 0) {
101
+ area2 = getPolygonSignedArea(data, {
102
+ start,
103
+ end,
104
+ size: dim
105
+ });
106
+ }
107
+ if (clockwise === area2 < 0) {
108
+ for (i = start; i < end; i += dim)
109
+ last = insertNode(i, data[i], data[i + 1], last);
110
+ } else {
111
+ for (i = end - dim; i >= start; i -= dim)
112
+ last = insertNode(i, data[i], data[i + 1], last);
113
+ }
114
+ if (last && equals(last, last.next)) {
115
+ removeNode(last);
116
+ last = last.next;
117
+ }
118
+ return last;
119
+ }
120
+ function filterPoints(start, end) {
121
+ if (!start)
122
+ return start;
123
+ if (!end)
124
+ end = start;
125
+ let p = start;
126
+ let again;
127
+ do {
128
+ again = false;
129
+ if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
130
+ removeNode(p);
131
+ p = end = p.prev;
132
+ if (p === p.next)
133
+ break;
134
+ again = true;
135
+ } else {
136
+ p = p.next;
137
+ }
138
+ } while (again || p !== end);
139
+ return end;
140
+ }
141
+ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
142
+ if (!ear)
143
+ return;
144
+ if (!pass && invSize)
145
+ indexCurve(ear, minX, minY, invSize);
146
+ let stop = ear;
147
+ let prev;
148
+ let next;
149
+ while (ear.prev !== ear.next) {
150
+ prev = ear.prev;
151
+ next = ear.next;
152
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
153
+ triangles.push(prev.i / dim);
154
+ triangles.push(ear.i / dim);
155
+ triangles.push(next.i / dim);
156
+ removeNode(ear);
157
+ ear = next.next;
158
+ stop = next.next;
159
+ continue;
160
+ }
161
+ ear = next;
162
+ if (ear === stop) {
163
+ if (!pass) {
164
+ earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
165
+ } else if (pass === 1) {
166
+ ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
167
+ earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
168
+ } else if (pass === 2) {
169
+ splitEarcut(ear, triangles, dim, minX, minY, invSize);
170
+ }
171
+ break;
172
+ }
173
+ }
174
+ }
175
+ function isEar(ear) {
176
+ const a = ear.prev;
177
+ const b = ear;
178
+ const c = ear.next;
179
+ if (area(a, b, c) >= 0)
180
+ return false;
181
+ let p = ear.next.next;
182
+ while (p !== ear.prev) {
183
+ 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)
184
+ return false;
185
+ p = p.next;
186
+ }
187
+ return true;
188
+ }
189
+ function isEarHashed(ear, minX, minY, invSize) {
190
+ const a = ear.prev;
191
+ const b = ear;
192
+ const c = ear.next;
193
+ if (area(a, b, c) >= 0)
194
+ return false;
195
+ const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
196
+ const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
197
+ const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
198
+ const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
199
+ const minZ = zOrder(minTX, minTY, minX, minY, invSize);
200
+ const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
201
+ let p = ear.prevZ;
202
+ let n = ear.nextZ;
203
+ while (p && p.z >= minZ && n && n.z <= maxZ) {
204
+ 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)
205
+ return false;
206
+ p = p.prevZ;
207
+ 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)
208
+ return false;
209
+ n = n.nextZ;
210
+ }
211
+ while (p && p.z >= minZ) {
212
+ 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)
213
+ return false;
214
+ p = p.prevZ;
215
+ }
216
+ while (n && n.z <= maxZ) {
217
+ 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)
218
+ return false;
219
+ n = n.nextZ;
220
+ }
221
+ return true;
222
+ }
223
+ function cureLocalIntersections(start, triangles, dim) {
224
+ let p = start;
225
+ do {
226
+ const a = p.prev;
227
+ const b = p.next.next;
228
+ if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
229
+ triangles.push(a.i / dim);
230
+ triangles.push(p.i / dim);
231
+ triangles.push(b.i / dim);
232
+ removeNode(p);
233
+ removeNode(p.next);
234
+ p = start = b;
235
+ }
236
+ p = p.next;
237
+ } while (p !== start);
238
+ return filterPoints(p);
239
+ }
240
+ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
241
+ let a = start;
242
+ do {
243
+ let b = a.next.next;
244
+ while (b !== a.prev) {
245
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
246
+ let c = splitPolygon(a, b);
247
+ a = filterPoints(a, a.next);
248
+ c = filterPoints(c, c.next);
249
+ earcutLinked(a, triangles, dim, minX, minY, invSize);
250
+ earcutLinked(c, triangles, dim, minX, minY, invSize);
251
+ return;
252
+ }
253
+ b = b.next;
254
+ }
255
+ a = a.next;
256
+ } while (a !== start);
257
+ }
258
+ function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
259
+ const queue = [];
260
+ let i;
261
+ let len;
262
+ let start;
263
+ let end;
264
+ let list;
265
+ for (i = 0, len = holeIndices.length; i < len; i++) {
266
+ start = holeIndices[i] * dim;
267
+ end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
268
+ list = linkedList(data, start, end, dim, false, areas && areas[i + 1]);
269
+ if (list === list.next)
270
+ list.steiner = true;
271
+ queue.push(getLeftmost(list));
272
+ }
273
+ queue.sort(compareX);
274
+ for (i = 0; i < queue.length; i++) {
275
+ eliminateHole(queue[i], outerNode);
276
+ outerNode = filterPoints(outerNode, outerNode.next);
277
+ }
278
+ return outerNode;
279
+ }
280
+ function compareX(a, b) {
281
+ return a.x - b.x;
282
+ }
283
+ function eliminateHole(hole, outerNode) {
284
+ outerNode = findHoleBridge(hole, outerNode);
285
+ if (outerNode) {
286
+ const b = splitPolygon(outerNode, hole);
287
+ filterPoints(outerNode, outerNode.next);
288
+ filterPoints(b, b.next);
289
+ }
290
+ }
291
+ function findHoleBridge(hole, outerNode) {
292
+ let p = outerNode;
293
+ const hx = hole.x;
294
+ const hy = hole.y;
295
+ let qx = -Infinity;
296
+ let m;
297
+ do {
298
+ if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
299
+ const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
300
+ if (x <= hx && x > qx) {
301
+ qx = x;
302
+ if (x === hx) {
303
+ if (hy === p.y)
304
+ return p;
305
+ if (hy === p.next.y)
306
+ return p.next;
307
+ }
308
+ m = p.x < p.next.x ? p : p.next;
309
+ }
310
+ }
311
+ p = p.next;
312
+ } while (p !== outerNode);
313
+ if (!m)
314
+ return null;
315
+ if (hx === qx)
316
+ return m;
317
+ const stop = m;
318
+ const mx = m.x;
319
+ const my = m.y;
320
+ let tanMin = Infinity;
321
+ let tan;
322
+ p = m;
323
+ do {
324
+ 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)) {
325
+ tan = Math.abs(hy - p.y) / (hx - p.x);
326
+ if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
327
+ m = p;
328
+ tanMin = tan;
329
+ }
330
+ }
331
+ p = p.next;
332
+ } while (p !== stop);
333
+ return m;
334
+ }
335
+ function sectorContainsSector(m, p) {
336
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
337
+ }
338
+ function indexCurve(start, minX, minY, invSize) {
339
+ let p = start;
340
+ do {
341
+ if (p.z === null)
342
+ p.z = zOrder(p.x, p.y, minX, minY, invSize);
343
+ p.prevZ = p.prev;
344
+ p.nextZ = p.next;
345
+ p = p.next;
346
+ } while (p !== start);
347
+ p.prevZ.nextZ = null;
348
+ p.prevZ = null;
349
+ sortLinked(p);
350
+ }
351
+ function sortLinked(list) {
352
+ let e;
353
+ let i;
354
+ let inSize = 1;
355
+ let numMerges;
356
+ let p;
357
+ let pSize;
358
+ let q;
359
+ let qSize;
360
+ let tail;
361
+ do {
362
+ p = list;
363
+ list = null;
364
+ tail = null;
365
+ numMerges = 0;
366
+ while (p) {
367
+ numMerges++;
368
+ q = p;
369
+ pSize = 0;
370
+ for (i = 0; i < inSize; i++) {
371
+ pSize++;
372
+ q = q.nextZ;
373
+ if (!q)
374
+ break;
375
+ }
376
+ qSize = inSize;
377
+ while (pSize > 0 || qSize > 0 && q) {
378
+ if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
379
+ e = p;
380
+ p = p.nextZ;
381
+ pSize--;
382
+ } else {
383
+ e = q;
384
+ q = q.nextZ;
385
+ qSize--;
386
+ }
387
+ if (tail)
388
+ tail.nextZ = e;
389
+ else
390
+ list = e;
391
+ e.prevZ = tail;
392
+ tail = e;
393
+ }
394
+ p = q;
395
+ }
396
+ tail.nextZ = null;
397
+ inSize *= 2;
398
+ } while (numMerges > 1);
399
+ return list;
400
+ }
401
+ function zOrder(x, y, minX, minY, invSize) {
402
+ x = 32767 * (x - minX) * invSize;
403
+ y = 32767 * (y - minY) * invSize;
404
+ x = (x | x << 8) & 16711935;
405
+ x = (x | x << 4) & 252645135;
406
+ x = (x | x << 2) & 858993459;
407
+ x = (x | x << 1) & 1431655765;
408
+ y = (y | y << 8) & 16711935;
409
+ y = (y | y << 4) & 252645135;
410
+ y = (y | y << 2) & 858993459;
411
+ y = (y | y << 1) & 1431655765;
412
+ return x | y << 1;
413
+ }
414
+ function getLeftmost(start) {
415
+ let p = start;
416
+ let leftmost = start;
417
+ do {
418
+ if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
419
+ leftmost = p;
420
+ p = p.next;
421
+ } while (p !== start);
422
+ return leftmost;
423
+ }
424
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
425
+ 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;
426
+ }
427
+ function isValidDiagonal(a, b) {
428
+ 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);
429
+ }
430
+ function area(p, q, r) {
431
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
432
+ }
433
+ function equals(p1, p2) {
434
+ return p1.x === p2.x && p1.y === p2.y;
435
+ }
436
+ function intersects(p1, q1, p2, q2) {
437
+ const o1 = sign(area(p1, q1, p2));
438
+ const o2 = sign(area(p1, q1, q2));
439
+ const o3 = sign(area(p2, q2, p1));
440
+ const o4 = sign(area(p2, q2, q1));
441
+ if (o1 !== o2 && o3 !== o4)
442
+ return true;
443
+ if (o1 === 0 && onSegment(p1, p2, q1))
444
+ return true;
445
+ if (o2 === 0 && onSegment(p1, q2, q1))
446
+ return true;
447
+ if (o3 === 0 && onSegment(p2, p1, q2))
448
+ return true;
449
+ if (o4 === 0 && onSegment(p2, q1, q2))
450
+ return true;
451
+ return false;
452
+ }
453
+ function onSegment(p, q, r) {
454
+ 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);
455
+ }
456
+ function sign(num) {
457
+ return num > 0 ? 1 : num < 0 ? -1 : 0;
458
+ }
459
+ function intersectsPolygon(a, b) {
460
+ let p = a;
461
+ do {
462
+ 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))
463
+ return true;
464
+ p = p.next;
465
+ } while (p !== a);
466
+ return false;
467
+ }
468
+ function locallyInside(a, b) {
469
+ 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;
470
+ }
471
+ function middleInside(a, b) {
472
+ let p = a;
473
+ let inside = false;
474
+ const px = (a.x + b.x) / 2;
475
+ const py = (a.y + b.y) / 2;
476
+ do {
477
+ 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)
478
+ inside = !inside;
479
+ p = p.next;
480
+ } while (p !== a);
481
+ return inside;
482
+ }
483
+ function splitPolygon(a, b) {
484
+ const a2 = new Node(a.i, a.x, a.y);
485
+ const b2 = new Node(b.i, b.x, b.y);
486
+ const an = a.next;
487
+ const bp = b.prev;
488
+ a.next = b;
489
+ b.prev = a;
490
+ a2.next = an;
491
+ an.prev = a2;
492
+ b2.next = a2;
493
+ a2.prev = b2;
494
+ bp.next = b2;
495
+ b2.prev = bp;
496
+ return b2;
497
+ }
498
+ function insertNode(i, x, y, last) {
499
+ const p = new Node(i, x, y);
500
+ if (!last) {
501
+ p.prev = p;
502
+ p.next = p;
503
+ } else {
504
+ p.next = last.next;
505
+ p.prev = last;
506
+ last.next.prev = p;
507
+ last.next = p;
508
+ }
509
+ return p;
510
+ }
511
+ function removeNode(p) {
512
+ p.next.prev = p.prev;
513
+ p.prev.next = p.next;
514
+ if (p.prevZ)
515
+ p.prevZ.nextZ = p.nextZ;
516
+ if (p.nextZ)
517
+ p.nextZ.prevZ = p.prevZ;
518
+ }
519
+ function Node(i, x, y) {
520
+ this.i = i;
521
+ this.x = x;
522
+ this.y = y;
523
+ this.prev = null;
524
+ this.next = null;
525
+ this.z = null;
526
+ this.prevZ = null;
527
+ this.nextZ = null;
528
+ this.steiner = false;
529
+ }
530
+ var init_earcut = __esm({
531
+ "../../node_modules/@math.gl/polygon/dist/esm/earcut.js"() {
532
+ init_polygon_utils();
533
+ }
534
+ });
535
+
536
+ // ../../node_modules/@math.gl/polygon/dist/esm/utils.js
537
+ var init_utils = __esm({
538
+ "../../node_modules/@math.gl/polygon/dist/esm/utils.js"() {
539
+ }
540
+ });
541
+
542
+ // ../../node_modules/@math.gl/polygon/dist/esm/lineclip.js
543
+ var init_lineclip = __esm({
544
+ "../../node_modules/@math.gl/polygon/dist/esm/lineclip.js"() {
545
+ init_utils();
546
+ }
547
+ });
548
+
549
+ // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js
550
+ var init_cut_by_grid = __esm({
551
+ "../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js"() {
552
+ init_lineclip();
553
+ init_utils();
554
+ }
555
+ });
556
+
557
+ // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js
558
+ var init_cut_by_mercator_bounds = __esm({
559
+ "../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js"() {
560
+ init_cut_by_grid();
561
+ init_utils();
562
+ }
563
+ });
564
+
565
+ // ../../node_modules/@math.gl/polygon/dist/esm/index.js
566
+ var init_esm = __esm({
567
+ "../../node_modules/@math.gl/polygon/dist/esm/index.js"() {
568
+ init_polygon();
569
+ init_polygon_utils();
570
+ init_earcut();
571
+ init_lineclip();
572
+ init_cut_by_grid();
573
+ init_cut_by_mercator_bounds();
574
+ init_polygon();
575
+ }
576
+ });
577
+
578
+ // ../gis/src/lib/flat-geojson-to-binary.ts
579
+ function flatGeojsonToBinary(features, geometryInfo, options) {
580
+ const propArrayTypes = extractNumericPropTypes(features);
581
+ const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
582
+ return fillArrays(features, {
583
+ propArrayTypes,
584
+ ...geometryInfo
585
+ }, {
586
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
587
+ PositionDataType: options ? options.PositionDataType : Float32Array
588
+ });
589
+ }
590
+ function extractNumericPropTypes(features) {
591
+ const propArrayTypes = {};
592
+ for (const feature of features) {
593
+ if (feature.properties) {
594
+ for (const key in feature.properties) {
595
+ const val = feature.properties[key];
596
+ propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
597
+ }
598
+ }
599
+ }
600
+ return propArrayTypes;
601
+ }
602
+ function fillArrays(features, geometryInfo, options) {
603
+ const {
604
+ pointPositionsCount,
605
+ pointFeaturesCount,
606
+ linePositionsCount,
607
+ linePathsCount,
608
+ lineFeaturesCount,
609
+ polygonPositionsCount,
610
+ polygonObjectsCount,
611
+ polygonRingsCount,
612
+ polygonFeaturesCount,
613
+ propArrayTypes,
614
+ coordLength
615
+ } = geometryInfo;
616
+ const { numericPropKeys = [], PositionDataType = Float32Array } = options;
617
+ const hasGlobalId = features[0] && "id" in features[0];
618
+ const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
619
+ const points = {
620
+ type: "Point",
621
+ positions: new PositionDataType(pointPositionsCount * coordLength),
622
+ globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
623
+ featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
624
+ numericProps: {},
625
+ properties: [],
626
+ fields: []
627
+ };
628
+ const lines = {
629
+ type: "LineString",
630
+ pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
631
+ positions: new PositionDataType(linePositionsCount * coordLength),
632
+ globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
633
+ featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
634
+ numericProps: {},
635
+ properties: [],
636
+ fields: []
637
+ };
638
+ const polygons = {
639
+ type: "Polygon",
640
+ polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
641
+ primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
642
+ positions: new PositionDataType(polygonPositionsCount * coordLength),
643
+ triangles: [],
644
+ globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
645
+ featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
646
+ numericProps: {},
647
+ properties: [],
648
+ fields: []
649
+ };
650
+ for (const object of [points, lines, polygons]) {
651
+ for (const propName of numericPropKeys) {
652
+ const T = propArrayTypes[propName];
653
+ object.numericProps[propName] = new T(object.positions.length / coordLength);
654
+ }
655
+ }
656
+ lines.pathIndices[linePathsCount] = linePositionsCount;
657
+ polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
658
+ polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
659
+ const indexMap = {
660
+ pointPosition: 0,
661
+ pointFeature: 0,
662
+ linePosition: 0,
663
+ linePath: 0,
664
+ lineFeature: 0,
665
+ polygonPosition: 0,
666
+ polygonObject: 0,
667
+ polygonRing: 0,
668
+ polygonFeature: 0,
669
+ feature: 0
670
+ };
671
+ for (const feature of features) {
672
+ const geometry = feature.geometry;
673
+ const properties = feature.properties || {};
674
+ switch (geometry.type) {
675
+ case "Point":
676
+ handlePoint(geometry, points, indexMap, coordLength, properties);
677
+ points.properties.push(keepStringProperties(properties, numericPropKeys));
678
+ if (hasGlobalId) {
679
+ points.fields.push({ id: feature.id });
680
+ }
681
+ indexMap.pointFeature++;
682
+ break;
683
+ case "LineString":
684
+ handleLineString(geometry, lines, indexMap, coordLength, properties);
685
+ lines.properties.push(keepStringProperties(properties, numericPropKeys));
686
+ if (hasGlobalId) {
687
+ lines.fields.push({ id: feature.id });
688
+ }
689
+ indexMap.lineFeature++;
690
+ break;
691
+ case "Polygon":
692
+ handlePolygon(geometry, polygons, indexMap, coordLength, properties);
693
+ polygons.properties.push(keepStringProperties(properties, numericPropKeys));
694
+ if (hasGlobalId) {
695
+ polygons.fields.push({ id: feature.id });
696
+ }
697
+ indexMap.polygonFeature++;
698
+ break;
699
+ default:
700
+ throw new Error("Invalid geometry type");
701
+ }
702
+ indexMap.feature++;
703
+ }
704
+ return makeAccessorObjects(points, lines, polygons, coordLength);
705
+ }
706
+ function handlePoint(geometry, points, indexMap, coordLength, properties) {
707
+ points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
708
+ const nPositions = geometry.data.length / coordLength;
709
+ fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
710
+ points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
711
+ points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
712
+ indexMap.pointPosition += nPositions;
713
+ }
714
+ function handleLineString(geometry, lines, indexMap, coordLength, properties) {
715
+ lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
716
+ const nPositions = geometry.data.length / coordLength;
717
+ fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
718
+ lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
719
+ lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
720
+ for (let i = 0, il = geometry.indices.length; i < il; ++i) {
721
+ const start = geometry.indices[i];
722
+ const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
723
+ lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
724
+ indexMap.linePosition += (end - start) / coordLength;
725
+ }
726
+ }
727
+ function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
728
+ polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
729
+ const nPositions = geometry.data.length / coordLength;
730
+ fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
731
+ polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
732
+ polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
733
+ for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
734
+ const startPosition = indexMap.polygonPosition;
735
+ polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
736
+ const areas = geometry.areas[l];
737
+ const indices = geometry.indices[l];
738
+ const nextIndices = geometry.indices[l + 1];
739
+ for (let i = 0, il = indices.length; i < il; ++i) {
740
+ const start = indices[i];
741
+ const end = i === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i + 1];
742
+ polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
743
+ indexMap.polygonPosition += (end - start) / coordLength;
744
+ }
745
+ const endPosition = indexMap.polygonPosition;
746
+ triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
747
+ }
748
+ }
749
+ function triangulatePolygon(polygons, areas, indices, {
750
+ startPosition,
751
+ endPosition,
752
+ coordLength
753
+ }) {
754
+ const start = startPosition * coordLength;
755
+ const end = endPosition * coordLength;
756
+ const polygonPositions = polygons.positions.subarray(start, end);
757
+ const offset = indices[0];
758
+ const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
759
+ const triangles = earcut(polygonPositions, holes, coordLength, areas);
760
+ for (let t = 0, tl = triangles.length; t < tl; ++t) {
761
+ polygons.triangles.push(startPosition + triangles[t]);
762
+ }
763
+ }
764
+ function wrapProps(obj, size) {
765
+ const returnObj = {};
766
+ for (const key in obj) {
767
+ returnObj[key] = { value: obj[key], size };
768
+ }
769
+ return returnObj;
770
+ }
771
+ function makeAccessorObjects(points, lines, polygons, coordLength) {
772
+ return {
773
+ points: {
774
+ ...points,
775
+ positions: { value: points.positions, size: coordLength },
776
+ globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
777
+ featureIds: { value: points.featureIds, size: 1 },
778
+ numericProps: wrapProps(points.numericProps, 1)
779
+ },
780
+ lines: {
781
+ ...lines,
782
+ positions: { value: lines.positions, size: coordLength },
783
+ pathIndices: { value: lines.pathIndices, size: 1 },
784
+ globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
785
+ featureIds: { value: lines.featureIds, size: 1 },
786
+ numericProps: wrapProps(lines.numericProps, 1)
787
+ },
788
+ polygons: {
789
+ ...polygons,
790
+ positions: { value: polygons.positions, size: coordLength },
791
+ polygonIndices: { value: polygons.polygonIndices, size: 1 },
792
+ primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
793
+ triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
794
+ globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
795
+ featureIds: { value: polygons.featureIds, size: 1 },
796
+ numericProps: wrapProps(polygons.numericProps, 1)
797
+ }
798
+ };
799
+ }
800
+ function fillNumericProperties(object, properties, index, length) {
801
+ for (const numericPropName in object.numericProps) {
802
+ if (numericPropName in properties) {
803
+ const value = properties[numericPropName];
804
+ object.numericProps[numericPropName].fill(value, index, index + length);
805
+ }
806
+ }
807
+ }
808
+ function keepStringProperties(properties, numericKeys) {
809
+ const props = {};
810
+ for (const key in properties) {
811
+ if (!numericKeys.includes(key)) {
812
+ props[key] = properties[key];
813
+ }
814
+ }
815
+ return props;
816
+ }
817
+ function deduceArrayType(x, constructor) {
818
+ if (constructor === Array || !Number.isFinite(x)) {
819
+ return Array;
820
+ }
821
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
822
+ }
823
+ var init_flat_geojson_to_binary = __esm({
824
+ "../gis/src/lib/flat-geojson-to-binary.ts"() {
825
+ init_esm();
826
+ }
827
+ });
828
+
829
+ // ../gis/src/lib/extract-geometry-info.ts
830
+ function extractGeometryInfo(features) {
831
+ let pointPositionsCount = 0;
832
+ let pointFeaturesCount = 0;
833
+ let linePositionsCount = 0;
834
+ let linePathsCount = 0;
835
+ let lineFeaturesCount = 0;
836
+ let polygonPositionsCount = 0;
837
+ let polygonObjectsCount = 0;
838
+ let polygonRingsCount = 0;
839
+ let polygonFeaturesCount = 0;
840
+ const coordLengths = new Set();
841
+ for (const feature of features) {
842
+ const geometry = feature.geometry;
843
+ switch (geometry.type) {
844
+ case "Point":
845
+ pointFeaturesCount++;
846
+ pointPositionsCount++;
847
+ coordLengths.add(geometry.coordinates.length);
848
+ break;
849
+ case "MultiPoint":
850
+ pointFeaturesCount++;
851
+ pointPositionsCount += geometry.coordinates.length;
852
+ for (const point of geometry.coordinates) {
853
+ coordLengths.add(point.length);
854
+ }
855
+ break;
856
+ case "LineString":
857
+ lineFeaturesCount++;
858
+ linePositionsCount += geometry.coordinates.length;
859
+ linePathsCount++;
860
+ for (const coord of geometry.coordinates) {
861
+ coordLengths.add(coord.length);
862
+ }
863
+ break;
864
+ case "MultiLineString":
865
+ lineFeaturesCount++;
866
+ for (const line of geometry.coordinates) {
867
+ linePositionsCount += line.length;
868
+ linePathsCount++;
869
+ for (const coord of line) {
870
+ coordLengths.add(coord.length);
871
+ }
872
+ }
873
+ break;
874
+ case "Polygon":
875
+ polygonFeaturesCount++;
876
+ polygonObjectsCount++;
877
+ polygonRingsCount += geometry.coordinates.length;
878
+ const flattened = geometry.coordinates.flat();
879
+ polygonPositionsCount += flattened.length;
880
+ for (const coord of flattened) {
881
+ coordLengths.add(coord.length);
882
+ }
883
+ break;
884
+ case "MultiPolygon":
885
+ polygonFeaturesCount++;
886
+ for (const polygon of geometry.coordinates) {
887
+ polygonObjectsCount++;
888
+ polygonRingsCount += polygon.length;
889
+ const flattened2 = polygon.flat();
890
+ polygonPositionsCount += flattened2.length;
891
+ for (const coord of flattened2) {
892
+ coordLengths.add(coord.length);
893
+ }
894
+ }
895
+ break;
896
+ default:
897
+ throw new Error(`Unsupported geometry type: ${geometry.type}`);
898
+ }
899
+ }
900
+ return {
901
+ coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
902
+ pointPositionsCount,
903
+ pointFeaturesCount,
904
+ linePositionsCount,
905
+ linePathsCount,
906
+ lineFeaturesCount,
907
+ polygonPositionsCount,
908
+ polygonObjectsCount,
909
+ polygonRingsCount,
910
+ polygonFeaturesCount
911
+ };
912
+ }
913
+ var init_extract_geometry_info = __esm({
914
+ "../gis/src/lib/extract-geometry-info.ts"() {
915
+ }
916
+ });
917
+
918
+ // ../gis/src/lib/geojson-to-flat-geojson.ts
919
+ function geojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
920
+ return features.map((feature) => flattenFeature(feature, options));
921
+ }
922
+ function flattenPoint(coordinates, data, indices, options) {
923
+ indices.push(data.length);
924
+ data.push(...coordinates);
925
+ for (let i = coordinates.length; i < options.coordLength; i++) {
926
+ data.push(0);
927
+ }
928
+ }
929
+ function flattenLineString(coordinates, data, indices, options) {
930
+ indices.push(data.length);
931
+ for (const c of coordinates) {
932
+ data.push(...c);
933
+ for (let i = c.length; i < options.coordLength; i++) {
934
+ data.push(0);
935
+ }
936
+ }
937
+ }
938
+ function flattenPolygon(coordinates, data, indices, areas, options) {
939
+ let count = 0;
940
+ const ringAreas = [];
941
+ const polygons = [];
942
+ for (const lineString of coordinates) {
943
+ const lineString2d = lineString.map((p) => p.slice(0, 2));
944
+ let area2 = getPolygonSignedArea(lineString2d.flat());
945
+ const ccw = area2 < 0;
946
+ if (options.fixRingWinding && (count === 0 && !ccw || count > 0 && ccw)) {
947
+ lineString.reverse();
948
+ area2 = -area2;
949
+ }
950
+ ringAreas.push(area2);
951
+ flattenLineString(lineString, data, polygons, options);
952
+ count++;
953
+ }
954
+ if (count > 0) {
955
+ areas.push(ringAreas);
956
+ indices.push(polygons);
957
+ }
958
+ }
959
+ function flattenFeature(feature, options) {
960
+ const { geometry } = feature;
961
+ if (geometry.type === "GeometryCollection") {
962
+ throw new Error("GeometryCollection type not supported");
963
+ }
964
+ const data = [];
965
+ const indices = [];
966
+ let areas;
967
+ let type;
968
+ switch (geometry.type) {
969
+ case "Point":
970
+ type = "Point";
971
+ flattenPoint(geometry.coordinates, data, indices, options);
972
+ break;
973
+ case "MultiPoint":
974
+ type = "Point";
975
+ geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));
976
+ break;
977
+ case "LineString":
978
+ type = "LineString";
979
+ flattenLineString(geometry.coordinates, data, indices, options);
980
+ break;
981
+ case "MultiLineString":
982
+ type = "LineString";
983
+ geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));
984
+ break;
985
+ case "Polygon":
986
+ type = "Polygon";
987
+ areas = [];
988
+ flattenPolygon(geometry.coordinates, data, indices, areas, options);
989
+ break;
990
+ case "MultiPolygon":
991
+ type = "Polygon";
992
+ areas = [];
993
+ geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));
994
+ break;
995
+ default:
996
+ throw new Error(`Unknown type: ${type}`);
997
+ }
998
+ return { ...feature, geometry: { type, indices, data, areas } };
999
+ }
1000
+ var init_geojson_to_flat_geojson = __esm({
1001
+ "../gis/src/lib/geojson-to-flat-geojson.ts"() {
1002
+ init_esm();
1003
+ }
1004
+ });
1005
+
1006
+ // ../gis/src/lib/geojson-to-binary.ts
1007
+ function geojsonToBinary(features, options = { fixRingWinding: true }) {
1008
+ const geometryInfo = extractGeometryInfo(features);
1009
+ const coordLength = geometryInfo.coordLength;
1010
+ const { fixRingWinding } = options;
1011
+ const flatFeatures = geojsonToFlatGeojson(features, { coordLength, fixRingWinding });
1012
+ return flatGeojsonToBinary(flatFeatures, geometryInfo, {
1013
+ numericPropKeys: options.numericPropKeys,
1014
+ PositionDataType: options.PositionDataType || Float32Array
1015
+ });
1016
+ }
1017
+ var init_geojson_to_binary = __esm({
1018
+ "../gis/src/lib/geojson-to-binary.ts"() {
1019
+ init_extract_geometry_info();
1020
+ init_geojson_to_flat_geojson();
1021
+ init_flat_geojson_to_binary();
1022
+ }
1023
+ });
1024
+
1025
+ // ../gis/src/index.ts
1026
+ var init_src = __esm({
1027
+ "../gis/src/index.ts"() {
1028
+ init_geojson_to_binary();
1029
+ }
1030
+ });
1031
+
1032
+ // ../../node_modules/@tmcw/togeojson/dist/togeojson.umd.js
1033
+ var require_togeojson_umd = __commonJS({
1034
+ "../../node_modules/@tmcw/togeojson/dist/togeojson.umd.js"(exports, module) {
1035
+ !function(e, t) {
1036
+ 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 = {});
1037
+ }(exports, function(e) {
1038
+ "use strict";
1039
+ function t(e2) {
1040
+ return e2 && e2.normalize && e2.normalize(), e2 && e2.textContent || "";
1041
+ }
1042
+ function n(e2, t2) {
1043
+ const n2 = e2.getElementsByTagName(t2);
1044
+ return n2.length ? n2[0] : null;
1045
+ }
1046
+ function o(e2) {
1047
+ const o2 = {};
1048
+ if (e2) {
1049
+ const s2 = n(e2, "line");
1050
+ if (s2) {
1051
+ const e3 = t(n(s2, "color")), r2 = parseFloat(t(n(s2, "opacity"))), i2 = parseFloat(t(n(s2, "width")));
1052
+ e3 && (o2.stroke = e3), isNaN(r2) || (o2["stroke-opacity"] = r2), isNaN(i2) || (o2["stroke-width"] = 96 * i2 / 25.4);
1053
+ }
1054
+ }
1055
+ return o2;
1056
+ }
1057
+ function s(e2, o2) {
1058
+ const s2 = {};
1059
+ let r2, i2;
1060
+ for (i2 = 0; i2 < o2.length; i2++)
1061
+ r2 = n(e2, o2[i2]), r2 && (s2[o2[i2]] = t(r2));
1062
+ return s2;
1063
+ }
1064
+ function r(e2) {
1065
+ const n2 = s(e2, ["name", "cmt", "desc", "type", "time", "keywords"]), o2 = e2.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/GpxExtensions/v3", "*");
1066
+ for (let s2 = 0; s2 < o2.length; s2++) {
1067
+ const r3 = o2[s2];
1068
+ r3.parentNode.parentNode === e2 && (n2[r3.tagName.replace(":", "_")] = t(r3));
1069
+ }
1070
+ const r2 = e2.getElementsByTagName("link");
1071
+ r2.length && (n2.links = []);
1072
+ for (let e3 = 0; e3 < r2.length; e3++)
1073
+ n2.links.push(Object.assign({ href: r2[e3].getAttribute("href") }, s(r2[e3], ["text", "type"])));
1074
+ return n2;
1075
+ }
1076
+ function i(e2) {
1077
+ 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");
1078
+ let l2;
1079
+ s2 && (l2 = parseFloat(t(s2)), isNaN(l2) || o2.push(l2));
1080
+ const a2 = { coordinates: o2, time: i2 ? t(i2) : null, extendedValues: [] };
1081
+ r2 && a2.extendedValues.push(["heart", parseFloat(t(r2))]);
1082
+ const c2 = n(e2, "extensions");
1083
+ if (c2 !== null)
1084
+ for (const e3 of ["speed", "course", "hAcc", "vAcc"]) {
1085
+ const o3 = parseFloat(t(n(c2, e3)));
1086
+ isNaN(o3) || a2.extendedValues.push([e3, o3]);
1087
+ }
1088
+ return a2;
1089
+ }
1090
+ function l(e2) {
1091
+ const t2 = a(e2, "rtept");
1092
+ if (t2)
1093
+ return { type: "Feature", properties: Object.assign(r(e2), o(n(e2, "extensions")), { _gpxType: "rte" }), geometry: { type: "LineString", coordinates: t2.line } };
1094
+ }
1095
+ function a(e2, t2) {
1096
+ const n2 = e2.getElementsByTagName(t2);
1097
+ if (n2.length < 2)
1098
+ return;
1099
+ const o2 = [], s2 = [], r2 = {};
1100
+ for (let e3 = 0; e3 < n2.length; e3++) {
1101
+ const t3 = i(n2[e3]);
1102
+ o2.push(t3.coordinates), t3.time && s2.push(t3.time);
1103
+ for (let o3 = 0; o3 < t3.extendedValues.length; o3++) {
1104
+ const [s3, i2] = t3.extendedValues[o3], l2 = s3 === "heart" ? s3 : s3 + "s";
1105
+ r2[l2] || (r2[l2] = Array(n2.length).fill(null)), r2[l2][e3] = i2;
1106
+ }
1107
+ }
1108
+ return { line: o2, times: s2, extendedValues: r2 };
1109
+ }
1110
+ function c(e2) {
1111
+ const t2 = e2.getElementsByTagName("trkseg"), s2 = [], i2 = [], l2 = [];
1112
+ for (let e3 = 0; e3 < t2.length; e3++) {
1113
+ const n2 = a(t2[e3], "trkpt");
1114
+ n2 && (l2.push(n2), n2.times && n2.times.length && i2.push(n2.times));
1115
+ }
1116
+ if (l2.length === 0)
1117
+ return;
1118
+ const c2 = l2.length > 1, g2 = Object.assign(r(e2), o(n(e2, "extensions")), { _gpxType: "trk" }, i2.length ? { coordinateProperties: { times: c2 ? i2 : i2[0] } } : {});
1119
+ for (let e3 = 0; e3 < l2.length; e3++) {
1120
+ const t3 = l2[e3];
1121
+ s2.push(t3.line);
1122
+ for (const [n2, o2] of Object.entries(t3.extendedValues)) {
1123
+ let t4 = g2;
1124
+ 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;
1125
+ }
1126
+ }
1127
+ return { type: "Feature", properties: g2, geometry: c2 ? { type: "MultiLineString", coordinates: s2 } : { type: "LineString", coordinates: s2[0] } };
1128
+ }
1129
+ function* g(e2) {
1130
+ const t2 = e2.getElementsByTagName("trk"), n2 = e2.getElementsByTagName("rte"), o2 = e2.getElementsByTagName("wpt");
1131
+ for (let e3 = 0; e3 < t2.length; e3++) {
1132
+ const n3 = c(t2[e3]);
1133
+ n3 && (yield n3);
1134
+ }
1135
+ for (let e3 = 0; e3 < n2.length; e3++) {
1136
+ const t3 = l(n2[e3]);
1137
+ t3 && (yield t3);
1138
+ }
1139
+ for (let e3 = 0; e3 < o2.length; e3++)
1140
+ yield (a2 = o2[e3], { type: "Feature", properties: Object.assign(r(a2), s(a2, ["sym"])), geometry: { type: "Point", coordinates: i(a2).coordinates } });
1141
+ var a2;
1142
+ }
1143
+ 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"]];
1144
+ function p(e2, o2) {
1145
+ const s2 = [];
1146
+ for (const [r2, i2] of o2) {
1147
+ let o3 = n(e2, r2);
1148
+ if (!o3) {
1149
+ const t2 = e2.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/ActivityExtension/v2", r2);
1150
+ t2.length && (o3 = t2[0]);
1151
+ }
1152
+ const l2 = parseFloat(t(o3));
1153
+ isNaN(l2) || s2.push([i2, l2]);
1154
+ }
1155
+ return s2;
1156
+ }
1157
+ function h(e2) {
1158
+ const o2 = t(n(e2, "LongitudeDegrees")), s2 = t(n(e2, "LatitudeDegrees"));
1159
+ if (!o2.length || !s2.length)
1160
+ return null;
1161
+ const r2 = [parseFloat(o2), parseFloat(s2)], i2 = n(e2, "AltitudeMeters"), l2 = n(e2, "HeartRateBpm"), a2 = n(e2, "Time");
1162
+ let c2;
1163
+ 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) };
1164
+ }
1165
+ function f(e2, t2) {
1166
+ const n2 = e2.getElementsByTagName(t2), o2 = [], s2 = [], r2 = [];
1167
+ if (n2.length < 2)
1168
+ return null;
1169
+ const i2 = { extendedProperties: {} };
1170
+ for (let e3 = 0; e3 < n2.length; e3++) {
1171
+ const t3 = h(n2[e3]);
1172
+ if (t3 !== null) {
1173
+ o2.push(t3.coordinates), t3.time && s2.push(t3.time), t3.heartRate && r2.push(t3.heartRate);
1174
+ for (const [o3, s3] of t3.extensions)
1175
+ i2.extendedProperties[o3] || (i2.extendedProperties[o3] = Array(n2.length).fill(null)), i2.extendedProperties[o3][e3] = s3;
1176
+ }
1177
+ }
1178
+ return Object.assign(i2, { line: o2, times: s2, heartRates: r2 });
1179
+ }
1180
+ function d(e2) {
1181
+ const o2 = e2.getElementsByTagName("Track"), s2 = [], r2 = [], i2 = [], l2 = [];
1182
+ let a2;
1183
+ const c2 = function(e3) {
1184
+ const t2 = {};
1185
+ for (const [n2, o3] of e3)
1186
+ t2[n2] = o3;
1187
+ return t2;
1188
+ }(p(e2, m)), g2 = n(e2, "Name");
1189
+ g2 && (c2.name = t(g2));
1190
+ for (let e3 = 0; e3 < o2.length; e3++)
1191
+ 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));
1192
+ for (let e3 = 0; e3 < l2.length; e3++) {
1193
+ const t2 = l2[e3];
1194
+ for (const n2 in t2)
1195
+ 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]);
1196
+ }
1197
+ if (s2.length !== 0)
1198
+ 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 } };
1199
+ }
1200
+ function* y(e2) {
1201
+ const t2 = e2.getElementsByTagName("Lap");
1202
+ for (let e3 = 0; e3 < t2.length; e3++) {
1203
+ const n3 = d(t2[e3]);
1204
+ n3 && (yield n3);
1205
+ }
1206
+ const n2 = e2.getElementsByTagName("Courses");
1207
+ for (let e3 = 0; e3 < n2.length; e3++) {
1208
+ const t3 = d(n2[e3]);
1209
+ t3 && (yield t3);
1210
+ }
1211
+ }
1212
+ const N = /\s*/g, x = /^\s*|\s*$/g, T = /\s+/;
1213
+ function b(e2) {
1214
+ if (!e2 || !e2.length)
1215
+ return 0;
1216
+ let t2 = 0;
1217
+ for (let n2 = 0; n2 < e2.length; n2++)
1218
+ t2 = (t2 << 5) - t2 + e2.charCodeAt(n2) | 0;
1219
+ return t2;
1220
+ }
1221
+ function S(e2) {
1222
+ return e2.replace(N, "").split(",").map(parseFloat);
1223
+ }
1224
+ function k(e2) {
1225
+ return e2.replace(x, "").split(T).map(S);
1226
+ }
1227
+ function A(e2) {
1228
+ if (e2.xml !== void 0)
1229
+ return e2.xml;
1230
+ if (e2.tagName) {
1231
+ let t2 = e2.tagName;
1232
+ for (let n2 = 0; n2 < e2.attributes.length; n2++)
1233
+ t2 += e2.attributes[n2].name + e2.attributes[n2].value;
1234
+ for (let n2 = 0; n2 < e2.childNodes.length; n2++)
1235
+ t2 += A(e2.childNodes[n2]);
1236
+ return t2;
1237
+ }
1238
+ return e2.nodeName === "#text" ? (e2.nodeValue || e2.value || "").trim() : e2.nodeName === "#cdata-section" ? e2.nodeValue : "";
1239
+ }
1240
+ const B = ["Polygon", "LineString", "Point", "Track", "gx:Track"];
1241
+ function E(e2, o2, s2) {
1242
+ let r2 = t(n(o2, "color")) || "";
1243
+ const i2 = s2 == "stroke" || s2 === "fill" ? s2 : s2 + "-color";
1244
+ 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));
1245
+ }
1246
+ function F(e2, o2, s2, r2) {
1247
+ const i2 = parseFloat(t(n(o2, s2)));
1248
+ isNaN(i2) || (e2[r2] = i2);
1249
+ }
1250
+ function P(e2) {
1251
+ let n2 = e2.getElementsByTagName("coord");
1252
+ const o2 = [], s2 = [];
1253
+ n2.length === 0 && (n2 = e2.getElementsByTagName("gx:coord"));
1254
+ for (let e3 = 0; e3 < n2.length; e3++)
1255
+ o2.push(t(n2[e3]).split(" ").map(parseFloat));
1256
+ const r2 = e2.getElementsByTagName("when");
1257
+ for (let e3 = 0; e3 < r2.length; e3++)
1258
+ s2.push(t(r2[e3]));
1259
+ return { coords: o2, times: s2 };
1260
+ }
1261
+ function v(e2) {
1262
+ let o2, s2, r2, i2, l2;
1263
+ const a2 = [], c2 = [];
1264
+ if (n(e2, "MultiGeometry"))
1265
+ return v(n(e2, "MultiGeometry"));
1266
+ if (n(e2, "MultiTrack"))
1267
+ return v(n(e2, "MultiTrack"));
1268
+ if (n(e2, "gx:MultiTrack"))
1269
+ return v(n(e2, "gx:MultiTrack"));
1270
+ for (r2 = 0; r2 < B.length; r2++)
1271
+ if (s2 = e2.getElementsByTagName(B[r2]), s2) {
1272
+ for (i2 = 0; i2 < s2.length; i2++)
1273
+ if (o2 = s2[i2], B[r2] === "Point")
1274
+ a2.push({ type: "Point", coordinates: S(t(n(o2, "coordinates"))) });
1275
+ else if (B[r2] === "LineString")
1276
+ a2.push({ type: "LineString", coordinates: k(t(n(o2, "coordinates"))) });
1277
+ else if (B[r2] === "Polygon") {
1278
+ const e3 = o2.getElementsByTagName("LinearRing"), s3 = [];
1279
+ for (l2 = 0; l2 < e3.length; l2++)
1280
+ s3.push(k(t(n(e3[l2], "coordinates"))));
1281
+ a2.push({ type: "Polygon", coordinates: s3 });
1282
+ } else if (B[r2] === "Track" || B[r2] === "gx:Track") {
1283
+ const e3 = P(o2);
1284
+ a2.push({ type: "LineString", coordinates: e3.coords }), e3.times.length && c2.push(e3.times);
1285
+ }
1286
+ }
1287
+ return { geoms: a2, coordTimes: c2 };
1288
+ }
1289
+ function L(e2, o2, s2, r2) {
1290
+ const i2 = v(e2);
1291
+ let l2;
1292
+ const a2 = {}, c2 = t(n(e2, "name")), g2 = t(n(e2, "address"));
1293
+ let u2 = t(n(e2, "styleUrl"));
1294
+ const m2 = t(n(e2, "description")), p2 = n(e2, "TimeSpan"), h2 = n(e2, "TimeStamp"), f2 = n(e2, "ExtendedData");
1295
+ let d2 = n(e2, "IconStyle"), y2 = n(e2, "LabelStyle"), N2 = n(e2, "LineStyle"), x2 = n(e2, "PolyStyle");
1296
+ const T2 = n(e2, "visibility");
1297
+ if (c2 && (a2.name = c2), g2 && (a2.address = g2), u2) {
1298
+ 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]);
1299
+ const e3 = r2[a2.styleHash];
1300
+ e3 && (d2 || (d2 = n(e3, "IconStyle")), y2 || (y2 = n(e3, "LabelStyle")), N2 || (N2 = n(e3, "LineStyle")), x2 || (x2 = n(e3, "PolyStyle")));
1301
+ }
1302
+ if (m2 && (a2.description = m2), p2) {
1303
+ const e3 = t(n(p2, "begin")), o3 = t(n(p2, "end"));
1304
+ a2.timespan = { begin: e3, end: o3 };
1305
+ }
1306
+ if (h2 && (a2.timestamp = t(n(h2, "when"))), d2) {
1307
+ E(a2, d2, "icon"), F(a2, d2, "scale", "icon-scale"), F(a2, d2, "heading", "icon-heading");
1308
+ const e3 = n(d2, "hotSpot");
1309
+ if (e3) {
1310
+ const t2 = parseFloat(e3.getAttribute("x")), n2 = parseFloat(e3.getAttribute("y"));
1311
+ isNaN(t2) || isNaN(n2) || (a2["icon-offset"] = [t2, n2]);
1312
+ }
1313
+ const o3 = n(d2, "Icon");
1314
+ if (o3) {
1315
+ const e4 = t(n(o3, "href"));
1316
+ e4 && (a2.icon = e4);
1317
+ }
1318
+ }
1319
+ if (y2 && (E(a2, y2, "label"), F(a2, y2, "scale", "label-scale")), N2 && (E(a2, N2, "stroke"), F(a2, N2, "width", "stroke-width")), x2) {
1320
+ E(a2, x2, "fill");
1321
+ const e3 = t(n(x2, "fill")), o3 = t(n(x2, "outline"));
1322
+ e3 && (a2["fill-opacity"] = e3 === "1" ? a2["fill-opacity"] || 1 : 0), o3 && (a2["stroke-opacity"] = o3 === "1" ? a2["stroke-opacity"] || 1 : 0);
1323
+ }
1324
+ if (f2) {
1325
+ const e3 = f2.getElementsByTagName("Data"), o3 = f2.getElementsByTagName("SimpleData");
1326
+ for (l2 = 0; l2 < e3.length; l2++)
1327
+ a2[e3[l2].getAttribute("name")] = t(n(e3[l2], "value"));
1328
+ for (l2 = 0; l2 < o3.length; l2++)
1329
+ a2[o3[l2].getAttribute("name")] = t(o3[l2]);
1330
+ }
1331
+ T2 && (a2.visibility = t(T2)), i2.coordTimes.length && (a2.coordinateProperties = { times: i2.coordTimes.length === 1 ? i2.coordTimes[0] : i2.coordTimes });
1332
+ const b2 = { type: "Feature", geometry: i2.geoms.length === 0 ? null : i2.geoms.length === 1 ? i2.geoms[0] : { type: "GeometryCollection", geometries: i2.geoms }, properties: a2 };
1333
+ return e2.getAttribute("id") && (b2.id = e2.getAttribute("id")), b2;
1334
+ }
1335
+ function* M(e2) {
1336
+ const o2 = {}, s2 = {}, r2 = {}, i2 = e2.getElementsByTagName("Placemark"), l2 = e2.getElementsByTagName("Style"), a2 = e2.getElementsByTagName("StyleMap");
1337
+ for (let e3 = 0; e3 < l2.length; e3++) {
1338
+ const t2 = b(A(l2[e3])).toString(16);
1339
+ o2["#" + l2[e3].getAttribute("id")] = t2, s2[t2] = l2[e3];
1340
+ }
1341
+ for (let e3 = 0; e3 < a2.length; e3++) {
1342
+ o2["#" + a2[e3].getAttribute("id")] = b(A(a2[e3])).toString(16);
1343
+ const s3 = a2[e3].getElementsByTagName("Pair"), i3 = {};
1344
+ for (let e4 = 0; e4 < s3.length; e4++)
1345
+ i3[t(n(s3[e4], "key"))] = t(n(s3[e4], "styleUrl"));
1346
+ r2["#" + a2[e3].getAttribute("id")] = i3;
1347
+ }
1348
+ for (let e3 = 0; e3 < i2.length; e3++) {
1349
+ const t2 = L(i2[e3], o2, r2, s2);
1350
+ t2 && (yield t2);
1351
+ }
1352
+ }
1353
+ e.gpx = function(e2) {
1354
+ return { type: "FeatureCollection", features: Array.from(g(e2)) };
1355
+ }, e.gpxGen = g, e.kml = function(e2) {
1356
+ return { type: "FeatureCollection", features: Array.from(M(e2)) };
1357
+ }, e.kmlGen = M, e.tcx = function(e2) {
1358
+ return { type: "FeatureCollection", features: Array.from(y(e2)) };
1359
+ }, e.tcxGen = y, Object.defineProperty(e, "__esModule", { value: true });
1360
+ });
1361
+ }
1362
+ });
1363
+
1364
+ // src/gpx-loader.ts
1365
+ function parseTextSync(text, options) {
1366
+ const doc = new DOMParser().parseFromString(text, "text/xml");
1367
+ const geojson = (0, import_togeojson.gpx)(doc);
1368
+ switch (options?.gpx?.type) {
1369
+ case "object-row-table":
1370
+ return geojson.features;
1371
+ default:
1372
+ }
1373
+ switch (options?.gis?.format) {
1374
+ case "geojson":
1375
+ return geojson;
1376
+ case "binary":
1377
+ return geojsonToBinary(geojson.features);
1378
+ case "raw":
1379
+ return doc;
1380
+ default:
1381
+ throw new Error();
1382
+ }
1383
+ }
1384
+ var import_togeojson, VERSION, GPX_HEADER, GPXLoader;
1385
+ var init_gpx_loader = __esm({
1386
+ "src/gpx-loader.ts"() {
1387
+ init_src();
1388
+ import_togeojson = __toModule(require_togeojson_umd());
1389
+ VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1390
+ GPX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1391
+ <gpx`;
1392
+ GPXLoader = {
1393
+ name: "GPX (GPS exchange format)",
1394
+ id: "gpx",
1395
+ module: "kml",
1396
+ version: VERSION,
1397
+ extensions: ["gpx"],
1398
+ mimeTypes: ["application/gpx+xml"],
1399
+ text: true,
1400
+ tests: [GPX_HEADER],
1401
+ parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
1402
+ parseTextSync,
1403
+ options: {
1404
+ gpx: {},
1405
+ gis: { format: "geojson" }
1406
+ }
1407
+ };
1408
+ }
1409
+ });
1410
+
1411
+ // src/kml-loader.ts
1412
+ function parseTextSync2(text, options) {
1413
+ const doc = new DOMParser().parseFromString(text, "text/xml");
1414
+ const geojson = (0, import_togeojson2.kml)(doc);
1415
+ switch (options?.kml?.type) {
1416
+ case "object-row-table":
1417
+ return geojson.features;
1418
+ default:
1419
+ }
1420
+ switch (options?.gis?.format) {
1421
+ case "geojson":
1422
+ return geojson;
1423
+ case "binary":
1424
+ return geojsonToBinary(geojson.features);
1425
+ case "raw":
1426
+ return doc;
1427
+ default:
1428
+ throw new Error();
1429
+ }
1430
+ }
1431
+ var import_togeojson2, VERSION2, KML_HEADER, KMLLoader;
1432
+ var init_kml_loader = __esm({
1433
+ "src/kml-loader.ts"() {
1434
+ init_src();
1435
+ import_togeojson2 = __toModule(require_togeojson_umd());
1436
+ VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1437
+ KML_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1438
+ <kml xmlns="http://www.opengis.net/kml/2.2">`;
1439
+ KMLLoader = {
1440
+ name: "KML (Keyhole Markup Language)",
1441
+ id: "kml",
1442
+ module: "kml",
1443
+ version: VERSION2,
1444
+ extensions: ["kml"],
1445
+ mimeTypes: ["application/vnd.google-earth.kml+xml"],
1446
+ text: true,
1447
+ tests: [KML_HEADER],
1448
+ parse: async (arrayBuffer, options) => parseTextSync2(new TextDecoder().decode(arrayBuffer), options),
1449
+ parseTextSync: parseTextSync2,
1450
+ options: {
1451
+ kml: {},
1452
+ gis: { format: "geojson" }
1453
+ }
1454
+ };
1455
+ }
1456
+ });
1457
+
1458
+ // src/tcx-loader.ts
1459
+ function parseTextSync3(text, options = {}) {
1460
+ const doc = new DOMParser().parseFromString(text, "text/xml");
1461
+ const geojson = (0, import_togeojson3.tcx)(doc);
1462
+ switch (options?.tcx?.type) {
1463
+ case "object-row-table":
1464
+ return geojson.features;
1465
+ default:
1466
+ }
1467
+ switch (options?.gis?.format) {
1468
+ case "geojson":
1469
+ return geojson;
1470
+ case "binary":
1471
+ return geojsonToBinary(geojson.features);
1472
+ case "raw":
1473
+ return doc;
1474
+ default:
1475
+ throw new Error();
1476
+ }
1477
+ }
1478
+ var import_togeojson3, VERSION3, TCX_HEADER, TCXLoader;
1479
+ var init_tcx_loader = __esm({
1480
+ "src/tcx-loader.ts"() {
1481
+ init_src();
1482
+ import_togeojson3 = __toModule(require_togeojson_umd());
1483
+ VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1484
+ TCX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1485
+ <TrainingCenterDatabase`;
1486
+ TCXLoader = {
1487
+ name: "TCX (Training Center XML)",
1488
+ id: "tcx",
1489
+ module: "kml",
1490
+ version: VERSION3,
1491
+ extensions: ["tcx"],
1492
+ mimeTypes: ["application/vnd.garmin.tcx+xml"],
1493
+ text: true,
1494
+ tests: [TCX_HEADER],
1495
+ parse: async (arrayBuffer, options) => parseTextSync3(new TextDecoder().decode(arrayBuffer), options),
1496
+ parseTextSync: parseTextSync3,
1497
+ options: {
1498
+ tcx: {},
1499
+ gis: { format: "geojson" }
1500
+ }
1501
+ };
1502
+ }
1503
+ });
1504
+
1505
+ // src/index.ts
1506
+ var src_exports = {};
1507
+ __export(src_exports, {
1508
+ GPXLoader: () => GPXLoader,
1509
+ KMLLoader: () => KMLLoader,
1510
+ TCXLoader: () => TCXLoader
1511
+ });
1512
+ var init_src2 = __esm({
1513
+ "src/index.ts"() {
1514
+ init_gpx_loader();
1515
+ init_kml_loader();
1516
+ init_tcx_loader();
1517
+ }
1518
+ });
1519
+
1520
+ // src/bundle.ts
1521
+ var require_bundle = __commonJS({
1522
+ "src/bundle.ts"(exports, module) {
1523
+ var moduleExports = (init_src2(), src_exports);
1524
+ globalThis.loaders = globalThis.loaders || {};
1525
+ module.exports = Object.assign(globalThis.loaders, moduleExports);
1526
+ }
1527
+ });
1528
+ require_bundle();
1529
+ })();