UNPKG

@tmcw/togeojson

Version:
1 lines 85.6 kB
{"version":3,"file":"togeojson.cjs","sources":["../lib/lib/shared.ts","../lib/lib/gpx/extensions.ts","../lib/lib/gpx/coord_pair.ts","../lib/lib/gpx/line.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/geometry.ts","../lib/lib/kml/shared.ts","../lib/lib/kml/ground_overlay.ts","../lib/lib/kml/networklink.ts","../lib/lib/kml/placemark.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<Feature[\"properties\"]>;\nexport type F = Feature<Geometry | null>;\n\nexport type StyleMap = { [key: string]: P };\n\nexport type NS = [string, string][];\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?.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 | undefined | 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 = Number.parseFloat(nodeVal(get1(node, tagName)));\n if (Number.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 = Number.parseFloat(nodeVal(get1(node, tagName)));\n if (Number.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 { 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 = Number.parseFloat(val);\n return Number.isNaN(num) ? val : num;\n}\n","import type { Position } from \"geojson\";\nimport { get1, nodeVal, num1 } from \"../shared\";\nimport { type 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 Number.parseFloat(node.getAttribute(\"lon\") || \"\"),\n Number.parseFloat(node.getAttribute(\"lat\") || \"\"),\n ];\n\n if (Number.isNaN(ll[0]) || Number.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 { $num, type P, get, val1 } 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 { $, type NS, getMulti, nodeVal } from \"../shared\";\n\nexport function extractProperties(ns: NS, node: Element) {\n const properties = getMulti(node, [\n \"name\",\n \"cmt\",\n \"desc\",\n \"type\",\n \"time\",\n \"keywords\",\n ]);\n\n for (const [n, url] of ns) {\n for (const child of Array.from(node.getElementsByTagNameNS(url, \"*\"))) {\n properties[child.tagName.replace(\":\", \"_\")] = nodeVal(child)?.trim();\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 { Document as XDocument } from \"@xmldom/xmldom\";\nimport type {\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n Point,\n Position,\n} from \"geojson\";\nimport { coordPair } from \"./gpx/coord_pair\";\nimport { getLineStyle } from \"./gpx/line\";\nimport { extractProperties } from \"./gpx/properties\";\nimport { $, type NS, type 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(ns: NS, node: Element): Feature<LineString> | 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(ns, node),\n getLineStyle(get1(node, \"extensions\"))\n ),\n geometry: {\n type: \"LineString\",\n coordinates: line.line,\n },\n };\n}\n\nfunction getTrack(\n ns: NS,\n node: Element\n): Feature<LineString | MultiLineString> | 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?.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(ns, 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 (let i = 0; i < extractedLines.length; i++) {\n const line = extractedLines[i];\n track.push(line.line);\n if (!properties.coordinateProperties) {\n properties.coordinateProperties = {};\n }\n const props = properties.coordinateProperties;\n // Generally extendedValues will be things like heart\n // rate, and this is an array like { heart: [100, 101...] }\n for (const [name, val] of Object.entries(line.extendedValues)) {\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(ns: NS, node: Element): Feature<Point> | null {\n const properties: Feature[\"properties\"] = Object.assign(\n extractProperties(ns, 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 | XDocument): Generator<Feature> {\n const n = node as Document;\n const GPXX = \"gpxx\";\n const GPXX_URI = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\";\n // Namespaces\n const ns: NS = [[GPXX, GPXX_URI]];\n const attrs = n.getElementsByTagName(\"gpx\")[0]?.attributes;\n if (attrs) {\n for (const attr of Array.from(attrs)) {\n if (attr.name?.startsWith(\"xmlns:\") && attr.value !== GPXX_URI) {\n ns.push([attr.name, attr.value]);\n }\n }\n }\n\n for (const track of $(n, \"trk\")) {\n const feature = getTrack(ns, track);\n if (feature) yield feature;\n }\n\n for (const route of $(n, \"rte\")) {\n const feature = getRoute(ns, route);\n if (feature) yield feature;\n }\n\n for (const waypoint of $(n, \"wpt\")) {\n const point = getPoint(ns, 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 | XDocument): FeatureCollection {\n return {\n type: \"FeatureCollection\",\n features: Array.from(gpxGen(node)),\n };\n}\n","import type { Document as XDocument } from \"@xmldom/xmldom\";\nimport type { Feature, FeatureCollection, Position } from \"geojson\";\nimport { $, type P, get, get1, nodeVal, num1 } 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 = Number.parseFloat(nodeVal(elem));\n if (!Number.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 Number.isNaN(ll[0]) ||\n ll[1] === undefined ||\n Number.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 = Number.parseFloat(nodeVal(alt));\n if (!Number.isNaN(a)) {\n ll.push(a);\n }\n });\n return {\n coordinates: ll as number[],\n time: time || null,\n heartRate: heartRate ? Number.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: any;\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 | XDocument): Generator<Feature> {\n for (const lap of $(node as Document, \"Lap\")) {\n const feature = getLap(lap);\n if (feature) yield feature;\n }\n\n for (const course of $(node as Document, \"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 | XDocument): FeatureCollection {\n return {\n type: \"FeatureCollection\",\n features: Array.from(tcxGen(node)),\n };\n}\n","import type { 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`] =\n Number.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 { type P, get, nodeVal, num1, 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 = Number.parseFloat(hotspot.getAttribute(\"x\") || \"\");\n const top = Number.parseFloat(hotspot.getAttribute(\"y\") || \"\");\n const xunits = hotspot.getAttribute(\"xunits\") || \"\";\n const yunits = hotspot.getAttribute(\"yunits\") || \"\";\n if (!Number.isNaN(left) && !Number.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 type { Geometry, LineString, Point, Position } from \"geojson\";\nimport { $, $ns, get1, isElement, nodeVal } 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(Number.parseFloat)\n .filter((num) => !Number.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(Number.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 {\n $,\n type P,\n type StyleMap,\n get,\n get1,\n nodeVal,\n normalizeId,\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<string, TypeConverter> = {\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\nexport enum AltitudeMode {\n ABSOLUTE = \"absolute\",\n RELATIVE_TO_GROUND = \"relativeToGround\",\n CLAMP_TO_GROUND = \"clampToGround\",\n CLAMP_TO_SEAFLOOR = \"clampToSeaFloor\",\n RELATIVE_TO_SEAFLOOR = \"relativeToSeaFloor\",\n}\n\nexport function processAltitudeMode(mode: Element | null): AltitudeMode | null {\n switch (mode?.textContent) {\n case AltitudeMode.ABSOLUTE:\n return AltitudeMode.ABSOLUTE;\n case AltitudeMode.CLAMP_TO_GROUND:\n return AltitudeMode.CLAMP_TO_GROUND;\n case AltitudeMode.CLAMP_TO_SEAFLOOR:\n return AltitudeMode.CLAMP_TO_SEAFLOOR;\n case AltitudeMode.RELATIVE_TO_GROUND:\n return AltitudeMode.RELATIVE_TO_GROUND;\n case AltitudeMode.RELATIVE_TO_SEAFLOOR:\n return AltitudeMode.RELATIVE_TO_SEAFLOOR;\n default:\n break;\n }\n return null;\n}\n\nexport type BBox = [number, number, number, number];\n","import type { Feature, Polygon } from \"geojson\";\nimport type { KMLOptions } from \"lib/kml\";\nimport { type StyleMap, get1, getMulti, num1 } from \"../shared\";\nimport { extractIconHref, extractStyle } from \"./extractStyle\";\nimport { coord, fixRing, getCoordinates } from \"./geometry\";\nimport {\n type BBox,\n type Schema,\n extractCascadedStyle,\n extractExtendedData,\n extractTimeSpan,\n extractTimeStamp,\n getMaybeHTMLDescription,\n} from \"./shared\";\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\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(dy ** 2 + 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<Polygon | null> | 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<Polygon | null> = {\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 type { Feature, Polygon } from \"geojson\";\nimport type { KMLOptions } from \"lib/kml\";\nimport { type StyleMap, get1, getMulti, num1 } from \"../shared\";\nimport { extractIconHref, extractStyle } from \"./extractStyle\";\nimport {\n AltitudeMode,\n type BBox,\n type Schema,\n extractCascadedStyle,\n extractExtendedData,\n extractTimeSpan,\n extractTimeStamp,\n getMaybeHTMLDescription,\n processAltitudeMode,\n} from \"./shared\";\n\ninterface BoxGeometry {\n bbox?: BBox;\n geometry: Polygon;\n}\n\ntype LOD = [number, number | null, number | null, number | null];\ninterface IRegion {\n coordinateBox: BoxGeometry | null;\n lod: LOD | null;\n}\n\nfunction getNetworkLinkRegion(node: Element): IRegion | null {\n const region = get1(node, \"Region\");\n\n if (region) {\n return {\n coordinateBox: getLatLonAltBox(region),\n lod: getLod(node),\n };\n }\n return null;\n}\n\nfunction getLod(node: Element): LOD | null {\n const lod = get1(node, \"Lod\");\n\n if (lod) {\n return [\n num1(lod, \"minLodPixels\") ?? -1,\n num1(lod, \"maxLodPixels\") ?? -1,\n num1(lod, \"minFadeExtent\") ?? null,\n num1(lod, \"maxFadeExtent\") ?? null,\n ];\n }\n\n return null;\n}\n\nfunction getLatLonAltBox(node: Element): BoxGeometry | null {\n const latLonAltBox = get1(node, \"LatLonAltBox\");\n\n if (latLonAltBox) {\n const north = num1(latLonAltBox, \"north\");\n const west = num1(latLonAltBox, \"west\");\n const east = num1(latLonAltBox, \"east\");\n const south = num1(latLonAltBox, \"south\");\n const altitudeMode = processAltitudeMode(\n get1(latLonAltBox, \"altitudeMode\") ||\n get1(latLonAltBox, \"gx:altitudeMode\")\n );\n\n if (altitudeMode) {\n console.debug(\n \"Encountered an unsupported feature of KML for togeojson: please contact developers for support of altitude mode.\"\n );\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 const 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 return {\n bbox,\n geometry: {\n type: \"Polygon\",\n coordinates,\n },\n };\n }\n }\n\n return null;\n}\n\nfunction getLinkObject(node: Element) {\n /*\n <Link id=\"ID\">\n <!-- specific to Link -->\n <href>...</href> <!-- string -->\n <refreshMode>onChange</refreshMode>\n <!-- refreshModeEnum: onChange, onInterval, or onExpire -->\n <refreshInterval>4</refreshInterval> <!-- float -->\n <viewRefreshMode>never</viewRefreshMode>\n <!-- viewRefreshModeEnum: never, onStop, onRequest, onRegion -->\n <viewRefreshTime>4</viewRefreshTime> <!-- float -->\n <viewBoundScale>1</viewBoundScale> <!-- float -->\n <viewFormat>BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]</viewFormat>\n <!-- string -->\n <httpQuery>...</httpQuery> <!-- string -->\n </Link>\n */\n const linkObj = get1(node, \"Link\");\n\n if (linkObj) {\n return getMulti(linkObj, [\n \"href\",\n \"refreshMode\",\n \"refreshInterval\",\n \"viewRefreshMode\",\n \"viewRefreshTime\",\n \"viewBoundScale\",\n \"viewFormat\",\n \"httpQuery\",\n ]);\n }\n\n return {};\n}\n\nexport function getNetworkLink(\n node: Element,\n styleMap: StyleMap,\n schema: Schema,\n options: KMLOptions\n): Feature<Polygon | null> | null {\n const box = getNetworkLinkRegion(node);\n\n const geometry = box?.coordinateBox?.geometry || null;\n\n if (!geometry && options.skipNullGeometry) {\n return null;\n }\n\n const feature: Feature<Polygon | null> = {\n type: \"Feature\",\n geometry,\n properties: Object.assign(\n /**\n * Related to\n * https://gist.github.com/tmcw/037a1cb6660d74a392e9da7446540f46\n */\n { \"@geometry-type\": \"networklink\" },\n getMulti(node, [\n \"name\",\n \"address\",\n \"visibility\",\n \"open\",\n \"phoneNumber\",\n \"styleUrl\",\n \"refreshVisibility\",\n \"flyToView\",\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 getLinkObject(node),\n box?.lod ? { lod: box.lod } : {}\n ),\n };\n\n if (box?.coordinateBox?.bbox) {\n feature.bbox = box.coordinateBox.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 type { Feature, Geometry } from \"geojson\";\nimport type { KMLOptions } from \"lib/kml\";\nimport { type StyleMap, getMulti } from \"../shared\";\nimport { extractStyle } from \"./extractStyle\";\nimport { getGeometry } from \"./geometry\";\nimport {\n type Schema,\n extractCascadedStyle,\n extractExtendedData,\n extractTimeSpan,\n extractTimeStamp,\n getMaybeHTMLDescription,\n} from \"./shared\";\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<Geometry | null> | 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<Geometry | null> = {\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 type { Document as XDocument } from \"@xmldom/xmldom\";\nimport type { FeatureCollection, Geometry } from \"geojson\";\nimport { extractStyle } from \"./kml/extractStyle\";\nimport { getGroundOverlay } from \"./kml/ground_overlay\";\nimport { getNetworkLink } from \"./kml/networklink\";\nimport { getPlacemark } from \"./kml/placemark\";\nimport { type Schema, typeConverters } from \"./kml/shared\";\nimport {\n $,\n type F,\n type P,\n type StyleMap,\n isElement,\n nodeVal,\n normalizeId,\n val1,\n} from \"./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<Folder | F>;\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<Folder | F>;\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\") || \"\"] || 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 | XDocument,\n options: KMLOptions = {\n skipNullGeometry: false,\n }\n): Root {\n const n = node as Document;\n const styleMap = buildStyleMap(n);\n const schema = buildSchema(n);\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 networkLinks = [];\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 case \"NetworkLink\": {\n networkLinks.push(node);\n const networkLink = getNetworkLink(node, styleMap, schema, options);\n if (networkLink) {\n pointer.children.push(networkLink);\n }\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(n, 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 | XDocument,\n options: KMLOptions = {\n skipNullGeometry: false,\n }\n): Generator<F> {\n const n = node as Document;\n const styleMap = buildStyleMap(n);\n const schema = buildSchema(n);\n for (const placemark of $(n, \"Placemark\")) {\n const feature = getPlacemark(placemark, styleMap, schema, options);\n if (feature) yield feature;\n }\n for (const groundOverlay of $(n, \"GroundOverlay\")) {\n const feature = getGroundOverlay(groundOverlay, styleMap, schema, options);\n if (feature) yield feature;\n }\n for (const networkLink of $(n, \"NetworkLink\")) {\n const feature = getNetworkLink(networkLink, 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 | XDocument,\n options: KMLOptions = {\n skipNullGeometry: false,\n }\n): FeatureCollection<Geometry | null> {\n return {\n type: \"FeatureCollection\",\n features: Array.from(kmlGen(node as Document, options)),\n };\n}\n"],"names":["coordPair","getPoints"],"mappings":";;AAEgB,SAAA,CAAC,CAAC,OAA2B,EAAE,OAAe,EAAA;IAC5D,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAC1D;AASM,SAAU,WAAW,CAAC,EAAU,EAAA;AACpC,IAAA,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,EAAE,GAAG,CAAI,CAAA,EAAA,EAAE,EAAE;AACtC;SAEgB,GAAG,CACjB,OAA2B,EAC3B,OAAe,EACf,EAAU,EAAA;AAEV,IAAA,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;AAChE;AAEA;;AAEG;AACG,SAAU,OAAO,CAAC,IAAoB,EAAA;IAC1C,IAAI,EAAE,SAAS,EAAE;AACjB,IAAA,OAAO,IAAI,EAAE,WAAW,IAAI,EAAE;AAChC;AAEA;;AAEG;SACa,IAAI,CAClB,IAAa,EACb,OAAe,EACf,QAAqC,EAAA;IAErC,MAAM,CAAC,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC;AAC5C,IAAA,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IACrC,IAAI,MAAM,IAAI,QAAQ;QAAE,QAAQ,CAAC,MAAM,CAAC;AACxC,IAAA,OAAO,MAAM;AACf;SAEgB,GAAG,CACjB,IAAoB,EACpB,OAAe,EACf,QAA8C,EAAA;IAE9C,MAAM,UAAU,GAA0B,EAAE;AAC5C,IAAA,IAAI,CAAC,IAAI;AAAE,QAAA,OAAO,UAAU;IAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC;AAC5C,IAAA,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;AACrC,IAAA,IAAI,MAAM,IAAI,QAAQ,EAAE;AACtB,QAAA,OAAO,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;;AAErC,IAAA,OAAO,UAAU;AACnB;SAEgB,IAAI,CAClB,IAAa,EACb,OAAe,EACf,QAA+C,EAAA;IAE/C,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACxC,IAAI,GAAG,IAAI,QAAQ;AAAE,QAAA,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE;AAC/C,IAAA,OAAO,EAAE;AACX;SAEgB,IAAI,CAClB,IAAa,EACb,OAAe,EACf,QAAgD,EAAA;AAEhD,IAAA,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC