UNPKG

@loaders.gl/kml

Version:

Framework-independent loader for the KML format

182 lines (177 loc) 5.53 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // dist/index.js var dist_exports = {}; __export(dist_exports, { GPXLoader: () => GPXLoader, KMLLoader: () => KMLLoader, TCXLoader: () => TCXLoader }); module.exports = __toCommonJS(dist_exports); // dist/gpx-loader.js var import_gis = require("@loaders.gl/gis"); var import_togeojson = require("@tmcw/togeojson"); var import_xmldom = require("@xmldom/xmldom"); var VERSION = true ? "4.3.2" : "latest"; var GPX_HEADER = `<?xml version="1.0" encoding="UTF-8"?> <gpx`; var GPXLoader = { dataType: null, batchType: null, name: "GPX (GPS exchange format)", id: "gpx", module: "kml", version: VERSION, extensions: ["gpx"], mimeTypes: ["application/gpx+xml"], text: true, tests: [GPX_HEADER], parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options), parseTextSync, options: { gpx: { shape: "geojson-table" }, gis: {} } }; function parseTextSync(text, options) { const doc = new import_xmldom.DOMParser().parseFromString(text, "text/xml"); const geojson = (0, import_togeojson.gpx)(doc); const gpxOptions = { ...GPXLoader.options.gpx, ...options == null ? void 0 : options.gpx }; switch (gpxOptions.shape) { case "object-row-table": { const table = { shape: "object-row-table", data: geojson.features }; return table; } case "geojson-table": { const table = { shape: "geojson-table", type: "FeatureCollection", features: geojson.features }; return table; } case "binary": return (0, import_gis.geojsonToBinary)(geojson.features); default: throw new Error(gpxOptions.shape); } } // dist/kml-loader.js var import_togeojson2 = require("@tmcw/togeojson"); var import_xmldom2 = require("@xmldom/xmldom"); var VERSION2 = true ? "4.3.2" : "latest"; var KML_HEADER = `<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2">`; var KMLLoader = { dataType: null, batchType: null, name: "KML (Keyhole Markup Language)", id: "kml", module: "kml", version: VERSION2, extensions: ["kml"], mimeTypes: ["application/vnd.google-earth.kml+xml"], text: true, tests: [KML_HEADER], parse: async (arrayBuffer, options) => parseTextSync2(new TextDecoder().decode(arrayBuffer), options), parseTextSync: parseTextSync2, options: { kml: { shape: "geojson-table" }, gis: {} } }; function parseTextSync2(text, options) { const doc = new import_xmldom2.DOMParser().parseFromString(text, "text/xml"); const geojson = (0, import_togeojson2.kml)(doc); const kmlOptions = { ...KMLLoader.options.kml, ...options == null ? void 0 : options.kml }; switch (kmlOptions.shape) { case "geojson-table": { const table2 = { shape: "geojson-table", type: "FeatureCollection", features: geojson.features }; return table2; } case "object-row-table": const table = { shape: "object-row-table", data: geojson.features }; return table; default: throw new Error(kmlOptions.shape); } } // dist/tcx-loader.js var import_gis2 = require("@loaders.gl/gis"); var import_togeojson3 = require("@tmcw/togeojson"); var import_xmldom3 = require("@xmldom/xmldom"); var VERSION3 = true ? "4.3.2" : "latest"; var TCX_HEADER = `<?xml version="1.0" encoding="UTF-8"?> <TrainingCenterDatabase`; var TCXLoader = { dataType: null, batchType: null, name: "TCX (Training Center XML)", id: "tcx", module: "kml", version: VERSION3, extensions: ["tcx"], mimeTypes: ["application/vnd.garmin.tcx+xml"], text: true, tests: [TCX_HEADER], parse: async (arrayBuffer, options) => parseTextSync3(new TextDecoder().decode(arrayBuffer), options), parseTextSync: parseTextSync3, options: { tcx: { shape: "geojson-table" }, gis: {} } }; function parseTextSync3(text, options) { const doc = new import_xmldom3.DOMParser().parseFromString(text, "text/xml"); const geojson = (0, import_togeojson3.tcx)(doc); const tcxOptions = { ...TCXLoader.options.tcx, ...options == null ? void 0 : options.tcx }; switch (tcxOptions.shape) { case "object-row-table": { const table = { shape: "object-row-table", data: geojson.features }; return table; } case "geojson-table": { const table = { shape: "geojson-table", type: "FeatureCollection", schema: { metadata: {}, fields: [] }, features: geojson.features }; return table; } case "binary": return (0, import_gis2.geojsonToBinary)(geojson.features); default: throw new Error(tcxOptions.shape); } } //# sourceMappingURL=index.cjs.map