@loaders.gl/kml 4.0.0-alpha.5 → 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 (41) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +782 -385
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/gpx-loader.js +81 -0
  6. package/dist/es5/gpx-loader.js.map +1 -0
  7. package/dist/es5/index.js +27 -0
  8. package/dist/es5/index.js.map +1 -0
  9. package/dist/es5/kml-loader.js +81 -0
  10. package/dist/es5/kml-loader.js.map +1 -0
  11. package/dist/es5/tcx-loader.js +81 -0
  12. package/dist/es5/tcx-loader.js.map +1 -0
  13. package/dist/esm/bundle.js +4 -0
  14. package/dist/esm/bundle.js.map +1 -0
  15. package/dist/esm/gpx-loader.js +54 -0
  16. package/dist/esm/gpx-loader.js.map +1 -0
  17. package/dist/esm/index.js +4 -0
  18. package/dist/esm/index.js.map +1 -0
  19. package/dist/esm/kml-loader.js +54 -0
  20. package/dist/esm/kml-loader.js.map +1 -0
  21. package/dist/esm/tcx-loader.js +54 -0
  22. package/dist/esm/tcx-loader.js.map +1 -0
  23. package/dist/gpx-loader.d.ts +16 -26
  24. package/dist/gpx-loader.d.ts.map +1 -1
  25. package/dist/gpx-loader.js +57 -49
  26. package/dist/index.js +9 -4
  27. package/dist/kml-loader.d.ts +14 -7
  28. package/dist/kml-loader.d.ts.map +1 -1
  29. package/dist/kml-loader.js +58 -49
  30. package/dist/tcx-loader.d.ts +14 -7
  31. package/dist/tcx-loader.d.ts.map +1 -1
  32. package/dist/tcx-loader.js +59 -50
  33. package/package.json +7 -7
  34. package/src/gpx-loader.ts +34 -14
  35. package/src/kml-loader.ts +33 -13
  36. package/src/tcx-loader.ts +33 -12
  37. package/dist/bundle.js.map +0 -1
  38. package/dist/gpx-loader.js.map +0 -1
  39. package/dist/index.js.map +0 -1
  40. package/dist/kml-loader.js.map +0 -1
  41. package/dist/tcx-loader.js.map +0 -1
package/dist/dist.min.js CHANGED
@@ -1,10 +1,5 @@
1
1
  (() => {
2
- var __create = Object.create;
3
2
  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
3
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
9
4
  var __esm = (fn, res) => function __init() {
10
5
  return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
@@ -17,17 +12,34 @@
17
12
  for (var name in all)
18
13
  __defProp(target, name, { get: all[name], enumerable: true });
19
14
  };
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 });
15
+
16
+ // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
17
+ var init_typeof = __esm({
18
+ "../../node_modules/@babel/runtime/helpers/esm/typeof.js"() {
25
19
  }
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
- };
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
+ });
31
43
 
32
44
  // ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
33
45
  function getPolygonSignedArea(points, options = {}) {
@@ -51,16 +63,16 @@
51
63
  // ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
52
64
  var init_polygon = __esm({
53
65
  "../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
66
+ init_defineProperty();
54
67
  init_polygon_utils();
55
68
  }
56
69
  });
57
70
 
58
71
  // ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
59
- function earcut(data, holeIndices, dim, areas) {
60
- dim = dim || 2;
72
+ function earcut(positions, holeIndices, dim = 2, areas) {
61
73
  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]);
74
+ const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
75
+ let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0]);
64
76
  const triangles = [];
65
77
  if (!outerNode || outerNode.next === outerNode.prev)
66
78
  return triangles;
@@ -72,13 +84,13 @@
72
84
  let x;
73
85
  let y;
74
86
  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];
87
+ outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas);
88
+ if (positions.length > 80 * dim) {
89
+ minX = maxX = positions[0];
90
+ minY = maxY = positions[1];
79
91
  for (let i = dim; i < outerLen; i += dim) {
80
- x = data[i];
81
- y = data[i + 1];
92
+ x = positions[i];
93
+ y = positions[i + 1];
82
94
  if (x < minX)
83
95
  minX = x;
84
96
  if (y < minY)
@@ -857,8 +869,8 @@
857
869
  lineFeaturesCount++;
858
870
  linePositionsCount += geometry.coordinates.length;
859
871
  linePathsCount++;
860
- for (const coord of geometry.coordinates) {
861
- coordLengths.add(coord.length);
872
+ for (const coord2 of geometry.coordinates) {
873
+ coordLengths.add(coord2.length);
862
874
  }
863
875
  break;
864
876
  case "MultiLineString":
@@ -866,8 +878,8 @@
866
878
  for (const line of geometry.coordinates) {
867
879
  linePositionsCount += line.length;
868
880
  linePathsCount++;
869
- for (const coord of line) {
870
- coordLengths.add(coord.length);
881
+ for (const coord2 of line) {
882
+ coordLengths.add(coord2.length);
871
883
  }
872
884
  }
873
885
  break;
@@ -877,8 +889,8 @@
877
889
  polygonRingsCount += geometry.coordinates.length;
878
890
  const flattened = geometry.coordinates.flat();
879
891
  polygonPositionsCount += flattened.length;
880
- for (const coord of flattened) {
881
- coordLengths.add(coord.length);
892
+ for (const coord2 of flattened) {
893
+ coordLengths.add(coord2.length);
882
894
  }
883
895
  break;
884
896
  case "MultiPolygon":
@@ -888,8 +900,8 @@
888
900
  polygonRingsCount += polygon.length;
889
901
  const flattened2 = polygon.flat();
890
902
  polygonPositionsCount += flattened2.length;
891
- for (const coord of flattened2) {
892
- coordLengths.add(coord.length);
903
+ for (const coord2 of flattened2) {
904
+ coordLengths.add(coord2.length);
893
905
  }
894
906
  }
895
907
  break;
@@ -1029,348 +1041,713 @@
1029
1041
  }
1030
1042
  });
1031
1043
 
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 });
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)]);
1179
1084
  }
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 } };
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);
1199
1173
  }
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
- }
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 = {};
1211
1210
  }
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;
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;
1220
1218
  }
1221
- function S(e2) {
1222
- return e2.replace(N, "").split(",").map(parseFloat);
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];
1223
1282
  }
1224
- function k(e2) {
1225
- return e2.replace(x, "").split(T).map(S);
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);
1226
1335
  }
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;
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));
1237
1376
  }
1238
- return e2.nodeName === "#text" ? (e2.nodeValue || e2.value || "").trim() : e2.nodeName === "#cdata-section" ? e2.nodeValue : "";
1377
+ properties[property][i] = extendedProperties[property];
1239
1378
  }
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);
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"))));
1317
1526
  }
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);
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);
1351
1539
  }
1352
1540
  }
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
- });
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"];
1361
1728
  }
1362
1729
  });
1363
1730
 
1364
1731
  // src/gpx-loader.ts
1365
1732
  function parseTextSync(text, options) {
1366
1733
  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) {
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
+ }
1374
1751
  case "geojson":
1375
1752
  return geojson;
1376
1753
  case "binary":
@@ -1378,14 +1755,14 @@
1378
1755
  case "raw":
1379
1756
  return doc;
1380
1757
  default:
1381
- throw new Error();
1758
+ return geojson;
1382
1759
  }
1383
1760
  }
1384
- var import_togeojson, VERSION, GPX_HEADER, GPXLoader;
1761
+ var VERSION, GPX_HEADER, GPXLoader;
1385
1762
  var init_gpx_loader = __esm({
1386
1763
  "src/gpx-loader.ts"() {
1387
1764
  init_src();
1388
- import_togeojson = __toModule(require_togeojson_umd());
1765
+ init_togeojson_es();
1389
1766
  VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1390
1767
  GPX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1391
1768
  <gpx`;
@@ -1402,7 +1779,7 @@
1402
1779
  parseTextSync,
1403
1780
  options: {
1404
1781
  gpx: {},
1405
- gis: { format: "geojson" }
1782
+ gis: {}
1406
1783
  }
1407
1784
  };
1408
1785
  }
@@ -1411,13 +1788,23 @@
1411
1788
  // src/kml-loader.ts
1412
1789
  function parseTextSync2(text, options) {
1413
1790
  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) {
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
+ }
1421
1808
  case "geojson":
1422
1809
  return geojson;
1423
1810
  case "binary":
@@ -1425,14 +1812,14 @@
1425
1812
  case "raw":
1426
1813
  return doc;
1427
1814
  default:
1428
- throw new Error();
1815
+ return geojson;
1429
1816
  }
1430
1817
  }
1431
- var import_togeojson2, VERSION2, KML_HEADER, KMLLoader;
1818
+ var VERSION2, KML_HEADER, KMLLoader;
1432
1819
  var init_kml_loader = __esm({
1433
1820
  "src/kml-loader.ts"() {
1434
1821
  init_src();
1435
- import_togeojson2 = __toModule(require_togeojson_umd());
1822
+ init_togeojson_es();
1436
1823
  VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1437
1824
  KML_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1438
1825
  <kml xmlns="http://www.opengis.net/kml/2.2">`;
@@ -1449,22 +1836,32 @@
1449
1836
  parseTextSync: parseTextSync2,
1450
1837
  options: {
1451
1838
  kml: {},
1452
- gis: { format: "geojson" }
1839
+ gis: {}
1453
1840
  }
1454
1841
  };
1455
1842
  }
1456
1843
  });
1457
1844
 
1458
1845
  // src/tcx-loader.ts
1459
- function parseTextSync3(text, options = {}) {
1846
+ function parseTextSync3(text, options) {
1460
1847
  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) {
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
+ }
1468
1865
  case "geojson":
1469
1866
  return geojson;
1470
1867
  case "binary":
@@ -1472,14 +1869,14 @@
1472
1869
  case "raw":
1473
1870
  return doc;
1474
1871
  default:
1475
- throw new Error();
1872
+ return geojson;
1476
1873
  }
1477
1874
  }
1478
- var import_togeojson3, VERSION3, TCX_HEADER, TCXLoader;
1875
+ var VERSION3, TCX_HEADER, TCXLoader;
1479
1876
  var init_tcx_loader = __esm({
1480
1877
  "src/tcx-loader.ts"() {
1481
1878
  init_src();
1482
- import_togeojson3 = __toModule(require_togeojson_umd());
1879
+ init_togeojson_es();
1483
1880
  VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1484
1881
  TCX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1485
1882
  <TrainingCenterDatabase`;
@@ -1496,7 +1893,7 @@
1496
1893
  parseTextSync: parseTextSync3,
1497
1894
  options: {
1498
1895
  tcx: {},
1499
- gis: { format: "geojson" }
1896
+ gis: {}
1500
1897
  }
1501
1898
  };
1502
1899
  }