{"version":3,"file":"togeojson.umd.js","sources":["../lib/lib/shared.ts","../lib/lib/gpx/line.ts","../lib/lib/gpx/extensions.ts","../lib/lib/gpx/coord_pair.ts","../lib/lib/gpx/properties.ts","../lib/lib/gpx.ts","../lib/lib/tcx.ts","../lib/lib/kml/fixColor.ts","../lib/lib/kml/extractStyle.ts","../lib/lib/kml/shared.ts","../lib/lib/kml/geometry.ts","../lib/lib/kml/placemark.ts","../lib/lib/kml/ground_overlay.ts","../lib/lib/kml.ts"],"sourcesContent":["import type { Feature, Geometry } from \"geojson\";\n\nexport function $(element: Element | Document, tagName: string): Element[] {\n return Array.from(element.getElementsByTagName(tagName));\n}\n\nexport type P = NonNullable;\nexport type F = Feature;\n\nexport type StyleMap = { [key: string]: P };\n\nexport function normalizeId(id: string) {\n return id[0] === \"#\" ? id : `#${id}`;\n}\n\nexport function $ns(\n element: Element | Document,\n tagName: string,\n ns: string\n): Element[] {\n return Array.from(element.getElementsByTagNameNS(ns, tagName));\n}\n\n/**\n * get the content of a text node, if any\n */\nexport function nodeVal(node: Element | null) {\n node?.normalize();\n return (node && node.textContent) || \"\";\n}\n\n/**\n * Get one Y child of X, if any, otherwise null\n */\nexport function get1(\n node: Element,\n tagName: string,\n callback?: (elem: Element) => unknown\n) {\n const n = node.getElementsByTagName(tagName);\n const result = n.length ? n[0] : null;\n if (result && callback) callback(result);\n return result;\n}\n\nexport function get(\n node: Element | null,\n tagName: string,\n callback?: (elem: Element, properties: P) => P\n) {\n const properties: Feature[\"properties\"] = {};\n if (!node) return properties;\n const n = node.getElementsByTagName(tagName);\n const result = n.length ? n[0] : null;\n if (result && callback) {\n return callback(result, properties);\n }\n return properties;\n}\n\nexport function val1(\n node: Element,\n tagName: string,\n callback: (val: string) => P | void\n): P {\n const val = nodeVal(get1(node, tagName));\n if (val && callback) return callback(val) || {};\n return {};\n}\n\nexport function $num(\n node: Element,\n tagName: string,\n callback: (val: number) => Feature[\"properties\"]\n) {\n const val = parseFloat(nodeVal(get1(node, tagName)));\n if (isNaN(val)) return undefined;\n if (val && callback) return callback(val) || {};\n return {};\n}\n\nexport function num1(\n node: Element,\n tagName: string,\n callback?: (val: number) => unknown\n) {\n const val = parseFloat(nodeVal(get1(node, tagName)));\n if (isNaN(val)) return undefined;\n if (callback) callback(val);\n return val;\n}\n\nexport function getMulti(node: Element, propertyNames: string[]): P {\n const properties: P = {};\n for (const property of propertyNames) {\n val1(node, property, (val) => {\n properties[property] = val;\n });\n }\n return properties;\n}\n\nexport function isElement(node: Node | null): node is Element {\n return node?.nodeType === 1;\n}\n","import { get, P, val1, $num } from \"../shared\";\n\nexport function getLineStyle(node: Element | null) {\n return get(node, \"line\", (lineStyle) => {\n const val: P = Object.assign(\n {},\n val1(lineStyle, \"color\", (color) => {\n return { stroke: `#${color}` };\n }),\n $num(lineStyle, \"opacity\", (opacity) => {\n return { \"stroke-opacity\": opacity };\n }),\n $num(lineStyle, \"width\", (width) => {\n // GPX width is in mm, convert to px with 96 px per inch\n return { \"stroke-width\": (width * 96) / 25.4 };\n })\n );\n return val;\n });\n}\n","import { isElement, nodeVal } from \"../shared\";\n\nexport type ExtendedValues = [string, string | number][];\n\nexport function getExtensions(node: Element | null): ExtendedValues {\n let values: [string, string | number][] = [];\n if (node === null) return values;\n for (const child of Array.from(node.childNodes)) {\n if (!isElement(child)) continue;\n const name = abbreviateName(child.nodeName);\n if (name === \"gpxtpx:TrackPointExtension\") {\n // loop again for nested garmin extensions (eg. \"gpxtpx:hr\")\n values = values.concat(getExtensions(child));\n } else {\n // push custom extension (eg. \"power\")\n const val = nodeVal(child);\n values.push([name, parseNumeric(val)]);\n }\n }\n return values;\n}\n\nfunction abbreviateName(name: string) {\n return [\"heart\", \"gpxtpx:hr\", \"hr\"].includes(name) ? \"heart\" : name;\n}\n\nfunction parseNumeric(val: string) {\n const num = parseFloat(val);\n return isNaN(num) ? val : num;\n}\n","import { Position } from \"geojson\";\nimport { num1, get1, nodeVal } from \"../shared\";\nimport { ExtendedValues, getExtensions } from \"./extensions\";\n\ninterface CoordPair {\n coordinates: Position;\n time: string | null;\n extendedValues: ExtendedValues;\n}\n\nexport function coordPair(node: Element): CoordPair | null {\n const ll = [\n parseFloat(node.getAttribute(\"lon\") || \"\"),\n parseFloat(node.getAttribute(\"lat\") || \"\"),\n ];\n\n if (isNaN(ll[0]) || isNaN(ll[1])) {\n return null;\n }\n\n num1(node, \"ele\", (val) => {\n ll.push(val);\n });\n\n const time = get1(node, \"time\");\n return {\n coordinates: ll,\n time: time ? nodeVal(time) : null,\n extendedValues: getExtensions(get1(node, \"extensions\")),\n };\n}\n","import { $, getMulti, nodeVal } from \"../shared\";\n\nexport function extractProperties(node: Element) {\n const properties = getMulti(node, [\n \"name\",\n \"cmt\",\n \"desc\",\n \"type\",\n \"time\",\n \"keywords\",\n ]);\n\n const extensions = Array.from(\n node.getElementsByTagNameNS(\n \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\",\n \"*\"\n )\n );\n for (const child of extensions) {\n if (child.parentNode?.parentNode === node) {\n properties[child.tagName.replace(\":\", \"_\")] = nodeVal(child);\n }\n }\n\n const links = $(node, \"link\");\n if (links.length) {\n properties.links = links.map((link) =>\n Object.assign(\n { href: link.getAttribute(\"href\") },\n getMulti(link, [\"text\", \"type\"])\n )\n );\n }\n\n return properties;\n}\n","import type {\n FeatureCollection,\n Feature,\n Point,\n MultiLineString,\n LineString,\n Position,\n} from \"geojson\";\nimport { getLineStyle } from \"./gpx/line\";\nimport { coordPair } from \"./gpx/coord_pair\";\nimport { extractProperties } from \"./gpx/properties\";\nimport { P, $, get1, getMulti } from \"./shared\";\n\n/**\n * Extract points from a trkseg or rte element.\n */\nfunction getPoints(node: Element, pointname: \"trkpt\" | \"rtept\") {\n const pts = $(node, pointname);\n const line: Position[] = [];\n const times = [];\n const extendedValues: P = {};\n\n for (let i = 0; i < pts.length; i++) {\n const c = coordPair(pts[i]);\n if (!c) {\n continue;\n }\n line.push(c.coordinates);\n if (c.time) times.push(c.time);\n for (const [name, val] of c.extendedValues) {\n const plural =\n name === \"heart\" ? name : name.replace(\"gpxtpx:\", \"\") + \"s\";\n if (!extendedValues[plural]) {\n extendedValues[plural] = Array(pts.length).fill(null);\n }\n extendedValues[plural][i] = val;\n }\n }\n\n if (line.length < 2) return; // Invalid line in GeoJSON\n\n return {\n line: line,\n times: times,\n extendedValues: extendedValues,\n };\n}\n\n/**\n * Extract a LineString geometry from a rte\n * element.\n */\nfunction getRoute(node: Element): Feature | undefined {\n const line = getPoints(node, \"rtept\");\n if (!line) return;\n return {\n type: \"Feature\",\n properties: Object.assign(\n { _gpxType: \"rte\" },\n extractProperties(node),\n getLineStyle(get1(node, \"extensions\"))\n ),\n geometry: {\n type: \"LineString\",\n coordinates: line.line,\n },\n };\n}\n\nfunction getTrack(node: Element): Feature | null {\n const segments = $(node, \"trkseg\");\n const track = [];\n const times = [];\n const extractedLines = [];\n\n for (const segment of segments) {\n const line = getPoints(segment, \"trkpt\");\n if (line) {\n extractedLines.push(line);\n if (line.times && line.times.length) times.push(line.times);\n }\n }\n\n if (extractedLines.length === 0) return null;\n\n const multi = extractedLines.length > 1;\n\n const properties: Feature[\"properties\"] = Object.assign(\n { _gpxType: \"trk\" },\n extractProperties(node),\n getLineStyle(get1(node, \"extensions\")),\n times.length\n ? {\n coordinateProperties: {\n times: multi ? times : times[0],\n },\n }\n : {}\n );\n\n for (const line of extractedLines) {\n track.push(line.line);\n if (!properties.coordinateProperties) {\n properties.coordinateProperties = {};\n }\n const props = properties.coordinateProperties;\n const entries = Object.entries(line.extendedValues);\n for (let i = 0; i < entries.length; i++) {\n const [name, val] = entries[i];\n if (multi) {\n if (!props[name]) {\n props[name] = extractedLines.map((line) =>\n new Array(line.line.length).fill(null)\n );\n }\n props[name][i] = val;\n } else {\n props[name] = val;\n }\n }\n }\n\n return {\n type: \"Feature\",\n properties: properties,\n geometry: multi\n ? {\n type: \"MultiLineString\",\n coordinates: track,\n }\n : {\n type: \"LineString\",\n coordinates: track[0],\n },\n };\n}\n\n/**\n * Extract a point, if possible, from a given node,\n * which is usually a wpt or trkpt\n */\nfunction getPoint(node: Element): Feature | null {\n const properties: Feature[\"properties\"] = Object.assign(\n extractProperties(node),\n getMulti(node, [\"sym\"])\n );\n const pair = coordPair(node);\n if (!pair) return null;\n return {\n type: \"Feature\",\n properties,\n geometry: {\n type: \"Point\",\n coordinates: pair.coordinates,\n },\n };\n}\n\n/**\n * Convert GPX to GeoJSON incrementally, returning\n * a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators)\n * that yields output feature by feature.\n */\nexport function* gpxGen(node: Document): Generator {\n for (const track of $(node, \"trk\")) {\n const feature = getTrack(track);\n if (feature) yield feature;\n }\n\n for (const route of $(node, \"rte\")) {\n const feature = getRoute(route);\n if (feature) yield feature;\n }\n\n for (const waypoint of $(node, \"wpt\")) {\n const point = getPoint(waypoint);\n if (point) yield point;\n }\n}\n\n/**\n *\n * Convert a GPX document to GeoJSON. The first argument, `doc`, must be a GPX\n * document as an XML DOM - not as a string. You can get this using jQuery's default\n * `.ajax` function or using a bare XMLHttpRequest with the `.response` property\n * holding an XML DOM.\n *\n * The output is a JavaScript object of GeoJSON data, same as `.kml` outputs, with the\n * addition of a `_gpxType` property on each `LineString` feature that indicates whether\n * the feature was encoded as a route (`rte`) or track (`trk`) in the GPX document.\n */\nexport function gpx(node: Document): FeatureCollection {\n return {\n type: \"FeatureCollection\",\n features: Array.from(gpxGen(node)),\n };\n}\n","import { Feature, FeatureCollection, Position } from \"geojson\";\nimport { P, $, get, num1, nodeVal, get1 } from \"./shared\";\n\ntype PropertyMapping = readonly [string, string][];\n\nconst EXTENSIONS_NS = \"http://www.garmin.com/xmlschemas/ActivityExtension/v2\";\n\nconst TRACKPOINT_ATTRIBUTES: PropertyMapping = [\n [\"heartRate\", \"heartRates\"],\n [\"Cadence\", \"cadences\"],\n // Extended Trackpoint attributes\n [\"Speed\", \"speeds\"],\n [\"Watts\", \"watts\"],\n];\n\nconst LAP_ATTRIBUTES: PropertyMapping = [\n [\"TotalTimeSeconds\", \"totalTimeSeconds\"],\n [\"DistanceMeters\", \"distanceMeters\"],\n [\"MaximumSpeed\", \"maxSpeed\"],\n [\"AverageHeartRateBpm\", \"avgHeartRate\"],\n [\"MaximumHeartRateBpm\", \"maxHeartRate\"],\n\n // Extended Lap attributes\n [\"AvgSpeed\", \"avgSpeed\"],\n [\"AvgWatts\", \"avgWatts\"],\n [\"MaxWatts\", \"maxWatts\"],\n];\n\nfunction getProperties(node: Element, attributeNames: PropertyMapping) {\n const properties = [];\n\n for (const [tag, alias] of attributeNames) {\n let elem = get1(node, tag);\n if (!elem) {\n const elements = node.getElementsByTagNameNS(EXTENSIONS_NS, tag);\n if (elements.length) {\n elem = elements[0];\n }\n }\n const val = parseFloat(nodeVal(elem));\n if (!isNaN(val)) {\n properties.push([alias, val]);\n }\n }\n\n return properties;\n}\n\nfunction coordPair(node: Element) {\n const ll = [num1(node, \"LongitudeDegrees\"), num1(node, \"LatitudeDegrees\")];\n if (\n ll[0] === undefined ||\n isNaN(ll[0]) ||\n ll[1] === undefined ||\n isNaN(ll[1])\n ) {\n return null;\n }\n const heartRate = get1(node, \"HeartRateBpm\");\n const time = nodeVal(get1(node, \"Time\"));\n get1(node, \"AltitudeMeters\", (alt) => {\n const a = parseFloat(nodeVal(alt));\n if (!isNaN(a)) {\n ll.push(a);\n }\n });\n return {\n coordinates: ll as number[],\n time: time || null,\n heartRate: heartRate ? parseFloat(nodeVal(heartRate)) : null,\n extensions: getProperties(node, TRACKPOINT_ATTRIBUTES),\n };\n}\n\nfunction getPoints(node: Element) {\n const pts = $(node, \"Trackpoint\");\n const line: Position[] = [];\n const times = [];\n const heartRates = [];\n if (pts.length < 2) return null; // Invalid line in GeoJSON\n const extendedProperties: P = {};\n const result = { extendedProperties };\n for (let i = 0; i < pts.length; i++) {\n const c = coordPair(pts[i]);\n if (c === null) continue;\n line.push(c.coordinates);\n const { time, heartRate, extensions } = c;\n if (time) times.push(time);\n if (heartRate) heartRates.push(heartRate);\n for (const [alias, value] of extensions) {\n if (!extendedProperties[alias]) {\n extendedProperties[alias] = Array(pts.length).fill(null);\n }\n extendedProperties[alias][i] = value;\n }\n }\n if (line.length < 2) return null;\n return Object.assign(result, {\n line: line,\n times: times,\n heartRates: heartRates,\n });\n}\n\nfunction getLap(node: Element): Feature | null {\n const segments = $(node, \"Track\");\n const track = [];\n const times = [];\n const heartRates = [];\n const allExtendedProperties = [];\n let line;\n const properties: P = Object.assign(\n Object.fromEntries(getProperties(node, LAP_ATTRIBUTES)),\n get(node, \"Name\", (nameElement) => {\n return { name: nodeVal(nameElement) };\n })\n );\n\n for (const segment of segments) {\n line = getPoints(segment);\n if (line) {\n track.push(line.line);\n if (line.times.length) times.push(line.times);\n if (line.heartRates.length) heartRates.push(line.heartRates);\n allExtendedProperties.push(line.extendedProperties);\n }\n }\n for (let i = 0; i < allExtendedProperties.length; i++) {\n const extendedProperties = allExtendedProperties[i];\n for (const property in extendedProperties) {\n if (segments.length === 1) {\n if (line) {\n properties[property] = line.extendedProperties[property];\n }\n } else {\n if (!properties[property]) {\n properties[property] = track.map((track) =>\n Array(track.length).fill(null)\n );\n }\n properties[property][i] = extendedProperties[property];\n }\n }\n }\n\n if (track.length === 0) return null;\n\n if (times.length || heartRates.length) {\n properties.coordinateProperties = Object.assign(\n times.length\n ? {\n times: track.length === 1 ? times[0] : times,\n }\n : {},\n heartRates.length\n ? {\n heart: track.length === 1 ? heartRates[0] : heartRates,\n }\n : {}\n );\n }\n\n return {\n type: \"Feature\",\n properties: properties,\n geometry:\n track.length === 1\n ? {\n type: \"LineString\",\n coordinates: track[0],\n }\n : {\n type: \"MultiLineString\",\n coordinates: track,\n },\n };\n}\n\n/**\n * Incrementally convert a TCX document to GeoJSON. The\n * first argument, `doc`, must be a TCX\n * document as an XML DOM - not as a string.\n */\nexport function* tcxGen(node: Document): Generator {\n for (const lap of $(node, \"Lap\")) {\n const feature = getLap(lap);\n if (feature) yield feature;\n }\n\n for (const course of $(node, \"Courses\")) {\n const feature = getLap(course);\n if (feature) yield feature;\n }\n}\n\n/**\n * Convert a TCX document to GeoJSON. The first argument, `doc`, must be a TCX\n * document as an XML DOM - not as a string.\n */\nexport function tcx(node: Document): FeatureCollection {\n return {\n type: \"FeatureCollection\",\n features: Array.from(tcxGen(node)),\n };\n}\n","import { P } from \"../shared\";\n\nexport function fixColor(v: string, prefix: string): P {\n const properties: P = {};\n const colorProp =\n prefix == \"stroke\" || prefix === \"fill\" ? prefix : prefix + \"-color\";\n if (v[0] === \"#\") {\n v = v.substring(1);\n }\n if (v.length === 6 || v.length === 3) {\n properties[colorProp] = \"#\" + v;\n } else if (v.length === 8) {\n properties[prefix + \"-opacity\"] = parseInt(v.substring(0, 2), 16) / 255;\n properties[colorProp] =\n \"#\" + v.substring(6, 8) + v.substring(4, 6) + v.substring(2, 4);\n }\n return properties;\n}\n","import { P, get, num1, nodeVal, val1 } from \"../shared\";\nimport { fixColor } from \"./fixColor\";\n\nfunction numericProperty(node: Element, source: string, target: string): P {\n const properties: P = {};\n num1(node, source, (val) => {\n properties[target] = val;\n });\n return properties;\n}\n\nfunction getColor(node: Element, output: string): P {\n return get(node, \"color\", (elem) => fixColor(nodeVal(elem), output));\n}\n\nexport function extractIconHref(node: Element) {\n return get(node, \"Icon\", (icon, properties) => {\n val1(icon, \"href\", (href) => {\n properties.icon = href;\n });\n return properties;\n });\n}\n\nexport function extractIcon(node: Element) {\n return get(node, \"IconStyle\", (iconStyle) => {\n return Object.assign(\n getColor(iconStyle, \"icon\"),\n numericProperty(iconStyle, \"scale\", \"icon-scale\"),\n numericProperty(iconStyle, \"heading\", \"icon-heading\"),\n get(iconStyle, \"hotSpot\", (hotspot) => {\n const left = parseFloat(hotspot.getAttribute(\"x\") || \"\");\n const top = parseFloat(hotspot.getAttribute(\"y\") || \"\");\n const xunits = hotspot.getAttribute(\"xunits\") || \"\";\n const yunits = hotspot.getAttribute(\"yunits\") || \"\";\n if (!isNaN(left) && !isNaN(top))\n return {\n \"icon-offset\": [left, top],\n \"icon-offset-units\": [xunits, yunits],\n };\n return {};\n }),\n extractIconHref(iconStyle)\n );\n });\n}\n\nexport function extractLabel(node: Element) {\n return get(node, \"LabelStyle\", (labelStyle) => {\n return Object.assign(\n getColor(labelStyle, \"label\"),\n numericProperty(labelStyle, \"scale\", \"label-scale\")\n );\n });\n}\n\nexport function extractLine(node: Element) {\n return get(node, \"LineStyle\", (lineStyle) => {\n return Object.assign(\n getColor(lineStyle, \"stroke\"),\n numericProperty(lineStyle, \"width\", \"stroke-width\")\n );\n });\n}\n\nexport function extractPoly(node: Element) {\n return get(node, \"PolyStyle\", (polyStyle, properties) => {\n return Object.assign(\n properties,\n get(polyStyle, \"color\", (elem) => fixColor(nodeVal(elem), \"fill\")),\n val1(polyStyle, \"fill\", (fill) => {\n if (fill === \"0\") return { \"fill-opacity\": 0 };\n }),\n val1(polyStyle, \"outline\", (outline) => {\n if (outline === \"0\") return { \"stroke-opacity\": 0 };\n })\n );\n });\n}\n\nexport function extractStyle(node: Element) {\n return Object.assign(\n {},\n extractPoly(node),\n extractLine(node),\n extractLabel(node),\n extractIcon(node)\n );\n}\n","import {\n get,\n get1,\n nodeVal,\n $,\n normalizeId,\n P,\n StyleMap,\n val1,\n} from \"../shared\";\n\nexport type TypeConverter = (x: string) => unknown;\nexport type Schema = { [key: string]: TypeConverter };\n\nconst toNumber: TypeConverter = (x) => Number(x);\nexport const typeConverters: Record = {\n string: (x) => x,\n int: toNumber,\n uint: toNumber,\n short: toNumber,\n ushort: toNumber,\n float: toNumber,\n double: toNumber,\n bool: (x) => Boolean(x),\n};\n\nexport function extractExtendedData(node: Element, schema: Schema) {\n return get(node, \"ExtendedData\", (extendedData, properties) => {\n for (const data of $(extendedData, \"Data\")) {\n properties[data.getAttribute(\"name\") || \"\"] = nodeVal(\n get1(data, \"value\")\n );\n }\n for (const simpleData of $(extendedData, \"SimpleData\")) {\n const name = simpleData.getAttribute(\"name\") || \"\";\n const typeConverter = schema[name] || typeConverters.string;\n properties[name] = typeConverter(nodeVal(simpleData));\n }\n return properties;\n });\n}\n\nexport function getMaybeHTMLDescription(node: Element) {\n const descriptionNode = get1(node, \"description\");\n for (const c of Array.from(descriptionNode?.childNodes || [])) {\n if (c.nodeType === 4) {\n return {\n description: {\n \"@type\": \"html\",\n value: nodeVal(c as Element),\n },\n };\n }\n }\n return {};\n}\n\nexport function extractTimeSpan(node: Element): P {\n return get(node, \"TimeSpan\", (timeSpan) => {\n return {\n timespan: {\n begin: nodeVal(get1(timeSpan, \"begin\")),\n end: nodeVal(get1(timeSpan, \"end\")),\n },\n };\n });\n}\n\nexport function extractTimeStamp(node: Element): P {\n return get(node, \"TimeStamp\", (timeStamp) => {\n return { timestamp: nodeVal(get1(timeStamp, \"when\")) };\n });\n}\n\nexport function extractCascadedStyle(node: Element, styleMap: StyleMap): P {\n return val1(node, \"styleUrl\", (styleUrl) => {\n styleUrl = normalizeId(styleUrl);\n if (styleMap[styleUrl]) {\n return Object.assign({ styleUrl }, styleMap[styleUrl]);\n }\n // For backward-compatibility. Should we still include\n // styleUrl even if it's not resolved?\n return { styleUrl };\n });\n}\n","import { Position, Point, LineString, Geometry } from \"geojson\";\nimport { $, $ns, nodeVal, get1, isElement } from \"../shared\";\n\nconst removeSpace = /\\s*/g;\nconst trimSpace = /^\\s*|\\s*$/g;\nconst splitSpace = /\\s+/;\n\n/**\n * Get one coordinate from a coordinate array, if any\n */\nexport function coord1(value: string): Position {\n return value\n .replace(removeSpace, \"\")\n .split(\",\")\n .map(parseFloat)\n .filter((num) => !isNaN(num))\n .slice(0, 3);\n}\n\n/**\n * Get all coordinates from a coordinate array as [[],[]]\n */\nexport function coord(value: string): Position[] {\n return value\n .replace(trimSpace, \"\")\n .split(splitSpace)\n .map(coord1)\n .filter((coord) => {\n return coord.length >= 2;\n });\n}\n\nfunction gxCoords(\n node: Element\n): { geometry: Point | LineString; times: string[] } | null {\n let elems = $(node, \"coord\");\n if (elems.length === 0) {\n elems = $ns(node, \"coord\", \"*\");\n }\n\n const coordinates = elems.map((elem) => {\n return nodeVal(elem).split(\" \").map(parseFloat);\n });\n\n if (coordinates.length === 0) {\n return null;\n }\n\n return {\n geometry:\n coordinates.length > 2\n ? {\n type: \"LineString\",\n coordinates,\n }\n : {\n type: \"Point\",\n coordinates: coordinates[0],\n },\n times: $(node, \"when\").map((elem) => nodeVal(elem)),\n };\n}\n\nexport function fixRing(ring: Position[]) {\n if (ring.length === 0) return ring;\n const first = ring[0];\n const last = ring[ring.length - 1];\n let equal = true;\n for (let i = 0; i < Math.max(first.length, last.length); i++) {\n if (first[i] !== last[i]) {\n equal = false;\n break;\n }\n }\n if (!equal) {\n return ring.concat([ring[0]]);\n }\n return ring;\n}\n\nexport function getCoordinates(node: Element) {\n return nodeVal(get1(node, \"coordinates\"));\n}\n\ninterface GeometriesAndTimes {\n geometries: Geometry[];\n coordTimes: string[][];\n}\n\nexport function getGeometry(node: Element): GeometriesAndTimes {\n let geometries: Geometry[] = [];\n let coordTimes: string[][] = [];\n\n for (let i = 0; i < node.childNodes.length; i++) {\n const child = node.childNodes.item(i);\n if (isElement(child)) {\n switch (child.tagName) {\n case \"MultiGeometry\":\n case \"MultiTrack\":\n case \"gx:MultiTrack\": {\n const childGeometries = getGeometry(child);\n geometries = geometries.concat(childGeometries.geometries);\n coordTimes = coordTimes.concat(childGeometries.coordTimes);\n break;\n }\n\n case \"Point\": {\n const coordinates = coord1(getCoordinates(child));\n if (coordinates.length >= 2) {\n geometries.push({\n type: \"Point\",\n coordinates,\n });\n }\n break;\n }\n case \"LinearRing\":\n case \"LineString\": {\n const coordinates = coord(getCoordinates(child));\n if (coordinates.length >= 2) {\n geometries.push({\n type: \"LineString\",\n coordinates,\n });\n }\n break;\n }\n case \"Polygon\": {\n const coords = [];\n for (const linearRing of $(child, \"LinearRing\")) {\n const ring = fixRing(coord(getCoordinates(linearRing)));\n if (ring.length >= 4) {\n coords.push(ring);\n }\n }\n if (coords.length) {\n geometries.push({\n type: \"Polygon\",\n coordinates: coords,\n });\n }\n break;\n }\n case \"Track\":\n case \"gx:Track\": {\n const gx = gxCoords(child);\n if (!gx) break;\n const { times, geometry } = gx;\n geometries.push(geometry);\n if (times.length) coordTimes.push(times);\n break;\n }\n }\n }\n }\n\n return {\n geometries,\n coordTimes,\n };\n}\n","import { Feature, Geometry } from \"geojson\";\nimport { StyleMap, getMulti } from \"../shared\";\nimport {\n extractCascadedStyle,\n extractExtendedData,\n extractTimeSpan,\n extractTimeStamp,\n getMaybeHTMLDescription,\n Schema,\n} from \"./shared\";\nimport { extractStyle } from \"./extractStyle\";\nimport { getGeometry } from \"./geometry\";\nimport { KMLOptions } from \"lib/kml\";\n\nfunction geometryListToGeometry(geometries: Geometry[]): Geometry | null {\n return geometries.length === 0\n ? null\n : geometries.length === 1\n ? geometries[0]\n : {\n type: \"GeometryCollection\",\n geometries,\n };\n}\n\nexport function getPlacemark(\n node: Element,\n styleMap: StyleMap,\n schema: Schema,\n options: KMLOptions\n): Feature | null {\n const { coordTimes, geometries } = getGeometry(node);\n\n const geometry = geometryListToGeometry(geometries);\n\n if (!geometry && options.skipNullGeometry) {\n return null;\n }\n\n const feature: Feature = {\n type: \"Feature\",\n geometry,\n properties: Object.assign(\n getMulti(node, [\n \"name\",\n \"address\",\n \"visibility\",\n \"open\",\n \"phoneNumber\",\n \"description\",\n ]),\n getMaybeHTMLDescription(node),\n extractCascadedStyle(node, styleMap),\n extractStyle(node),\n extractExtendedData(node, schema),\n extractTimeSpan(node),\n extractTimeStamp(node),\n coordTimes.length\n ? {\n coordinateProperties: {\n times: coordTimes.length === 1 ? coordTimes[0] : coordTimes,\n },\n }\n : {}\n ),\n };\n\n if (feature.properties?.visibility !== undefined) {\n feature.properties.visibility = feature.properties.visibility !== \"0\";\n }\n\n const id = node.getAttribute(\"id\");\n if (id !== null && id !== \"\") feature.id = id;\n return feature;\n}\n","import { Feature, Polygon } from \"geojson\";\nimport { StyleMap, get1, num1, getMulti } from \"../shared\";\nimport {\n extractCascadedStyle,\n extractExtendedData,\n extractTimeSpan,\n extractTimeStamp,\n getMaybeHTMLDescription,\n Schema,\n} from \"./shared\";\nimport { extractIconHref, extractStyle } from \"./extractStyle\";\nimport { coord, fixRing, getCoordinates } from \"./geometry\";\nimport { KMLOptions } from \"lib/kml\";\n\ninterface BoxGeometry {\n bbox?: BBox;\n geometry: Polygon;\n}\n\nfunction getGroundOverlayBox(node: Element): BoxGeometry | null {\n const latLonQuad = get1(node, \"gx:LatLonQuad\");\n\n if (latLonQuad) {\n const ring = fixRing(coord(getCoordinates(node)));\n return {\n geometry: {\n type: \"Polygon\",\n coordinates: [ring],\n },\n };\n }\n\n return getLatLonBox(node);\n}\n\ntype BBox = [number, number, number, number];\n\nconst DEGREES_TO_RADIANS = Math.PI / 180;\n\nfunction rotateBox(\n bbox: BBox,\n coordinates: Polygon[\"coordinates\"],\n rotation: number\n): Polygon[\"coordinates\"] {\n const center = [(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2];\n\n return [\n coordinates[0].map((coordinate) => {\n const dy = coordinate[1] - center[1];\n const dx = coordinate[0] - center[0];\n const distance = Math.sqrt(Math.pow(dy, 2) + Math.pow(dx, 2));\n const angle = Math.atan2(dy, dx) + rotation * DEGREES_TO_RADIANS;\n\n return [\n center[0] + Math.cos(angle) * distance,\n center[1] + Math.sin(angle) * distance,\n ];\n }),\n ];\n}\n\nfunction getLatLonBox(node: Element): BoxGeometry | null {\n const latLonBox = get1(node, \"LatLonBox\");\n\n if (latLonBox) {\n const north = num1(latLonBox, \"north\");\n const west = num1(latLonBox, \"west\");\n const east = num1(latLonBox, \"east\");\n const south = num1(latLonBox, \"south\");\n const rotation = num1(latLonBox, \"rotation\");\n\n if (\n typeof north === \"number\" &&\n typeof south === \"number\" &&\n typeof west === \"number\" &&\n typeof east === \"number\"\n ) {\n const bbox: BBox = [west, south, east, north];\n let coordinates = [\n [\n [west, north], // top left\n [east, north], // top right\n [east, south], // top right\n [west, south], // bottom left\n [west, north], // top left (again)\n ],\n ];\n if (typeof rotation === \"number\") {\n coordinates = rotateBox(bbox, coordinates, rotation);\n }\n return {\n bbox,\n geometry: {\n type: \"Polygon\",\n coordinates,\n },\n };\n }\n }\n\n return null;\n}\n\nexport function getGroundOverlay(\n node: Element,\n styleMap: StyleMap,\n schema: Schema,\n options: KMLOptions\n): Feature | null {\n const box = getGroundOverlayBox(node);\n\n const geometry = box?.geometry || null;\n\n if (!geometry && options.skipNullGeometry) {\n return null;\n }\n\n const feature: Feature = {\n type: \"Feature\",\n geometry,\n properties: Object.assign(\n /**\n * Related to\n * https://gist.github.com/tmcw/037a1cb6660d74a392e9da7446540f46\n */\n { \"@geometry-type\": \"groundoverlay\" },\n getMulti(node, [\n \"name\",\n \"address\",\n \"visibility\",\n \"open\",\n \"phoneNumber\",\n \"description\",\n ]),\n getMaybeHTMLDescription(node),\n extractCascadedStyle(node, styleMap),\n extractStyle(node),\n extractIconHref(node),\n extractExtendedData(node, schema),\n extractTimeSpan(node),\n extractTimeStamp(node)\n ),\n };\n\n if (box?.bbox) {\n feature.bbox = box.bbox;\n }\n\n if (feature.properties?.visibility !== undefined) {\n feature.properties.visibility = feature.properties.visibility !== \"0\";\n }\n\n const id = node.getAttribute(\"id\");\n if (id !== null && id !== \"\") feature.id = id;\n return feature;\n}\n","import { extractStyle } from \"./kml/extractStyle\";\nimport { getPlacemark } from \"./kml/placemark\";\nimport { getGroundOverlay } from \"./kml/ground_overlay\";\nimport { FeatureCollection, Geometry } from \"geojson\";\nimport {\n $,\n StyleMap,\n P,\n F,\n val1,\n nodeVal,\n isElement,\n normalizeId,\n} from \"./shared\";\nimport { Schema, typeConverters } from \"./kml/shared\";\n\n/**\n * Options to customize KML output.\n *\n * The only option currently\n * is `skipNullGeometry`. Both the KML and GeoJSON formats support\n * the idea of features that don't have geometries: in KML,\n * this is a Placemark without a Point, etc element, and in GeoJSON\n * it's a geometry member with a value of `null`.\n *\n * toGeoJSON, by default, translates null geometries in KML to\n * null geometries in GeoJSON. For systems that use GeoJSON but\n * don't support null geometries, you can specify `skipNullGeometry`\n * to omit these features entirely and only include\n * features that have a geometry defined.\n */\nexport interface KMLOptions {\n skipNullGeometry?: boolean;\n}\n\n/**\n * A folder including metadata. Folders\n * may contain other folders or features,\n * or nothing at all.\n */\nexport interface Folder {\n type: \"folder\";\n /**\n * Standard values:\n *\n * * \"name\",\n * * \"visibility\",\n * * \"open\",\n * * \"address\",\n * * \"description\",\n * * \"phoneNumber\",\n * * \"visibility\",\n */\n meta: {\n [key: string]: unknown;\n };\n children: Array;\n}\n\n/**\n * A nested folder structure, represented\n * as a tree with folders and features.\n */\nexport interface Root {\n type: \"root\";\n children: Array;\n}\n\ntype TreeContainer = Root | Folder;\n\nfunction getStyleId(style: Element) {\n let id = style.getAttribute(\"id\");\n const parentNode = style.parentNode;\n if (\n !id &&\n isElement(parentNode) &&\n parentNode.localName === \"CascadingStyle\"\n ) {\n id = parentNode.getAttribute(\"kml:id\") || parentNode.getAttribute(\"id\");\n }\n return normalizeId(id || \"\");\n}\n\nfunction buildStyleMap(node: Document): StyleMap {\n const styleMap: StyleMap = {};\n for (const style of $(node, \"Style\")) {\n styleMap[getStyleId(style)] = extractStyle(style);\n }\n for (const map of $(node, \"StyleMap\")) {\n const id = normalizeId(map.getAttribute(\"id\") || \"\");\n val1(map, \"styleUrl\", (styleUrl) => {\n styleUrl = normalizeId(styleUrl);\n if (styleMap[styleUrl]) {\n styleMap[id] = styleMap[styleUrl];\n }\n });\n }\n return styleMap;\n}\n\nfunction buildSchema(node: Document): Schema {\n const schema: Schema = {};\n for (const field of $(node, \"SimpleField\")) {\n schema[field.getAttribute(\"name\") || \"\"] =\n typeConverters[field.getAttribute(\"type\") || \"\"] ||\n typeConverters[\"string\"];\n }\n return schema;\n}\n\nconst FOLDER_PROPS = [\n \"name\",\n \"visibility\",\n \"open\",\n \"address\",\n \"description\",\n \"phoneNumber\",\n \"visibility\",\n] as const;\n\nfunction getFolder(node: Element): Folder {\n const meta: P = {};\n\n for (const child of Array.from(node.childNodes)) {\n if (isElement(child) && FOLDER_PROPS.includes(child.tagName as any)) {\n meta[child.tagName] = nodeVal(child);\n }\n }\n\n return {\n type: \"folder\",\n meta,\n children: [],\n };\n}\n\n/**\n * Yield a nested tree with KML folder structure\n *\n * This generates a tree with the given structure:\n *\n * ```js\n * {\n * \"type\": \"root\",\n * \"children\": [\n * {\n * \"type\": \"folder\",\n * \"meta\": {\n * \"name\": \"Test\"\n * },\n * \"children\": [\n * // ...features and folders\n * ]\n * }\n * // ...features\n * ]\n * }\n * ```\n *\n * ### GroundOverlay\n *\n * GroundOverlay elements are converted into\n * `Feature` objects with `Polygon` geometries,\n * a property like:\n *\n * ```json\n * {\n * \"@geometry-type\": \"groundoverlay\"\n * }\n * ```\n *\n * And the ground overlay's image URL in the `href`\n * property. Ground overlays will need to be displayed\n * with a separate method to other features, depending\n * on which map framework you're using.\n */\nexport function kmlWithFolders(\n node: Document,\n options: KMLOptions = {\n skipNullGeometry: false,\n }\n): Root {\n const styleMap = buildStyleMap(node);\n const schema = buildSchema(node);\n\n // atomic geospatial types supported by KML - MultiGeometry is\n // handled separately\n // all root placemarks in the file\n const placemarks = [];\n const tree: Root = { type: \"root\", children: [] };\n\n function traverse(\n node: Document | ChildNode | Element,\n pointer: TreeContainer,\n options: KMLOptions\n ) {\n if (isElement(node)) {\n switch (node.tagName) {\n case \"GroundOverlay\": {\n placemarks.push(node);\n const placemark = getGroundOverlay(node, styleMap, schema, options);\n if (placemark) {\n pointer.children.push(placemark);\n }\n break;\n }\n case \"Placemark\": {\n placemarks.push(node);\n const placemark = getPlacemark(node, styleMap, schema, options);\n if (placemark) {\n pointer.children.push(placemark);\n }\n break;\n }\n case \"Folder\": {\n const folder = getFolder(node);\n pointer.children.push(folder);\n pointer = folder;\n break;\n }\n }\n }\n\n if (node.childNodes) {\n for (let i = 0; i < node.childNodes.length; i++) {\n traverse(node.childNodes[i], pointer, options);\n }\n }\n }\n\n traverse(node, tree, options);\n\n return tree;\n}\n\n/**\n * Convert KML to GeoJSON incrementally, returning\n * a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators)\n * that yields output feature by feature.\n */\nexport function* kmlGen(\n node: Document,\n options: KMLOptions = {\n skipNullGeometry: false,\n }\n): Generator {\n const styleMap = buildStyleMap(node);\n const schema = buildSchema(node);\n for (const placemark of $(node, \"Placemark\")) {\n const feature = getPlacemark(placemark, styleMap, schema, options);\n if (feature) yield feature;\n }\n for (const groundOverlay of $(node, \"GroundOverlay\")) {\n const feature = getGroundOverlay(groundOverlay, styleMap, schema, options);\n if (feature) yield feature;\n }\n}\n\n/**\n * Convert a KML document to GeoJSON. The first argument, `doc`, must be a KML\n * document as an XML DOM - not as a string. You can get this using jQuery's default\n * `.ajax` function or using a bare XMLHttpRequest with the `.response` property\n * holding an XML DOM.\n *\n * The output is a JavaScript object of GeoJSON data. You can convert it to a string\n * with [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)\n * or use it directly in libraries.\n */\nexport function kml(\n node: Document,\n options: KMLOptions = {\n skipNullGeometry: false,\n }\n): FeatureCollection {\n return {\n type: \"FeatureCollection\",\n features: Array.from(kmlGen(node, options)),\n };\n}\n"],"names":["$","element","tagName","Array","from","getElementsByTagName","normalizeId","id","nodeVal","node","normalize","textContent","get1","callback","n","result","length","get","properties","val1","val","$num","parseFloat","isNaN","num1","getMulti","propertyNames","property","isElement","nodeType","getLineStyle","lineStyle","Object","assign","color","stroke","opacity","width","getExtensions","values","child","childNodes","name","abbreviateName","nodeName","concat","push","parseNumeric","includes","num","coordPair","ll","getAttribute","time","coordinates","extendedValues","extractProperties","extensions","getElementsByTagNameNS","parentNode","replace","links","map","link","href","getPoints","pointname","pts","line","times","i","c","plural","fill","getRoute","type","_gpxType","geometry","getTrack","segments","track","extractedLines","segment","multi","coordinateProperties","props","entries","getPoint","pair","gpxGen","feature","route","waypoint","point","TRACKPOINT_ATTRIBUTES","LAP_ATTRIBUTES","getProperties","attributeNames","tag","alias","elem","elements","undefined","heartRate","alt","a","heartRates","extendedProperties","value","getLap","allExtendedProperties","fromEntries","nameElement","heart","tcxGen","lap","course","fixColor","v","prefix","colorProp","substring","parseInt","numericProperty","source","target","getColor","output","extractIconHref","icon","extractStyle","polyStyle","outline","extractPoly","extractLine","labelStyle","extractLabel","iconStyle","hotspot","left","top","xunits","yunits","extractIcon","toNumber","x","Number","typeConverters","string","int","uint","short","ushort","float","double","bool","Boolean","extractExtendedData","schema","extendedData","data","simpleData","typeConverter","getMaybeHTMLDescription","descriptionNode","description","extractTimeSpan","timeSpan","timespan","begin","end","extractTimeStamp","timeStamp","timestamp","extractCascadedStyle","styleMap","styleUrl","removeSpace","trimSpace","splitSpace","coord1","split","filter","slice","coord","gxCoords","elems","ns","fixRing","ring","first","last","equal","Math","max","getCoordinates","getGeometry","geometries","coordTimes","item","childGeometries","coords","linearRing","gx","getPlacemark","options","geometryListToGeometry","skipNullGeometry","visibility","getGroundOverlayBox","latLonBox","north","west","east","south","rotation","bbox","center","coordinate","dy","dx","distance","sqrt","pow","angle","atan2","DEGREES_TO_RADIANS","cos","sin","rotateBox","getLatLonBox","PI","getGroundOverlay","box","getStyleId","style","localName","buildStyleMap","buildSchema","field","FOLDER_PROPS","kmlGen","placemark","groundOverlay","features","tree","children","traverse","pointer","folder","meta","getFolder"],"mappings":"iPAEgB,SAAAA,EAAEC,EAA6BC,GAC7C,OAAOC,MAAMC,KAAKH,EAAQI,qBAAqBH,IAQ3C,SAAUI,EAAYC,GAC1B,MAAiB,MAAVA,EAAG,GAAaA,EAAK,IAAIA,IAc5B,SAAUC,EAAQC,GAEtB,OADAA,GAAMC,YACED,GAAQA,EAAKE,aAAgB,YAMvBC,EACdH,EACAP,EACAW,GAEA,MAAMC,EAAIL,EAAKJ,qBAAqBH,GAC9Ba,EAASD,EAAEE,OAASF,EAAE,GAAK,KAEjC,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