@loaders.gl/kml 3.3.0-alpha.1 → 3.3.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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,12 @@
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/defineProperty.js
17
+ var init_defineProperty = __esm({
18
+ "../../node_modules/@babel/runtime/helpers/esm/defineProperty.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
+ });
31
21
 
32
22
  // ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
33
23
  function getPolygonSignedArea(points, options = {}) {
@@ -51,16 +41,16 @@
51
41
  // ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
52
42
  var init_polygon = __esm({
53
43
  "../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
44
+ init_defineProperty();
54
45
  init_polygon_utils();
55
46
  }
56
47
  });
57
48
 
58
49
  // ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
59
- function earcut(data, holeIndices, dim, areas) {
60
- dim = dim || 2;
50
+ function earcut(positions, holeIndices, dim = 2, areas) {
61
51
  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]);
52
+ const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
53
+ let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0]);
64
54
  const triangles = [];
65
55
  if (!outerNode || outerNode.next === outerNode.prev)
66
56
  return triangles;
@@ -72,13 +62,13 @@
72
62
  let x;
73
63
  let y;
74
64
  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];
65
+ outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas);
66
+ if (positions.length > 80 * dim) {
67
+ minX = maxX = positions[0];
68
+ minY = maxY = positions[1];
79
69
  for (let i = dim; i < outerLen; i += dim) {
80
- x = data[i];
81
- y = data[i + 1];
70
+ x = positions[i];
71
+ y = positions[i + 1];
82
72
  if (x < minX)
83
73
  minX = x;
84
74
  if (y < minY)
@@ -857,8 +847,8 @@
857
847
  lineFeaturesCount++;
858
848
  linePositionsCount += geometry.coordinates.length;
859
849
  linePathsCount++;
860
- for (const coord of geometry.coordinates) {
861
- coordLengths.add(coord.length);
850
+ for (const coord2 of geometry.coordinates) {
851
+ coordLengths.add(coord2.length);
862
852
  }
863
853
  break;
864
854
  case "MultiLineString":
@@ -866,8 +856,8 @@
866
856
  for (const line of geometry.coordinates) {
867
857
  linePositionsCount += line.length;
868
858
  linePathsCount++;
869
- for (const coord of line) {
870
- coordLengths.add(coord.length);
859
+ for (const coord2 of line) {
860
+ coordLengths.add(coord2.length);
871
861
  }
872
862
  }
873
863
  break;
@@ -877,8 +867,8 @@
877
867
  polygonRingsCount += geometry.coordinates.length;
878
868
  const flattened = geometry.coordinates.flat();
879
869
  polygonPositionsCount += flattened.length;
880
- for (const coord of flattened) {
881
- coordLengths.add(coord.length);
870
+ for (const coord2 of flattened) {
871
+ coordLengths.add(coord2.length);
882
872
  }
883
873
  break;
884
874
  case "MultiPolygon":
@@ -888,8 +878,8 @@
888
878
  polygonRingsCount += polygon.length;
889
879
  const flattened2 = polygon.flat();
890
880
  polygonPositionsCount += flattened2.length;
891
- for (const coord of flattened2) {
892
- coordLengths.add(coord.length);
881
+ for (const coord2 of flattened2) {
882
+ coordLengths.add(coord2.length);
893
883
  }
894
884
  }
895
885
  break;
@@ -1029,342 +1019,697 @@
1029
1019
  }
1030
1020
  });
1031
1021
 
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 });
1022
+ // ../../node_modules/@tmcw/togeojson/dist/togeojson.es.js
1023
+ function nodeVal(x) {
1024
+ if (x && x.normalize) {
1025
+ x.normalize();
1026
+ }
1027
+ return x && x.textContent || "";
1028
+ }
1029
+ function get1(x, y) {
1030
+ const n = x.getElementsByTagName(y);
1031
+ return n.length ? n[0] : null;
1032
+ }
1033
+ function getLineStyle(extensions) {
1034
+ const style = {};
1035
+ if (extensions) {
1036
+ const lineStyle = get1(extensions, "line");
1037
+ if (lineStyle) {
1038
+ const color = nodeVal(get1(lineStyle, "color")), opacity = parseFloat(nodeVal(get1(lineStyle, "opacity"))), width = parseFloat(nodeVal(get1(lineStyle, "width")));
1039
+ if (color)
1040
+ style.stroke = color;
1041
+ if (!isNaN(opacity))
1042
+ style["stroke-opacity"] = opacity;
1043
+ if (!isNaN(width))
1044
+ style["stroke-width"] = width * 96 / 25.4;
1045
+ }
1046
+ }
1047
+ return style;
1048
+ }
1049
+ function getExtensions(node) {
1050
+ let values = [];
1051
+ if (node !== null) {
1052
+ for (let i = 0; i < node.childNodes.length; i++) {
1053
+ const child = node.childNodes[i];
1054
+ if (child.nodeType !== 1)
1055
+ continue;
1056
+ const name = ["heart", "gpxtpx:hr", "hr"].includes(child.nodeName) ? "heart" : child.nodeName;
1057
+ if (name === "gpxtpx:TrackPointExtension") {
1058
+ values = values.concat(getExtensions(child));
1059
+ } else {
1060
+ const val = nodeVal(child);
1061
+ values.push([name, isNaN(val) ? val : parseFloat(val)]);
1179
1062
  }
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 } };
1063
+ }
1064
+ }
1065
+ return values;
1066
+ }
1067
+ function getMulti(x, ys) {
1068
+ const o = {};
1069
+ let n;
1070
+ let k;
1071
+ for (k = 0; k < ys.length; k++) {
1072
+ n = get1(x, ys[k]);
1073
+ if (n)
1074
+ o[ys[k]] = nodeVal(n);
1075
+ }
1076
+ return o;
1077
+ }
1078
+ function getProperties$1(node) {
1079
+ const prop = getMulti(node, [
1080
+ "name",
1081
+ "cmt",
1082
+ "desc",
1083
+ "type",
1084
+ "time",
1085
+ "keywords"
1086
+ ]);
1087
+ const extensions = node.getElementsByTagNameNS("http://www.garmin.com/xmlschemas/GpxExtensions/v3", "*");
1088
+ for (let i = 0; i < extensions.length; i++) {
1089
+ const extension = extensions[i];
1090
+ if (extension.parentNode.parentNode === node) {
1091
+ prop[extension.tagName.replace(":", "_")] = nodeVal(extension);
1092
+ }
1093
+ }
1094
+ const links = node.getElementsByTagName("link");
1095
+ if (links.length)
1096
+ prop.links = [];
1097
+ for (let i = 0; i < links.length; i++) {
1098
+ prop.links.push(Object.assign({ href: links[i].getAttribute("href") }, getMulti(links[i], ["text", "type"])));
1099
+ }
1100
+ return prop;
1101
+ }
1102
+ function coordPair$1(x) {
1103
+ const ll = [
1104
+ parseFloat(x.getAttribute("lon")),
1105
+ parseFloat(x.getAttribute("lat"))
1106
+ ];
1107
+ const ele = get1(x, "ele");
1108
+ const time = get1(x, "time");
1109
+ if (ele) {
1110
+ const e = parseFloat(nodeVal(ele));
1111
+ if (!isNaN(e)) {
1112
+ ll.push(e);
1113
+ }
1114
+ }
1115
+ return {
1116
+ coordinates: ll,
1117
+ time: time ? nodeVal(time) : null,
1118
+ extendedValues: getExtensions(get1(x, "extensions"))
1119
+ };
1120
+ }
1121
+ function getRoute(node) {
1122
+ const line = getPoints$1(node, "rtept");
1123
+ if (!line)
1124
+ return;
1125
+ return {
1126
+ type: "Feature",
1127
+ properties: Object.assign(getProperties$1(node), getLineStyle(get1(node, "extensions")), { _gpxType: "rte" }),
1128
+ geometry: {
1129
+ type: "LineString",
1130
+ coordinates: line.line
1131
+ }
1132
+ };
1133
+ }
1134
+ function getPoints$1(node, pointname) {
1135
+ const pts = node.getElementsByTagName(pointname);
1136
+ if (pts.length < 2)
1137
+ return;
1138
+ const line = [];
1139
+ const times = [];
1140
+ const extendedValues = {};
1141
+ for (let i = 0; i < pts.length; i++) {
1142
+ const c = coordPair$1(pts[i]);
1143
+ line.push(c.coordinates);
1144
+ if (c.time)
1145
+ times.push(c.time);
1146
+ for (let j = 0; j < c.extendedValues.length; j++) {
1147
+ const [name, val] = c.extendedValues[j];
1148
+ const plural = name === "heart" ? name : name.replace("gpxtpx:", "") + "s";
1149
+ if (!extendedValues[plural]) {
1150
+ extendedValues[plural] = Array(pts.length).fill(null);
1199
1151
  }
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
- }
1152
+ extendedValues[plural][i] = val;
1153
+ }
1154
+ }
1155
+ return {
1156
+ line,
1157
+ times,
1158
+ extendedValues
1159
+ };
1160
+ }
1161
+ function getTrack(node) {
1162
+ const segments = node.getElementsByTagName("trkseg");
1163
+ const track = [];
1164
+ const times = [];
1165
+ const extractedLines = [];
1166
+ for (let i = 0; i < segments.length; i++) {
1167
+ const line = getPoints$1(segments[i], "trkpt");
1168
+ if (line) {
1169
+ extractedLines.push(line);
1170
+ if (line.times && line.times.length)
1171
+ times.push(line.times);
1172
+ }
1173
+ }
1174
+ if (extractedLines.length === 0)
1175
+ return;
1176
+ const multi = extractedLines.length > 1;
1177
+ const properties = Object.assign(getProperties$1(node), getLineStyle(get1(node, "extensions")), { _gpxType: "trk" }, times.length ? {
1178
+ coordinateProperties: {
1179
+ times: multi ? times : times[0]
1180
+ }
1181
+ } : {});
1182
+ for (let i = 0; i < extractedLines.length; i++) {
1183
+ const line = extractedLines[i];
1184
+ track.push(line.line);
1185
+ for (const [name, val] of Object.entries(line.extendedValues)) {
1186
+ if (!properties.coordinateProperties) {
1187
+ properties.coordinateProperties = {};
1211
1188
  }
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;
1189
+ const props = properties.coordinateProperties;
1190
+ if (multi) {
1191
+ if (!props[name])
1192
+ props[name] = extractedLines.map((line2) => new Array(line2.line.length).fill(null));
1193
+ props[name][i] = val;
1194
+ } else {
1195
+ props[name] = val;
1220
1196
  }
1221
- function S(e2) {
1222
- return e2.replace(N, "").split(",").map(parseFloat);
1197
+ }
1198
+ }
1199
+ return {
1200
+ type: "Feature",
1201
+ properties,
1202
+ geometry: multi ? {
1203
+ type: "MultiLineString",
1204
+ coordinates: track
1205
+ } : {
1206
+ type: "LineString",
1207
+ coordinates: track[0]
1208
+ }
1209
+ };
1210
+ }
1211
+ function getPoint(node) {
1212
+ return {
1213
+ type: "Feature",
1214
+ properties: Object.assign(getProperties$1(node), getMulti(node, ["sym"])),
1215
+ geometry: {
1216
+ type: "Point",
1217
+ coordinates: coordPair$1(node).coordinates
1218
+ }
1219
+ };
1220
+ }
1221
+ function* gpxGen(doc) {
1222
+ const tracks = doc.getElementsByTagName("trk");
1223
+ const routes = doc.getElementsByTagName("rte");
1224
+ const waypoints = doc.getElementsByTagName("wpt");
1225
+ for (let i = 0; i < tracks.length; i++) {
1226
+ const feature = getTrack(tracks[i]);
1227
+ if (feature)
1228
+ yield feature;
1229
+ }
1230
+ for (let i = 0; i < routes.length; i++) {
1231
+ const feature = getRoute(routes[i]);
1232
+ if (feature)
1233
+ yield feature;
1234
+ }
1235
+ for (let i = 0; i < waypoints.length; i++) {
1236
+ yield getPoint(waypoints[i]);
1237
+ }
1238
+ }
1239
+ function gpx(doc) {
1240
+ return {
1241
+ type: "FeatureCollection",
1242
+ features: Array.from(gpxGen(doc))
1243
+ };
1244
+ }
1245
+ function fromEntries(arr) {
1246
+ const obj = {};
1247
+ for (const [key, value] of arr) {
1248
+ obj[key] = value;
1249
+ }
1250
+ return obj;
1251
+ }
1252
+ function getProperties(node, attributeNames) {
1253
+ const properties = [];
1254
+ for (const [tag, alias] of attributeNames) {
1255
+ let elem = get1(node, tag);
1256
+ if (!elem) {
1257
+ const elements = node.getElementsByTagNameNS(EXTENSIONS_NS, tag);
1258
+ if (elements.length) {
1259
+ elem = elements[0];
1223
1260
  }
1224
- function k(e2) {
1225
- return e2.replace(x, "").split(T).map(S);
1261
+ }
1262
+ const val = parseFloat(nodeVal(elem));
1263
+ if (!isNaN(val)) {
1264
+ properties.push([alias, val]);
1265
+ }
1266
+ }
1267
+ return properties;
1268
+ }
1269
+ function coordPair(x) {
1270
+ const lon = nodeVal(get1(x, "LongitudeDegrees"));
1271
+ const lat = nodeVal(get1(x, "LatitudeDegrees"));
1272
+ if (!lon.length || !lat.length) {
1273
+ return null;
1274
+ }
1275
+ const ll = [parseFloat(lon), parseFloat(lat)];
1276
+ const alt = get1(x, "AltitudeMeters");
1277
+ const heartRate = get1(x, "HeartRateBpm");
1278
+ const time = get1(x, "Time");
1279
+ let a;
1280
+ if (alt) {
1281
+ a = parseFloat(nodeVal(alt));
1282
+ if (!isNaN(a)) {
1283
+ ll.push(a);
1284
+ }
1285
+ }
1286
+ return {
1287
+ coordinates: ll,
1288
+ time: time ? nodeVal(time) : null,
1289
+ heartRate: heartRate ? parseFloat(nodeVal(heartRate)) : null,
1290
+ extensions: getProperties(x, TRACKPOINT_ATTRIBUTES)
1291
+ };
1292
+ }
1293
+ function getPoints(node, pointname) {
1294
+ const pts = node.getElementsByTagName(pointname);
1295
+ const line = [];
1296
+ const times = [];
1297
+ const heartRates = [];
1298
+ if (pts.length < 2)
1299
+ return null;
1300
+ const result = { extendedProperties: {} };
1301
+ for (let i = 0; i < pts.length; i++) {
1302
+ const c = coordPair(pts[i]);
1303
+ if (c === null)
1304
+ continue;
1305
+ line.push(c.coordinates);
1306
+ if (c.time)
1307
+ times.push(c.time);
1308
+ if (c.heartRate)
1309
+ heartRates.push(c.heartRate);
1310
+ for (const [alias, value] of c.extensions) {
1311
+ if (!result.extendedProperties[alias]) {
1312
+ result.extendedProperties[alias] = Array(pts.length).fill(null);
1226
1313
  }
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;
1314
+ result.extendedProperties[alias][i] = value;
1315
+ }
1316
+ }
1317
+ return Object.assign(result, {
1318
+ line,
1319
+ times,
1320
+ heartRates
1321
+ });
1322
+ }
1323
+ function getLap(node) {
1324
+ const segments = node.getElementsByTagName("Track");
1325
+ const track = [];
1326
+ const times = [];
1327
+ const heartRates = [];
1328
+ const allExtendedProperties = [];
1329
+ let line;
1330
+ const properties = fromEntries(getProperties(node, LAP_ATTRIBUTES));
1331
+ const nameElement = get1(node, "Name");
1332
+ if (nameElement) {
1333
+ properties.name = nodeVal(nameElement);
1334
+ }
1335
+ for (let i = 0; i < segments.length; i++) {
1336
+ line = getPoints(segments[i], "Trackpoint");
1337
+ if (line) {
1338
+ track.push(line.line);
1339
+ if (line.times.length)
1340
+ times.push(line.times);
1341
+ if (line.heartRates.length)
1342
+ heartRates.push(line.heartRates);
1343
+ allExtendedProperties.push(line.extendedProperties);
1344
+ }
1345
+ }
1346
+ for (let i = 0; i < allExtendedProperties.length; i++) {
1347
+ const extendedProperties = allExtendedProperties[i];
1348
+ for (const property in extendedProperties) {
1349
+ if (segments.length === 1) {
1350
+ properties[property] = line.extendedProperties[property];
1351
+ } else {
1352
+ if (!properties[property]) {
1353
+ properties[property] = track.map((track2) => Array(track2.length).fill(null));
1237
1354
  }
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 };
1355
+ properties[property][i] = extendedProperties[property];
1260
1356
  }
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);
1357
+ }
1358
+ }
1359
+ if (track.length === 0)
1360
+ return;
1361
+ if (times.length || heartRates.length) {
1362
+ properties.coordinateProperties = Object.assign(times.length ? {
1363
+ times: track.length === 1 ? times[0] : times
1364
+ } : {}, heartRates.length ? {
1365
+ heart: track.length === 1 ? heartRates[0] : heartRates
1366
+ } : {});
1367
+ }
1368
+ return {
1369
+ type: "Feature",
1370
+ properties,
1371
+ geometry: {
1372
+ type: track.length === 1 ? "LineString" : "MultiLineString",
1373
+ coordinates: track.length === 1 ? track[0] : track
1374
+ }
1375
+ };
1376
+ }
1377
+ function* tcxGen(doc) {
1378
+ const laps = doc.getElementsByTagName("Lap");
1379
+ for (let i = 0; i < laps.length; i++) {
1380
+ const feature = getLap(laps[i]);
1381
+ if (feature)
1382
+ yield feature;
1383
+ }
1384
+ const courses = doc.getElementsByTagName("Courses");
1385
+ for (let i = 0; i < courses.length; i++) {
1386
+ const feature = getLap(courses[i]);
1387
+ if (feature)
1388
+ yield feature;
1389
+ }
1390
+ }
1391
+ function tcx(doc) {
1392
+ return {
1393
+ type: "FeatureCollection",
1394
+ features: Array.from(tcxGen(doc))
1395
+ };
1396
+ }
1397
+ function okhash(x) {
1398
+ if (!x || !x.length)
1399
+ return 0;
1400
+ let h = 0;
1401
+ for (let i = 0; i < x.length; i++) {
1402
+ h = (h << 5) - h + x.charCodeAt(i) | 0;
1403
+ }
1404
+ return h;
1405
+ }
1406
+ function coord1(v) {
1407
+ return v.replace(removeSpace, "").split(",").map(parseFloat);
1408
+ }
1409
+ function coord(v) {
1410
+ return v.replace(trimSpace, "").split(splitSpace).map(coord1);
1411
+ }
1412
+ function xml2str(node) {
1413
+ if (node.xml !== void 0)
1414
+ return node.xml;
1415
+ if (node.tagName) {
1416
+ let output = node.tagName;
1417
+ for (let i = 0; i < node.attributes.length; i++) {
1418
+ output += node.attributes[i].name + node.attributes[i].value;
1419
+ }
1420
+ for (let i = 0; i < node.childNodes.length; i++) {
1421
+ output += xml2str(node.childNodes[i]);
1422
+ }
1423
+ return output;
1424
+ }
1425
+ if (node.nodeName === "#text") {
1426
+ return (node.nodeValue || node.value || "").trim();
1427
+ }
1428
+ if (node.nodeName === "#cdata-section") {
1429
+ return node.nodeValue;
1430
+ }
1431
+ return "";
1432
+ }
1433
+ function kmlColor(properties, elem, prefix) {
1434
+ let v = nodeVal(get1(elem, "color")) || "";
1435
+ const colorProp = prefix == "stroke" || prefix === "fill" ? prefix : prefix + "-color";
1436
+ if (v.substr(0, 1) === "#") {
1437
+ v = v.substr(1);
1438
+ }
1439
+ if (v.length === 6 || v.length === 3) {
1440
+ properties[colorProp] = v;
1441
+ } else if (v.length === 8) {
1442
+ properties[prefix + "-opacity"] = parseInt(v.substr(0, 2), 16) / 255;
1443
+ properties[colorProp] = "#" + v.substr(6, 2) + v.substr(4, 2) + v.substr(2, 2);
1444
+ }
1445
+ }
1446
+ function numericProperty(properties, elem, source, target) {
1447
+ const val = parseFloat(nodeVal(get1(elem, source)));
1448
+ if (!isNaN(val))
1449
+ properties[target] = val;
1450
+ }
1451
+ function gxCoords(root) {
1452
+ let elems = root.getElementsByTagName("coord");
1453
+ const coords = [];
1454
+ const times = [];
1455
+ if (elems.length === 0)
1456
+ elems = root.getElementsByTagName("gx:coord");
1457
+ for (let i = 0; i < elems.length; i++) {
1458
+ coords.push(nodeVal(elems[i]).split(" ").map(parseFloat));
1459
+ }
1460
+ const timeElems = root.getElementsByTagName("when");
1461
+ for (let j = 0; j < timeElems.length; j++)
1462
+ times.push(nodeVal(timeElems[j]));
1463
+ return {
1464
+ coords,
1465
+ times
1466
+ };
1467
+ }
1468
+ function getGeometry(root) {
1469
+ let geomNode;
1470
+ let geomNodes;
1471
+ let i;
1472
+ let j;
1473
+ let k;
1474
+ const geoms = [];
1475
+ const coordTimes = [];
1476
+ if (get1(root, "MultiGeometry")) {
1477
+ return getGeometry(get1(root, "MultiGeometry"));
1478
+ }
1479
+ if (get1(root, "MultiTrack")) {
1480
+ return getGeometry(get1(root, "MultiTrack"));
1481
+ }
1482
+ if (get1(root, "gx:MultiTrack")) {
1483
+ return getGeometry(get1(root, "gx:MultiTrack"));
1484
+ }
1485
+ for (i = 0; i < geotypes.length; i++) {
1486
+ geomNodes = root.getElementsByTagName(geotypes[i]);
1487
+ if (geomNodes) {
1488
+ for (j = 0; j < geomNodes.length; j++) {
1489
+ geomNode = geomNodes[j];
1490
+ if (geotypes[i] === "Point") {
1491
+ geoms.push({
1492
+ type: "Point",
1493
+ coordinates: coord1(nodeVal(get1(geomNode, "coordinates")))
1494
+ });
1495
+ } else if (geotypes[i] === "LineString") {
1496
+ geoms.push({
1497
+ type: "LineString",
1498
+ coordinates: coord(nodeVal(get1(geomNode, "coordinates")))
1499
+ });
1500
+ } else if (geotypes[i] === "Polygon") {
1501
+ const rings = geomNode.getElementsByTagName("LinearRing"), coords = [];
1502
+ for (k = 0; k < rings.length; k++) {
1503
+ coords.push(coord(nodeVal(get1(rings[k], "coordinates"))));
1317
1504
  }
1505
+ geoms.push({
1506
+ type: "Polygon",
1507
+ coordinates: coords
1508
+ });
1509
+ } else if (geotypes[i] === "Track" || geotypes[i] === "gx:Track") {
1510
+ const track = gxCoords(geomNode);
1511
+ geoms.push({
1512
+ type: "LineString",
1513
+ coordinates: track.coords
1514
+ });
1515
+ if (track.times.length)
1516
+ coordTimes.push(track.times);
1318
1517
  }
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
1518
  }
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
- });
1519
+ }
1520
+ }
1521
+ return {
1522
+ geoms,
1523
+ coordTimes
1524
+ };
1525
+ }
1526
+ function getPlacemark(root, styleIndex, styleMapIndex, styleByHash) {
1527
+ const geomsAndTimes = getGeometry(root);
1528
+ let i;
1529
+ const properties = {};
1530
+ const name = nodeVal(get1(root, "name"));
1531
+ const address = nodeVal(get1(root, "address"));
1532
+ let styleUrl = nodeVal(get1(root, "styleUrl"));
1533
+ const description = nodeVal(get1(root, "description"));
1534
+ const timeSpan = get1(root, "TimeSpan");
1535
+ const timeStamp = get1(root, "TimeStamp");
1536
+ const extendedData = get1(root, "ExtendedData");
1537
+ let iconStyle = get1(root, "IconStyle");
1538
+ let labelStyle = get1(root, "LabelStyle");
1539
+ let lineStyle = get1(root, "LineStyle");
1540
+ let polyStyle = get1(root, "PolyStyle");
1541
+ const visibility = get1(root, "visibility");
1542
+ if (name)
1543
+ properties.name = name;
1544
+ if (address)
1545
+ properties.address = address;
1546
+ if (styleUrl) {
1547
+ if (styleUrl[0] !== "#") {
1548
+ styleUrl = "#" + styleUrl;
1549
+ }
1550
+ properties.styleUrl = styleUrl;
1551
+ if (styleIndex[styleUrl]) {
1552
+ properties.styleHash = styleIndex[styleUrl];
1553
+ }
1554
+ if (styleMapIndex[styleUrl]) {
1555
+ properties.styleMapHash = styleMapIndex[styleUrl];
1556
+ properties.styleHash = styleIndex[styleMapIndex[styleUrl].normal];
1557
+ }
1558
+ const style = styleByHash[properties.styleHash];
1559
+ if (style) {
1560
+ if (!iconStyle)
1561
+ iconStyle = get1(style, "IconStyle");
1562
+ if (!labelStyle)
1563
+ labelStyle = get1(style, "LabelStyle");
1564
+ if (!lineStyle)
1565
+ lineStyle = get1(style, "LineStyle");
1566
+ if (!polyStyle)
1567
+ polyStyle = get1(style, "PolyStyle");
1568
+ }
1569
+ }
1570
+ if (description)
1571
+ properties.description = description;
1572
+ if (timeSpan) {
1573
+ const begin = nodeVal(get1(timeSpan, "begin"));
1574
+ const end = nodeVal(get1(timeSpan, "end"));
1575
+ properties.timespan = { begin, end };
1576
+ }
1577
+ if (timeStamp) {
1578
+ properties.timestamp = nodeVal(get1(timeStamp, "when"));
1579
+ }
1580
+ if (iconStyle) {
1581
+ kmlColor(properties, iconStyle, "icon");
1582
+ numericProperty(properties, iconStyle, "scale", "icon-scale");
1583
+ numericProperty(properties, iconStyle, "heading", "icon-heading");
1584
+ const hotspot = get1(iconStyle, "hotSpot");
1585
+ if (hotspot) {
1586
+ const left = parseFloat(hotspot.getAttribute("x"));
1587
+ const top = parseFloat(hotspot.getAttribute("y"));
1588
+ if (!isNaN(left) && !isNaN(top))
1589
+ properties["icon-offset"] = [left, top];
1590
+ }
1591
+ const icon = get1(iconStyle, "Icon");
1592
+ if (icon) {
1593
+ const href = nodeVal(get1(icon, "href"));
1594
+ if (href)
1595
+ properties.icon = href;
1596
+ }
1597
+ }
1598
+ if (labelStyle) {
1599
+ kmlColor(properties, labelStyle, "label");
1600
+ numericProperty(properties, labelStyle, "scale", "label-scale");
1601
+ }
1602
+ if (lineStyle) {
1603
+ kmlColor(properties, lineStyle, "stroke");
1604
+ numericProperty(properties, lineStyle, "width", "stroke-width");
1605
+ }
1606
+ if (polyStyle) {
1607
+ kmlColor(properties, polyStyle, "fill");
1608
+ const fill = nodeVal(get1(polyStyle, "fill"));
1609
+ const outline = nodeVal(get1(polyStyle, "outline"));
1610
+ if (fill)
1611
+ properties["fill-opacity"] = fill === "1" ? properties["fill-opacity"] || 1 : 0;
1612
+ if (outline)
1613
+ properties["stroke-opacity"] = outline === "1" ? properties["stroke-opacity"] || 1 : 0;
1614
+ }
1615
+ if (extendedData) {
1616
+ const datas = extendedData.getElementsByTagName("Data"), simpleDatas = extendedData.getElementsByTagName("SimpleData");
1617
+ for (i = 0; i < datas.length; i++) {
1618
+ properties[datas[i].getAttribute("name")] = nodeVal(get1(datas[i], "value"));
1619
+ }
1620
+ for (i = 0; i < simpleDatas.length; i++) {
1621
+ properties[simpleDatas[i].getAttribute("name")] = nodeVal(simpleDatas[i]);
1622
+ }
1623
+ }
1624
+ if (visibility) {
1625
+ properties.visibility = nodeVal(visibility);
1626
+ }
1627
+ if (geomsAndTimes.coordTimes.length) {
1628
+ properties.coordinateProperties = {
1629
+ times: geomsAndTimes.coordTimes.length === 1 ? geomsAndTimes.coordTimes[0] : geomsAndTimes.coordTimes
1630
+ };
1631
+ }
1632
+ const feature = {
1633
+ type: "Feature",
1634
+ geometry: geomsAndTimes.geoms.length === 0 ? null : geomsAndTimes.geoms.length === 1 ? geomsAndTimes.geoms[0] : {
1635
+ type: "GeometryCollection",
1636
+ geometries: geomsAndTimes.geoms
1637
+ },
1638
+ properties
1639
+ };
1640
+ if (root.getAttribute("id"))
1641
+ feature.id = root.getAttribute("id");
1642
+ return feature;
1643
+ }
1644
+ function* kmlGen(doc) {
1645
+ const styleIndex = {};
1646
+ const styleByHash = {};
1647
+ const styleMapIndex = {};
1648
+ const placemarks = doc.getElementsByTagName("Placemark");
1649
+ const styles = doc.getElementsByTagName("Style");
1650
+ const styleMaps = doc.getElementsByTagName("StyleMap");
1651
+ for (let k = 0; k < styles.length; k++) {
1652
+ const style = styles[k];
1653
+ const hash = okhash(xml2str(style)).toString(16);
1654
+ let id = style.getAttribute("id");
1655
+ if (!id && style.parentNode.tagName.replace("gx:", "") === "CascadingStyle") {
1656
+ id = style.parentNode.getAttribute("kml:id") || style.parentNode.getAttribute("id");
1657
+ }
1658
+ styleIndex["#" + id] = hash;
1659
+ styleByHash[hash] = style;
1660
+ }
1661
+ for (let l = 0; l < styleMaps.length; l++) {
1662
+ styleIndex["#" + styleMaps[l].getAttribute("id")] = okhash(xml2str(styleMaps[l])).toString(16);
1663
+ const pairs = styleMaps[l].getElementsByTagName("Pair");
1664
+ const pairsMap = {};
1665
+ for (let m = 0; m < pairs.length; m++) {
1666
+ pairsMap[nodeVal(get1(pairs[m], "key"))] = nodeVal(get1(pairs[m], "styleUrl"));
1667
+ }
1668
+ styleMapIndex["#" + styleMaps[l].getAttribute("id")] = pairsMap;
1669
+ }
1670
+ for (let j = 0; j < placemarks.length; j++) {
1671
+ const feature = getPlacemark(placemarks[j], styleIndex, styleMapIndex, styleByHash);
1672
+ if (feature)
1673
+ yield feature;
1674
+ }
1675
+ }
1676
+ function kml(doc) {
1677
+ return {
1678
+ type: "FeatureCollection",
1679
+ features: Array.from(kmlGen(doc))
1680
+ };
1681
+ }
1682
+ var EXTENSIONS_NS, TRACKPOINT_ATTRIBUTES, LAP_ATTRIBUTES, removeSpace, trimSpace, splitSpace, geotypes;
1683
+ var init_togeojson_es = __esm({
1684
+ "../../node_modules/@tmcw/togeojson/dist/togeojson.es.js"() {
1685
+ EXTENSIONS_NS = "http://www.garmin.com/xmlschemas/ActivityExtension/v2";
1686
+ TRACKPOINT_ATTRIBUTES = [
1687
+ ["heartRate", "heartRates"],
1688
+ ["Cadence", "cadences"],
1689
+ ["Speed", "speeds"],
1690
+ ["Watts", "watts"]
1691
+ ];
1692
+ LAP_ATTRIBUTES = [
1693
+ ["TotalTimeSeconds", "totalTimeSeconds"],
1694
+ ["DistanceMeters", "distanceMeters"],
1695
+ ["MaximumSpeed", "maxSpeed"],
1696
+ ["AverageHeartRateBpm", "avgHeartRate"],
1697
+ ["MaximumHeartRateBpm", "maxHeartRate"],
1698
+ ["AvgSpeed", "avgSpeed"],
1699
+ ["AvgWatts", "avgWatts"],
1700
+ ["MaxWatts", "maxWatts"]
1701
+ ];
1702
+ removeSpace = /\s*/g;
1703
+ trimSpace = /^\s*|\s*$/g;
1704
+ splitSpace = /\s+/;
1705
+ geotypes = ["Polygon", "LineString", "Point", "Track", "gx:Track"];
1361
1706
  }
1362
1707
  });
1363
1708
 
1364
1709
  // src/gpx-loader.ts
1365
1710
  function parseTextSync(text, options) {
1366
1711
  const doc = new DOMParser().parseFromString(text, "text/xml");
1367
- const geojson = (0, import_togeojson.gpx)(doc);
1712
+ const geojson = gpx(doc);
1368
1713
  const shape = options?.gis?.format || options?.gpx?.type || options?.gpx?.shape;
1369
1714
  switch (shape) {
1370
1715
  case "object-row-table": {
@@ -1391,11 +1736,11 @@
1391
1736
  return geojson;
1392
1737
  }
1393
1738
  }
1394
- var import_togeojson, VERSION, GPX_HEADER, GPXLoader;
1739
+ var VERSION, GPX_HEADER, GPXLoader;
1395
1740
  var init_gpx_loader = __esm({
1396
1741
  "src/gpx-loader.ts"() {
1397
1742
  init_src();
1398
- import_togeojson = __toModule(require_togeojson_umd());
1743
+ init_togeojson_es();
1399
1744
  VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1400
1745
  GPX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1401
1746
  <gpx`;
@@ -1421,7 +1766,7 @@
1421
1766
  // src/kml-loader.ts
1422
1767
  function parseTextSync2(text, options) {
1423
1768
  const doc = new DOMParser().parseFromString(text, "text/xml");
1424
- const geojson = (0, import_togeojson2.kml)(doc);
1769
+ const geojson = kml(doc);
1425
1770
  const shape = options?.gis?.format || options?.kml?.type || options?.kml?.shape;
1426
1771
  switch (shape) {
1427
1772
  case "object-row-table": {
@@ -1448,11 +1793,11 @@
1448
1793
  return geojson;
1449
1794
  }
1450
1795
  }
1451
- var import_togeojson2, VERSION2, KML_HEADER, KMLLoader;
1796
+ var VERSION2, KML_HEADER, KMLLoader;
1452
1797
  var init_kml_loader = __esm({
1453
1798
  "src/kml-loader.ts"() {
1454
1799
  init_src();
1455
- import_togeojson2 = __toModule(require_togeojson_umd());
1800
+ init_togeojson_es();
1456
1801
  VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1457
1802
  KML_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1458
1803
  <kml xmlns="http://www.opengis.net/kml/2.2">`;
@@ -1478,7 +1823,7 @@
1478
1823
  // src/tcx-loader.ts
1479
1824
  function parseTextSync3(text, options) {
1480
1825
  const doc = new DOMParser().parseFromString(text, "text/xml");
1481
- const geojson = (0, import_togeojson3.tcx)(doc);
1826
+ const geojson = tcx(doc);
1482
1827
  const shape = options?.gis?.format || options?.tcx?.type || options?.tcx?.shape;
1483
1828
  switch (shape) {
1484
1829
  case "object-row-table": {
@@ -1505,11 +1850,11 @@
1505
1850
  return geojson;
1506
1851
  }
1507
1852
  }
1508
- var import_togeojson3, VERSION3, TCX_HEADER, TCXLoader;
1853
+ var VERSION3, TCX_HEADER, TCXLoader;
1509
1854
  var init_tcx_loader = __esm({
1510
1855
  "src/tcx-loader.ts"() {
1511
1856
  init_src();
1512
- import_togeojson3 = __toModule(require_togeojson_umd());
1857
+ init_togeojson_es();
1513
1858
  VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1514
1859
  TCX_HEADER = `<?xml version="1.0" encoding="UTF-8"?>
1515
1860
  <TrainingCenterDatabase`;