@loaders.gl/kml 4.0.0-alpha.5 → 4.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +3123 -375
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/gpx-loader.js +82 -0
  6. package/dist/es5/gpx-loader.js.map +1 -0
  7. package/dist/es5/index.js +27 -0
  8. package/dist/es5/index.js.map +1 -0
  9. package/dist/es5/kml-loader.js +82 -0
  10. package/dist/es5/kml-loader.js.map +1 -0
  11. package/dist/es5/tcx-loader.js +82 -0
  12. package/dist/es5/tcx-loader.js.map +1 -0
  13. package/dist/esm/bundle.js +4 -0
  14. package/dist/esm/bundle.js.map +1 -0
  15. package/dist/esm/gpx-loader.js +55 -0
  16. package/dist/esm/gpx-loader.js.map +1 -0
  17. package/dist/esm/index.js +4 -0
  18. package/dist/esm/index.js.map +1 -0
  19. package/dist/esm/kml-loader.js +55 -0
  20. package/dist/esm/kml-loader.js.map +1 -0
  21. package/dist/esm/tcx-loader.js +55 -0
  22. package/dist/esm/tcx-loader.js.map +1 -0
  23. package/dist/gpx-loader.d.ts +16 -26
  24. package/dist/gpx-loader.d.ts.map +1 -1
  25. package/dist/gpx-loader.js +58 -49
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +12 -4
  28. package/dist/kml-loader.d.ts +14 -7
  29. package/dist/kml-loader.d.ts.map +1 -1
  30. package/dist/kml-loader.js +59 -49
  31. package/dist/tcx-loader.d.ts +14 -7
  32. package/dist/tcx-loader.d.ts.map +1 -1
  33. package/dist/tcx-loader.js +60 -50
  34. package/package.json +9 -8
  35. package/src/gpx-loader.ts +35 -14
  36. package/src/index.ts +4 -0
  37. package/src/kml-loader.ts +34 -13
  38. package/src/tcx-loader.ts +34 -12
  39. package/dist/bundle.js.map +0 -1
  40. package/dist/gpx-loader.js.map +0 -1
  41. package/dist/index.js.map +0 -1
  42. package/dist/kml-loader.js.map +0 -1
  43. package/dist/tcx-loader.js.map +0 -1
@@ -1,53 +1,62 @@
1
- import { geojsonToBinary } from '@loaders.gl/gis';
2
- import { gpx } from '@tmcw/togeojson';
3
- const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
4
- const GPX_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gpx";
5
- export const GPXLoader = {
6
- name: 'GPX (GPS exchange format)',
7
- id: 'gpx',
8
- module: 'kml',
9
- version: VERSION,
10
- extensions: ['gpx'],
11
- mimeTypes: ['application/gpx+xml'],
12
- text: true,
13
- tests: [GPX_HEADER],
14
- parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
15
- parseTextSync,
16
- options: {
17
- gpx: {},
18
- gis: {
19
- format: 'geojson'
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._typecheckGPXLoader = exports.GPXLoader = void 0;
4
+ const gis_1 = require("@loaders.gl/gis");
5
+ const togeojson_1 = require("@tmcw/togeojson");
6
+ const xmldom_1 = require("@xmldom/xmldom");
7
+ // __VERSION__ is injected by babel-plugin-version-inline
8
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
9
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
10
+ const GPX_HEADER = `\
11
+ <?xml version="1.0" encoding="UTF-8"?>
12
+ <gpx`;
13
+ /**
14
+ * Loader for GPX (GPS exchange format)
15
+ */
16
+ exports.GPXLoader = {
17
+ name: 'GPX (GPS exchange format)',
18
+ id: 'gpx',
19
+ module: 'kml',
20
+ version: VERSION,
21
+ extensions: ['gpx'],
22
+ mimeTypes: ['application/gpx+xml'],
23
+ text: true,
24
+ tests: [GPX_HEADER],
25
+ parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
26
+ parseTextSync,
27
+ options: {
28
+ gpx: {},
29
+ gis: {}
20
30
  }
21
- }
22
31
  };
23
-
24
32
  function parseTextSync(text, options) {
25
- var _options$gpx, _options$gis;
26
-
27
- const doc = new DOMParser().parseFromString(text, 'text/xml');
28
- const geojson = gpx(doc);
29
-
30
- switch (options === null || options === void 0 ? void 0 : (_options$gpx = options.gpx) === null || _options$gpx === void 0 ? void 0 : _options$gpx.type) {
31
- case 'object-row-table':
32
- return geojson.features;
33
-
34
- default:
35
- }
36
-
37
- switch (options === null || options === void 0 ? void 0 : (_options$gis = options.gis) === null || _options$gis === void 0 ? void 0 : _options$gis.format) {
38
- case 'geojson':
39
- return geojson;
40
-
41
- case 'binary':
42
- return geojsonToBinary(geojson.features);
43
-
44
- case 'raw':
45
- return doc;
46
-
47
- default:
48
- throw new Error();
49
- }
33
+ const doc = new xmldom_1.DOMParser().parseFromString(text, 'text/xml');
34
+ const geojson = (0, togeojson_1.gpx)(doc);
35
+ const shape = options?.gis?.format || options?.gpx?.type || options?.gpx?.shape;
36
+ switch (shape) {
37
+ case 'object-row-table': {
38
+ const table = {
39
+ shape: 'object-row-table',
40
+ data: geojson.features
41
+ };
42
+ return table;
43
+ }
44
+ case 'geojson-row-table': {
45
+ const table = {
46
+ shape: 'geojson-row-table',
47
+ data: geojson.features
48
+ };
49
+ return table;
50
+ }
51
+ case 'geojson':
52
+ return geojson;
53
+ case 'binary':
54
+ return (0, gis_1.geojsonToBinary)(geojson.features);
55
+ case 'raw':
56
+ return doc;
57
+ default:
58
+ // Default to geojson for backwards compatibility
59
+ return geojson;
60
+ }
50
61
  }
51
-
52
- export const _typecheckGPXLoader = GPXLoader;
53
- //# sourceMappingURL=gpx-loader.js.map
62
+ exports._typecheckGPXLoader = exports.GPXLoader;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAEvC,YAAY,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAEvC,YAAY,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAEvC,YAAY,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAEvC,YAAY,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,12 @@
1
- export { GPXLoader } from './gpx-loader';
2
- export { KMLLoader } from './kml-loader';
3
- export { TCXLoader } from './tcx-loader';
4
- //# sourceMappingURL=index.js.map
1
+ "use strict";
2
+ // POLYFILL: DOMParser
3
+ // - Node: Yes
4
+ // - Browser: No
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TCXLoader = exports.KMLLoader = exports.GPXLoader = void 0;
7
+ var gpx_loader_1 = require("./gpx-loader");
8
+ Object.defineProperty(exports, "GPXLoader", { enumerable: true, get: function () { return gpx_loader_1.GPXLoader; } });
9
+ var kml_loader_1 = require("./kml-loader");
10
+ Object.defineProperty(exports, "KMLLoader", { enumerable: true, get: function () { return kml_loader_1.KMLLoader; } });
11
+ var tcx_loader_1 = require("./tcx-loader");
12
+ Object.defineProperty(exports, "TCXLoader", { enumerable: true, get: function () { return tcx_loader_1.TCXLoader; } });
@@ -1,6 +1,15 @@
1
1
  import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
2
- export declare type KMLLoaderOptions = LoaderOptions & {
3
- kml?: {};
2
+ import { GeoJSONRowTable, FeatureCollection, ObjectRowTable } from '@loaders.gl/schema';
3
+ export type KMLLoaderOptions = LoaderOptions & {
4
+ kml?: {
5
+ shape?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
6
+ /** @deprecated. Use options.kml.shape */
7
+ type?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
8
+ };
9
+ gis?: {
10
+ /** @deprecated. Use options.kml.shape */
11
+ format?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
12
+ };
4
13
  };
5
14
  /**
6
15
  * Loader for KML (Keyhole Markup Language)
@@ -14,16 +23,14 @@ export declare const KMLLoader: {
14
23
  mimeTypes: string[];
15
24
  text: boolean;
16
25
  tests: string[];
17
- parse: (arrayBuffer: any, options: any) => Promise<any>;
26
+ parse: (arrayBuffer: any, options?: KMLLoaderOptions) => Promise<Document | FeatureCollection<import("geojson").Geometry, import("geojson").GeoJsonProperties> | ObjectRowTable | GeoJSONRowTable | import("@loaders.gl/schema").BinaryFeatures>;
18
27
  parseTextSync: typeof parseTextSync;
19
28
  options: {
20
29
  kml: {};
21
- gis: {
22
- format: string;
23
- };
30
+ gis: {};
24
31
  };
25
32
  };
26
- declare function parseTextSync(text: string, options: any): any;
33
+ declare function parseTextSync(text: string, options?: KMLLoaderOptions): Document | FeatureCollection<import("geojson").Geometry, import("geojson").GeoJsonProperties> | ObjectRowTable | GeoJSONRowTable | import("@loaders.gl/schema").BinaryFeatures;
27
34
  export declare const _typecheckKMLLoader: LoaderWithParser;
28
35
  export {};
29
36
  //# sourceMappingURL=kml-loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kml-loader.d.ts","sourceRoot":"","sources":["../src/kml-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAQ9E,oBAAY,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,EAAE,CAAC;CACV,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;CAgBrB,CAAC;AAEF,iBAAS,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAoBhD;AAED,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
1
+ {"version":3,"file":"kml-loader.d.ts","sourceRoot":"","sources":["../src/kml-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAE9E,OAAO,EAAC,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAQtF,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE;QACJ,KAAK,CAAC,EAAE,kBAAkB,GAAG,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;QAChF,yCAAyC;QACzC,IAAI,CAAC,EAAE,kBAAkB,GAAG,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;KAChF,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,yCAAyC;QACzC,MAAM,CAAC,EAAE,kBAAkB,GAAG,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;KAClF,CAAC;CACH,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;wCASiB,gBAAgB;;;;;;CAOtD,CAAC;AAEF,iBAAS,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,kLA+B9D;AAED,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
@@ -1,53 +1,63 @@
1
- import { geojsonToBinary } from '@loaders.gl/gis';
2
- import { kml } from '@tmcw/togeojson';
3
- const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
4
- const KML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">";
5
- export const KMLLoader = {
6
- name: 'KML (Keyhole Markup Language)',
7
- id: 'kml',
8
- module: 'kml',
9
- version: VERSION,
10
- extensions: ['kml'],
11
- mimeTypes: ['application/vnd.google-earth.kml+xml'],
12
- text: true,
13
- tests: [KML_HEADER],
14
- parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
15
- parseTextSync,
16
- options: {
17
- kml: {},
18
- gis: {
19
- format: 'geojson'
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._typecheckKMLLoader = exports.KMLLoader = void 0;
4
+ const gis_1 = require("@loaders.gl/gis");
5
+ const togeojson_1 = require("@tmcw/togeojson");
6
+ const xmldom_1 = require("@xmldom/xmldom");
7
+ // __VERSION__ is injected by babel-plugin-version-inline
8
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
9
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
10
+ const KML_HEADER = `\
11
+ <?xml version="1.0" encoding="UTF-8"?>
12
+ <kml xmlns="http://www.opengis.net/kml/2.2">`;
13
+ /**
14
+ * Loader for KML (Keyhole Markup Language)
15
+ */
16
+ exports.KMLLoader = {
17
+ name: 'KML (Keyhole Markup Language)',
18
+ id: 'kml',
19
+ module: 'kml',
20
+ version: VERSION,
21
+ extensions: ['kml'],
22
+ mimeTypes: ['application/vnd.google-earth.kml+xml'],
23
+ text: true,
24
+ tests: [KML_HEADER],
25
+ parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
26
+ parseTextSync,
27
+ options: {
28
+ kml: {},
29
+ gis: {}
20
30
  }
21
- }
22
31
  };
23
-
24
32
  function parseTextSync(text, options) {
25
- var _options$kml, _options$gis;
26
-
27
- const doc = new DOMParser().parseFromString(text, 'text/xml');
28
- const geojson = kml(doc);
29
-
30
- switch (options === null || options === void 0 ? void 0 : (_options$kml = options.kml) === null || _options$kml === void 0 ? void 0 : _options$kml.type) {
31
- case 'object-row-table':
32
- return geojson.features;
33
-
34
- default:
35
- }
36
-
37
- switch (options === null || options === void 0 ? void 0 : (_options$gis = options.gis) === null || _options$gis === void 0 ? void 0 : _options$gis.format) {
38
- case 'geojson':
39
- return geojson;
40
-
41
- case 'binary':
42
- return geojsonToBinary(geojson.features);
43
-
44
- case 'raw':
45
- return doc;
46
-
47
- default:
48
- throw new Error();
49
- }
33
+ const doc = new xmldom_1.DOMParser().parseFromString(text, 'text/xml');
34
+ const geojson = (0, togeojson_1.kml)(doc);
35
+ // backwards compatibility
36
+ const shape = options?.gis?.format || options?.kml?.type || options?.kml?.shape;
37
+ switch (shape) {
38
+ case 'object-row-table': {
39
+ const table = {
40
+ shape: 'object-row-table',
41
+ data: geojson.features
42
+ };
43
+ return table;
44
+ }
45
+ case 'geojson-row-table': {
46
+ const table = {
47
+ shape: 'geojson-row-table',
48
+ data: geojson.features
49
+ };
50
+ return table;
51
+ }
52
+ case 'geojson':
53
+ return geojson;
54
+ case 'binary':
55
+ return (0, gis_1.geojsonToBinary)(geojson.features);
56
+ case 'raw':
57
+ return doc;
58
+ default:
59
+ // Default to geojson for backwards compatibility
60
+ return geojson;
61
+ }
50
62
  }
51
-
52
- export const _typecheckKMLLoader = KMLLoader;
53
- //# sourceMappingURL=kml-loader.js.map
63
+ exports._typecheckKMLLoader = exports.KMLLoader;
@@ -1,6 +1,15 @@
1
1
  import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
2
- export declare type TCXLoaderOptions = LoaderOptions & {
3
- tcx?: {};
2
+ import type { GeoJSONRowTable, FeatureCollection, ObjectRowTable } from '@loaders.gl/schema';
3
+ export type TCXLoaderOptions = LoaderOptions & {
4
+ tcx?: {
5
+ shape?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
6
+ /** @deprecated. Use options.tcx.shape */
7
+ type?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
8
+ };
9
+ gis?: {
10
+ /** @deprecated. Use options.tcx.shape */
11
+ format?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
12
+ };
4
13
  };
5
14
  /**
6
15
  * Loader for TCX (Training Center XML) - Garmin GPS track format
@@ -14,16 +23,14 @@ export declare const TCXLoader: {
14
23
  mimeTypes: string[];
15
24
  text: boolean;
16
25
  tests: string[];
17
- parse: (arrayBuffer: any, options: any) => Promise<any>;
26
+ parse: (arrayBuffer: any, options?: TCXLoaderOptions) => Promise<Document | FeatureCollection<import("geojson").Geometry, import("geojson").GeoJsonProperties> | ObjectRowTable | GeoJSONRowTable | import("@loaders.gl/schema").BinaryFeatures>;
18
27
  parseTextSync: typeof parseTextSync;
19
28
  options: {
20
29
  tcx: {};
21
- gis: {
22
- format: string;
23
- };
30
+ gis: {};
24
31
  };
25
32
  };
26
- declare function parseTextSync(text: string, options?: any): any;
33
+ declare function parseTextSync(text: string, options?: TCXLoaderOptions): Document | FeatureCollection<import("geojson").Geometry, import("geojson").GeoJsonProperties> | ObjectRowTable | GeoJSONRowTable | import("@loaders.gl/schema").BinaryFeatures;
27
34
  export declare const _typecheckTCXLoader: LoaderWithParser;
28
35
  export {};
29
36
  //# sourceMappingURL=tcx-loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tcx-loader.d.ts","sourceRoot":"","sources":["../src/tcx-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAQ9E,oBAAY,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,EAAE,CAAC;CACV,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;CAgBrB,CAAC;AAEF,iBAAS,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,GAAQ,OAoBrD;AAED,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
1
+ {"version":3,"file":"tcx-loader.d.ts","sourceRoot":"","sources":["../src/tcx-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAE9E,OAAO,KAAK,EAAC,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAQ3F,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE;QACJ,KAAK,CAAC,EAAE,kBAAkB,GAAG,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;QAChF,yCAAyC;QACzC,IAAI,CAAC,EAAE,kBAAkB,GAAG,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;KAChF,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,yCAAyC;QACzC,MAAM,CAAC,EAAE,kBAAkB,GAAG,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;KAClF,CAAC;CACH,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;wCASiB,gBAAgB;;;;;;CAOtD,CAAC;AAEF,iBAAS,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,kLAgC9D;AAED,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
@@ -1,53 +1,63 @@
1
- import { geojsonToBinary } from '@loaders.gl/gis';
2
- import { tcx } from '@tmcw/togeojson';
3
- const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
4
- const TCX_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<TrainingCenterDatabase";
5
- export const TCXLoader = {
6
- name: 'TCX (Training Center XML)',
7
- id: 'tcx',
8
- module: 'kml',
9
- version: VERSION,
10
- extensions: ['tcx'],
11
- mimeTypes: ['application/vnd.garmin.tcx+xml'],
12
- text: true,
13
- tests: [TCX_HEADER],
14
- parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
15
- parseTextSync,
16
- options: {
17
- tcx: {},
18
- gis: {
19
- format: 'geojson'
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._typecheckTCXLoader = exports.TCXLoader = void 0;
4
+ const gis_1 = require("@loaders.gl/gis");
5
+ const togeojson_1 = require("@tmcw/togeojson");
6
+ const xmldom_1 = require("@xmldom/xmldom");
7
+ // __VERSION__ is injected by babel-plugin-version-inline
8
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
9
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
10
+ const TCX_HEADER = `\
11
+ <?xml version="1.0" encoding="UTF-8"?>
12
+ <TrainingCenterDatabase`;
13
+ /**
14
+ * Loader for TCX (Training Center XML) - Garmin GPS track format
15
+ */
16
+ exports.TCXLoader = {
17
+ name: 'TCX (Training Center XML)',
18
+ id: 'tcx',
19
+ module: 'kml',
20
+ version: VERSION,
21
+ extensions: ['tcx'],
22
+ mimeTypes: ['application/vnd.garmin.tcx+xml'],
23
+ text: true,
24
+ tests: [TCX_HEADER],
25
+ parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
26
+ parseTextSync,
27
+ options: {
28
+ tcx: {},
29
+ gis: {}
20
30
  }
21
- }
22
31
  };
23
-
24
- function parseTextSync(text, options = {}) {
25
- var _options$tcx, _options$gis;
26
-
27
- const doc = new DOMParser().parseFromString(text, 'text/xml');
28
- const geojson = tcx(doc);
29
-
30
- switch (options === null || options === void 0 ? void 0 : (_options$tcx = options.tcx) === null || _options$tcx === void 0 ? void 0 : _options$tcx.type) {
31
- case 'object-row-table':
32
- return geojson.features;
33
-
34
- default:
35
- }
36
-
37
- switch (options === null || options === void 0 ? void 0 : (_options$gis = options.gis) === null || _options$gis === void 0 ? void 0 : _options$gis.format) {
38
- case 'geojson':
39
- return geojson;
40
-
41
- case 'binary':
42
- return geojsonToBinary(geojson.features);
43
-
44
- case 'raw':
45
- return doc;
46
-
47
- default:
48
- throw new Error();
49
- }
32
+ function parseTextSync(text, options) {
33
+ const doc = new xmldom_1.DOMParser().parseFromString(text, 'text/xml');
34
+ const geojson = (0, togeojson_1.tcx)(doc);
35
+ // backwards compatibility
36
+ const shape = options?.gis?.format || options?.tcx?.type || options?.tcx?.shape;
37
+ switch (shape) {
38
+ case 'object-row-table': {
39
+ const table = {
40
+ shape: 'object-row-table',
41
+ data: geojson.features
42
+ };
43
+ return table;
44
+ }
45
+ case 'geojson-row-table': {
46
+ const table = {
47
+ shape: 'geojson-row-table',
48
+ data: geojson.features
49
+ };
50
+ return table;
51
+ }
52
+ case 'geojson':
53
+ return geojson;
54
+ case 'binary':
55
+ return (0, gis_1.geojsonToBinary)(geojson.features);
56
+ case 'raw':
57
+ return doc;
58
+ default:
59
+ // Default to geojson for backwards compatibility
60
+ return geojson;
61
+ }
50
62
  }
51
-
52
- export const _typecheckTCXLoader = TCXLoader;
53
- //# sourceMappingURL=tcx-loader.js.map
63
+ exports._typecheckTCXLoader = exports.TCXLoader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/kml",
3
- "version": "4.0.0-alpha.5",
3
+ "version": "4.0.0-alpha.7",
4
4
  "description": "Framework-independent loader for the KML format",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -19,8 +19,8 @@
19
19
  "KML"
20
20
  ],
21
21
  "types": "dist/index.d.ts",
22
- "main": "dist/index.js",
23
- "module": "dist/index.js",
22
+ "main": "dist/es5/index.js",
23
+ "module": "dist/esm/index.js",
24
24
  "sideEffects": false,
25
25
  "files": [
26
26
  "src",
@@ -32,10 +32,11 @@
32
32
  "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js"
33
33
  },
34
34
  "dependencies": {
35
- "@loaders.gl/gis": "4.0.0-alpha.5",
36
- "@loaders.gl/loader-utils": "4.0.0-alpha.5",
37
- "@loaders.gl/schema": "4.0.0-alpha.5",
38
- "@tmcw/togeojson": "^4.5.0"
35
+ "@loaders.gl/gis": "4.0.0-alpha.7",
36
+ "@loaders.gl/loader-utils": "4.0.0-alpha.7",
37
+ "@loaders.gl/schema": "4.0.0-alpha.7",
38
+ "@tmcw/togeojson": "^4.5.0",
39
+ "@xmldom/xmldom": "^0.7.5"
39
40
  },
40
- "gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
41
+ "gitHead": "afb59c4d8e5d8ebb9c28f111cb0c96c5527d0ffd"
41
42
  }
package/src/gpx-loader.ts CHANGED
@@ -1,13 +1,23 @@
1
- import type {LoaderOptions} from '@loaders.gl/loader-utils';
1
+ import type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
2
2
  import {geojsonToBinary} from '@loaders.gl/gis';
3
+ import type {GeoJSONRowTable, FeatureCollection, ObjectRowTable} from '@loaders.gl/schema';
3
4
  import {gpx} from '@tmcw/togeojson';
5
+ import {DOMParser} from '@xmldom/xmldom';
4
6
 
5
7
  // __VERSION__ is injected by babel-plugin-version-inline
6
8
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
9
  const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
8
10
 
9
11
  export type GPXLoaderOptions = LoaderOptions & {
10
- gpx?: {};
12
+ gpx?: {
13
+ shape?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
14
+ /** @deprecated. Use options.gpx.shape */
15
+ type?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
16
+ };
17
+ gis?: {
18
+ /** @deprecated. Use options.gpx.shape */
19
+ format?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
20
+ };
11
21
  };
12
22
 
13
23
  const GPX_HEADER = `\
@@ -26,26 +36,36 @@ export const GPXLoader = {
26
36
  mimeTypes: ['application/gpx+xml'],
27
37
  text: true,
28
38
  tests: [GPX_HEADER],
29
- parse: async (arrayBuffer, options) =>
39
+ parse: async (arrayBuffer, options?: GPXLoaderOptions) =>
30
40
  parseTextSync(new TextDecoder().decode(arrayBuffer), options),
31
41
  parseTextSync,
32
42
  options: {
33
43
  gpx: {},
34
- gis: {format: 'geojson'}
44
+ gis: {}
35
45
  }
36
46
  };
37
47
 
38
- function parseTextSync(text: string, options: any) {
48
+ function parseTextSync(text: string, options?: GPXLoaderOptions) {
39
49
  const doc = new DOMParser().parseFromString(text, 'text/xml');
40
- const geojson = gpx(doc);
50
+ const geojson: FeatureCollection = gpx(doc);
41
51
 
42
- switch (options?.gpx?.type) {
43
- case 'object-row-table':
44
- return geojson.features;
45
- default:
46
- }
52
+ const shape = options?.gis?.format || options?.gpx?.type || options?.gpx?.shape;
47
53
 
48
- switch (options?.gis?.format) {
54
+ switch (shape) {
55
+ case 'object-row-table': {
56
+ const table: ObjectRowTable = {
57
+ shape: 'object-row-table',
58
+ data: geojson.features
59
+ };
60
+ return table;
61
+ }
62
+ case 'geojson-row-table': {
63
+ const table: GeoJSONRowTable = {
64
+ shape: 'geojson-row-table',
65
+ data: geojson.features
66
+ };
67
+ return table;
68
+ }
49
69
  case 'geojson':
50
70
  return geojson;
51
71
  case 'binary':
@@ -53,8 +73,9 @@ function parseTextSync(text: string, options: any) {
53
73
  case 'raw':
54
74
  return doc;
55
75
  default:
56
- throw new Error();
76
+ // Default to geojson for backwards compatibility
77
+ return geojson;
57
78
  }
58
79
  }
59
80
 
60
- export const _typecheckGPXLoader = GPXLoader;
81
+ export const _typecheckGPXLoader: LoaderWithParser = GPXLoader;
package/src/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ // POLYFILL: DOMParser
2
+ // - Node: Yes
3
+ // - Browser: No
4
+
1
5
  export type {GPXLoaderOptions} from './gpx-loader';
2
6
  export {GPXLoader} from './gpx-loader';
3
7