@loaders.gl/kml 4.0.0-alpha.9 → 4.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/gpx-loader.ts CHANGED
@@ -1,6 +1,6 @@
1
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
+ import type {GeoJSONTable, FeatureCollection, ObjectRowTable} from '@loaders.gl/schema';
4
4
  import {gpx} from '@tmcw/togeojson';
5
5
  import {DOMParser} from '@xmldom/xmldom';
6
6
 
@@ -10,13 +10,13 @@ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
10
10
 
11
11
  export type GPXLoaderOptions = LoaderOptions & {
12
12
  gpx?: {
13
- shape?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
13
+ shape?: 'object-row-table' | 'geojson-table' | 'geojson' | 'binary' | 'raw';
14
14
  /** @deprecated. Use options.gpx.shape */
15
- type?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
15
+ type?: 'object-row-table' | 'geojson-table' | 'geojson' | 'binary' | 'raw';
16
16
  };
17
17
  gis?: {
18
18
  /** @deprecated. Use options.gpx.shape */
19
- format?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
19
+ format?: 'object-row-table' | 'geojson-table' | 'geojson' | 'binary' | 'raw';
20
20
  };
21
21
  };
22
22
 
@@ -27,7 +27,7 @@ const GPX_HEADER = `\
27
27
  /**
28
28
  * Loader for GPX (GPS exchange format)
29
29
  */
30
- export const GPXLoader = {
30
+ export const GPXLoader: LoaderWithParser<any, never, GPXLoaderOptions> = {
31
31
  name: 'GPX (GPS exchange format)',
32
32
  id: 'gpx',
33
33
  module: 'kml',
@@ -59,10 +59,11 @@ function parseTextSync(text: string, options?: GPXLoaderOptions) {
59
59
  };
60
60
  return table;
61
61
  }
62
- case 'geojson-row-table': {
63
- const table: GeoJSONRowTable = {
64
- shape: 'geojson-row-table',
65
- data: geojson.features
62
+ case 'geojson-table': {
63
+ const table: GeoJSONTable = {
64
+ shape: 'geojson-table',
65
+ type: 'FeatureCollection',
66
+ features: geojson.features
66
67
  };
67
68
  return table;
68
69
  }
@@ -77,5 +78,3 @@ function parseTextSync(text: string, options?: GPXLoaderOptions) {
77
78
  return geojson;
78
79
  }
79
80
  }
80
-
81
- export const _typecheckGPXLoader: LoaderWithParser = GPXLoader;
package/src/kml-loader.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
2
- import {geojsonToBinary} from '@loaders.gl/gis';
3
- import {GeoJSONRowTable, FeatureCollection, ObjectRowTable} from '@loaders.gl/schema';
2
+ // import {geojsonToBinary} from '@loaders.gl/gis';
3
+ // import {GeoJSONTable} from '@loaders.gl/schema';
4
+ import {FeatureCollection, ObjectRowTable} from '@loaders.gl/schema';
4
5
  import {kml} from '@tmcw/togeojson';
5
6
  import {DOMParser} from '@xmldom/xmldom';
6
7
 
@@ -10,13 +11,13 @@ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
10
11
 
11
12
  export type KMLLoaderOptions = LoaderOptions & {
12
13
  kml?: {
13
- shape?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
14
+ shape?: 'object-row-table' | 'geojson-table';
14
15
  /** @deprecated. Use options.kml.shape */
15
- type?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
16
+ type?: 'object-row-table' | 'geojson-table';
16
17
  };
17
18
  gis?: {
18
19
  /** @deprecated. Use options.kml.shape */
19
- format?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
20
+ format?: 'object-row-table' | 'geojson-table' | 'geojson' | 'binary' | 'raw';
20
21
  };
21
22
  };
22
23
 
@@ -27,7 +28,7 @@ const KML_HEADER = `\
27
28
  /**
28
29
  * Loader for KML (Keyhole Markup Language)
29
30
  */
30
- export const KMLLoader = {
31
+ export const KMLLoader: LoaderWithParser<ObjectRowTable, never, KMLLoaderOptions> = {
31
32
  name: 'KML (Keyhole Markup Language)',
32
33
  id: 'kml',
33
34
  module: 'kml',
@@ -45,37 +46,32 @@ export const KMLLoader = {
45
46
  }
46
47
  };
47
48
 
48
- function parseTextSync(text: string, options?: KMLLoaderOptions) {
49
+ function parseTextSync(text: string, options?: KMLLoaderOptions): ObjectRowTable {
49
50
  const doc = new DOMParser().parseFromString(text, 'text/xml');
50
51
  const geojson: FeatureCollection = kml(doc);
51
52
 
52
53
  // backwards compatibility
53
54
  const shape = options?.gis?.format || options?.kml?.type || options?.kml?.shape;
54
55
  switch (shape) {
55
- case 'object-row-table': {
56
+ // case 'geojson-table': {
57
+ // const table: GeoJSONTable = {
58
+ // shape: 'geojson-table',
59
+ // data: geojson.features
60
+ // };
61
+ // return table;
62
+ // }
63
+ // case 'geojson':
64
+ // return geojson;
65
+ // case 'binary':
66
+ // return geojsonToBinary(geojson.features);
67
+ // case 'raw':
68
+ // return doc;
69
+ case 'object-row-table':
70
+ default:
56
71
  const table: ObjectRowTable = {
57
72
  shape: 'object-row-table',
58
73
  data: geojson.features
59
74
  };
60
75
  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
- }
69
- case 'geojson':
70
- return geojson;
71
- case 'binary':
72
- return geojsonToBinary(geojson.features);
73
- case 'raw':
74
- return doc;
75
- default:
76
- // Default to geojson for backwards compatibility
77
- return geojson;
78
76
  }
79
77
  }
80
-
81
- export const _typecheckKMLLoader: LoaderWithParser = KMLLoader;
package/src/tcx-loader.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
2
2
  import {geojsonToBinary} from '@loaders.gl/gis';
3
- import type {GeoJSONRowTable, FeatureCollection, ObjectRowTable} from '@loaders.gl/schema';
3
+ import type {GeoJSONTable, FeatureCollection, ObjectRowTable} from '@loaders.gl/schema';
4
4
  import {tcx} from '@tmcw/togeojson';
5
5
  import {DOMParser} from '@xmldom/xmldom';
6
6
 
@@ -10,13 +10,13 @@ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
10
10
 
11
11
  export type TCXLoaderOptions = LoaderOptions & {
12
12
  tcx?: {
13
- shape?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
13
+ shape?: 'object-row-table' | 'geojson-table' | 'geojson' | 'binary' | 'raw';
14
14
  /** @deprecated. Use options.tcx.shape */
15
- type?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
15
+ type?: 'object-row-table' | 'geojson-table' | 'geojson' | 'binary' | 'raw';
16
16
  };
17
17
  gis?: {
18
18
  /** @deprecated. Use options.tcx.shape */
19
- format?: 'object-row-table' | 'geojson-row-table' | 'geojson' | 'binary' | 'raw';
19
+ format?: 'object-row-table' | 'geojson-table' | 'geojson' | 'binary' | 'raw';
20
20
  };
21
21
  };
22
22
 
@@ -27,7 +27,7 @@ const TCX_HEADER = `\
27
27
  /**
28
28
  * Loader for TCX (Training Center XML) - Garmin GPS track format
29
29
  */
30
- export const TCXLoader = {
30
+ export const TCXLoader: LoaderWithParser<any, never, TCXLoaderOptions> = {
31
31
  name: 'TCX (Training Center XML)',
32
32
  id: 'tcx',
33
33
  module: 'kml',
@@ -60,10 +60,11 @@ function parseTextSync(text: string, options?: TCXLoaderOptions) {
60
60
  };
61
61
  return table;
62
62
  }
63
- case 'geojson-row-table': {
64
- const table: GeoJSONRowTable = {
65
- shape: 'geojson-row-table',
66
- data: geojson.features
63
+ case 'geojson-table': {
64
+ const table: GeoJSONTable = {
65
+ shape: 'geojson-table',
66
+ type: 'FeatureCollection',
67
+ features: geojson.features
67
68
  };
68
69
  return table;
69
70
  }
@@ -78,5 +79,3 @@ function parseTextSync(text: string, options?: TCXLoaderOptions) {
78
79
  return geojson;
79
80
  }
80
81
  }
81
-
82
- export const _typecheckTCXLoader: LoaderWithParser = TCXLoader;
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
@@ -1,62 +0,0 @@
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: {}
30
- }
31
- };
32
- function parseTextSync(text, options) {
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
- }
61
- }
62
- exports._typecheckGPXLoader = exports.GPXLoader;
package/dist/index.js DELETED
@@ -1,12 +0,0 @@
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,63 +0,0 @@
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: {}
30
- }
31
- };
32
- function parseTextSync(text, options) {
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
- }
62
- }
63
- exports._typecheckKMLLoader = exports.KMLLoader;
@@ -1,63 +0,0 @@
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: {}
30
- }
31
- };
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
- }
62
- }
63
- exports._typecheckTCXLoader = exports.TCXLoader;