@tmcw/togeojson 4.6.1 → 5.0.0-0
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/CHANGELOG.md +18 -0
- package/README.md +2 -60
- package/dist/gpx/coord_pair.d.ts +9 -0
- package/dist/gpx/extensions.d.ts +2 -0
- package/dist/gpx/line.d.ts +3 -0
- package/dist/gpx/properties.d.ts +3 -0
- package/dist/gpx.d.ts +19 -0
- package/dist/index.d.ts +3 -0
- package/dist/kml/extractStyle.d.ts +13 -0
- package/dist/kml/fixColor.d.ts +2 -0
- package/dist/kml/geometry.d.ts +16 -0
- package/dist/kml/placemark.d.ts +3 -0
- package/dist/kml.d.ts +61 -0
- package/dist/shared.d.ts +27 -0
- package/dist/tcx.d.ts +12 -0
- package/dist/togeojson.cjs +748 -717
- package/dist/togeojson.cjs.map +1 -1
- package/dist/togeojson.es.js +1 -776
- package/dist/togeojson.es.js.map +1 -1
- package/dist/togeojson.js +1 -785
- package/dist/togeojson.js.map +1 -1
- package/dist/togeojson.modern.js +2 -0
- package/dist/togeojson.modern.js.map +1 -0
- package/dist/togeojson.umd.js +1 -1
- package/dist/togeojson.umd.js.map +1 -1
- package/package.json +21 -10
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [5.0.0-0](https://github.com/tmcw/togeojson/compare/v4.8.0-0...v5.0.0-0) (2022-03-14)
|
|
6
|
+
|
|
7
|
+
## [4.8.0-0](https://github.com/tmcw/togeojson/compare/v4.7.0...v4.8.0-0) (2022-03-14)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* Folders and TypeScript ([6f36fd3](https://github.com/tmcw/togeojson/commit/6f36fd381798377909632eae11efef9e8b9be596))
|
|
13
|
+
|
|
14
|
+
### [4.7.1-0](https://github.com/tmcw/togeojson/compare/v4.7.0...v4.7.1-0) (2022-03-09)
|
|
15
|
+
|
|
16
|
+
## [4.7.0](https://github.com/tmcw/togeojson/compare/v4.6.1...v4.7.0) (2022-03-08)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* Support gx:CascadingStyle ([600c542](https://github.com/tmcw/togeojson/commit/600c542b016684066fb31107c5896bedad0b5329))
|
|
22
|
+
|
|
5
23
|
### [4.6.1](https://github.com/tmcw/togeojson/compare/v4.6.1-1...v4.6.1) (2022-03-07)
|
|
6
24
|
|
|
7
25
|
### [4.6.1-1](https://github.com/tmcw/togeojson/compare/v4.6.1-0...v4.6.1-1) (2022-03-07)
|
package/README.md
CHANGED
|
@@ -15,51 +15,6 @@ looking for a command line too, use [@tmcw/togeojson-cli](https://github.com/tmc
|
|
|
15
15
|
want to convert one KML or GPX file, use [my online tool](https://observablehq.com/@tmcw/convert-kml-to-geojson).
|
|
16
16
|
If you want to convert another format, consider [GDAL](https://www.gdal.org/)._
|
|
17
17
|
|
|
18
|
-
## API
|
|
19
|
-
|
|
20
|
-
### `toGeoJSON.kml(doc)`
|
|
21
|
-
|
|
22
|
-
Convert a KML document to GeoJSON. The first argument, `doc`, must be a KML
|
|
23
|
-
document as an XML DOM - not as a string. You can get this using jQuery's default
|
|
24
|
-
`.ajax` function or using a bare XMLHttpRequest with the `.response` property
|
|
25
|
-
holding an XML DOM.
|
|
26
|
-
|
|
27
|
-
The output is a JavaScript object of GeoJSON data. You can convert it to a string
|
|
28
|
-
with [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
|
|
29
|
-
or use it directly in libraries.
|
|
30
|
-
|
|
31
|
-
### `toGeoJSON.kmlGen(doc)`
|
|
32
|
-
|
|
33
|
-
Convert KML to GeoJSON incrementally, returning a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
34
|
-
that yields output feature by feature.
|
|
35
|
-
|
|
36
|
-
### `toGeoJSON.gpx(doc)`
|
|
37
|
-
|
|
38
|
-
Convert a GPX document to GeoJSON. The first argument, `doc`, must be a GPX
|
|
39
|
-
document as an XML DOM - not as a string. You can get this using jQuery's default
|
|
40
|
-
`.ajax` function or using a bare XMLHttpRequest with the `.response` property
|
|
41
|
-
holding an XML DOM.
|
|
42
|
-
|
|
43
|
-
The output is a JavaScript object of GeoJSON data, same as `.kml` outputs, with the
|
|
44
|
-
addition of a `_gpxType` property on each `LineString` feature that indicates whether
|
|
45
|
-
the feature was encoded as a route (`rte`) or track (`trk`) in the GPX document.
|
|
46
|
-
|
|
47
|
-
### `toGeoJSON.gpxGen(doc)`
|
|
48
|
-
|
|
49
|
-
Convert GPX to GeoJSON incrementally, returning a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
50
|
-
that yields output feature by feature.
|
|
51
|
-
|
|
52
|
-
### `toGeoJSON.tcx(doc)`
|
|
53
|
-
|
|
54
|
-
Convert a TCX document to GeoJSON. The first argument, `doc`, must be a TCX
|
|
55
|
-
document as an XML DOM - not as a string.
|
|
56
|
-
|
|
57
|
-
### `toGeoJSON.tcxGen(doc)`
|
|
58
|
-
|
|
59
|
-
Convert a TCX document to GeoJSON incrementally, returning a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
60
|
-
that yields output feature by feature. The first argument, `doc`, must be a TCX
|
|
61
|
-
document as an XML DOM - not as a string.
|
|
62
|
-
|
|
63
18
|
## Property conversions
|
|
64
19
|
|
|
65
20
|
In addition to converting KML’s `<ExtendedData>` verbatim, @tmcw/togeojson
|
|
@@ -138,10 +93,11 @@ import { kml } from "@tmcw/togeojson";
|
|
|
138
93
|
- [x] ExtendedData
|
|
139
94
|
- [x] SimpleData
|
|
140
95
|
- [x] MultiGeometry -> GeometryCollection
|
|
141
|
-
- [x] Styles
|
|
96
|
+
- [x] Styles
|
|
142
97
|
- [x] Tracks & MultiTracks with `gx:coords`, including altitude
|
|
143
98
|
- [x] [TimeSpan](https://developers.google.com/kml/documentation/kmlreference#timespan)
|
|
144
99
|
- [x] [TimeStamp](https://developers.google.com/kml/documentation/kmlreference#timestamp)
|
|
100
|
+
- [x] Folders (with kmlWithFolders)
|
|
145
101
|
- [ ] NetworkLinks
|
|
146
102
|
- [ ] GroundOverlays
|
|
147
103
|
|
|
@@ -167,20 +123,6 @@ import { kml } from "@tmcw/togeojson";
|
|
|
167
123
|
- The command line utility was moved to [tmcw/togeojson-cli](https://github.com/tmcw/togeojson-cli),
|
|
168
124
|
which lets this module enjoy reduced dependencies: installing @tmcw/togeojson doesn’t
|
|
169
125
|
require any other dependencies.
|
|
170
|
-
- The hashing method is improved, which means that parsing is the same between browsers and
|
|
171
|
-
Node.js, and there are no runtime dependencies.
|
|
172
|
-
|
|
173
|
-
### What is hashing?
|
|
174
|
-
|
|
175
|
-
KML's style system isn't semantic: a typical document made through official tools
|
|
176
|
-
(read Google) has hundreds of identical styles. So, togeojson does its best to
|
|
177
|
-
make this into something usable, by taking a quick hash of each style and exposing
|
|
178
|
-
`styleUrl` and `styleHash` to users. This lets you work backwards from the awful
|
|
179
|
-
representation and build your own styles or derive data based on the classes
|
|
180
|
-
chosen.
|
|
181
|
-
|
|
182
|
-
Implied here is that this does not try to represent all data contained in KML
|
|
183
|
-
styles.
|
|
184
126
|
|
|
185
127
|
### Why doesn't toGeoJSON support NetworkLinks?
|
|
186
128
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Position } from "geojson";
|
|
2
|
+
import { ExtendedValues } from "./extensions";
|
|
3
|
+
interface CoordPair {
|
|
4
|
+
coordinates: Position;
|
|
5
|
+
time: string | null;
|
|
6
|
+
extendedValues: ExtendedValues;
|
|
7
|
+
}
|
|
8
|
+
export declare function coordPair(node: Element): CoordPair;
|
|
9
|
+
export {};
|
package/dist/gpx.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FeatureCollection, Feature } from "geojson";
|
|
2
|
+
/**
|
|
3
|
+
* Convert GPX to GeoJSON incrementally, returning
|
|
4
|
+
* a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
5
|
+
* that yields output feature by feature.
|
|
6
|
+
*/
|
|
7
|
+
export declare function gpxGen(node: Document): Generator<Feature>;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* Convert a GPX document to GeoJSON. The first argument, `doc`, must be a GPX
|
|
11
|
+
* document as an XML DOM - not as a string. You can get this using jQuery's default
|
|
12
|
+
* `.ajax` function or using a bare XMLHttpRequest with the `.response` property
|
|
13
|
+
* holding an XML DOM.
|
|
14
|
+
*
|
|
15
|
+
* The output is a JavaScript object of GeoJSON data, same as `.kml` outputs, with the
|
|
16
|
+
* addition of a `_gpxType` property on each `LineString` feature that indicates whether
|
|
17
|
+
* the feature was encoded as a route (`rte`) or track (`trk`) in the GPX document.
|
|
18
|
+
*/
|
|
19
|
+
export declare function gpx(node: Document): FeatureCollection;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function extractIcon(node: Element): {
|
|
2
|
+
[name: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export declare function extractLabel(node: Element): {
|
|
5
|
+
[name: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export declare function extractLine(node: Element): {
|
|
8
|
+
[name: string]: any;
|
|
9
|
+
};
|
|
10
|
+
export declare function extractPoly(node: Element): {
|
|
11
|
+
[name: string]: any;
|
|
12
|
+
};
|
|
13
|
+
export declare function extractStyle(node: Element): any;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Position, Geometry } from "geojson";
|
|
2
|
+
/**
|
|
3
|
+
* Get one coordinate from a coordinate array, if any
|
|
4
|
+
*/
|
|
5
|
+
export declare function coord1(value: string): Position;
|
|
6
|
+
/**
|
|
7
|
+
* Get all coordinates from a coordinate array as [[],[]]
|
|
8
|
+
*/
|
|
9
|
+
export declare function coord(value: string): Position[];
|
|
10
|
+
export declare function fixRing(ring: Position[]): Position[];
|
|
11
|
+
interface GeometriesAndTimes {
|
|
12
|
+
geometries: Geometry[];
|
|
13
|
+
coordTimes: string[][];
|
|
14
|
+
}
|
|
15
|
+
export declare function getGeometry(node: Element): GeometriesAndTimes;
|
|
16
|
+
export {};
|
package/dist/kml.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { FeatureCollection, Geometry } from "geojson";
|
|
2
|
+
import { F } from "./shared";
|
|
3
|
+
interface Folder {
|
|
4
|
+
type: "folder";
|
|
5
|
+
meta: {
|
|
6
|
+
name?: string;
|
|
7
|
+
visibility?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
};
|
|
10
|
+
children: Array<Folder | F>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A nested folder structure, represented
|
|
14
|
+
* as a tree with folders and features.
|
|
15
|
+
*/
|
|
16
|
+
export interface Root {
|
|
17
|
+
type: "root";
|
|
18
|
+
children: Array<Folder | F>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Yield a nested tree with KML folder structure
|
|
22
|
+
*
|
|
23
|
+
* This generates a tree with the given structure:
|
|
24
|
+
*
|
|
25
|
+
* ```js
|
|
26
|
+
* {
|
|
27
|
+
* "type": "root",
|
|
28
|
+
* "children": [
|
|
29
|
+
* {
|
|
30
|
+
* "type": "folder",
|
|
31
|
+
* "meta": {
|
|
32
|
+
* "name": "Test"
|
|
33
|
+
* },
|
|
34
|
+
* "children": [
|
|
35
|
+
* // ...features and folders
|
|
36
|
+
* ]
|
|
37
|
+
* }
|
|
38
|
+
* // ...features
|
|
39
|
+
* ]
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function kmlWithFolders(node: Document): Root;
|
|
44
|
+
/**
|
|
45
|
+
* Convert KML to GeoJSON incrementally, returning
|
|
46
|
+
* a [Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
47
|
+
* that yields output feature by feature.
|
|
48
|
+
*/
|
|
49
|
+
export declare function kmlGen(node: Document): Generator<F>;
|
|
50
|
+
/**
|
|
51
|
+
* Convert a KML document to GeoJSON. The first argument, `doc`, must be a KML
|
|
52
|
+
* document as an XML DOM - not as a string. You can get this using jQuery's default
|
|
53
|
+
* `.ajax` function or using a bare XMLHttpRequest with the `.response` property
|
|
54
|
+
* holding an XML DOM.
|
|
55
|
+
*
|
|
56
|
+
* The output is a JavaScript object of GeoJSON data. You can convert it to a string
|
|
57
|
+
* with [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
|
|
58
|
+
* or use it directly in libraries.
|
|
59
|
+
*/
|
|
60
|
+
export declare function kml(node: Document): FeatureCollection<Geometry | null>;
|
|
61
|
+
export {};
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Feature, Geometry } from "geojson";
|
|
2
|
+
export declare function $(element: Element | Document, tagName: string): Element[];
|
|
3
|
+
export declare type P = NonNullable<Feature["properties"]>;
|
|
4
|
+
export declare type F = Feature<Geometry | null>;
|
|
5
|
+
export declare type StyleMap = {
|
|
6
|
+
[key: string]: P;
|
|
7
|
+
};
|
|
8
|
+
export declare function normalizeId(id: string): string;
|
|
9
|
+
export declare function $ns(element: Element | Document, tagName: string, ns: string): Element[];
|
|
10
|
+
/**
|
|
11
|
+
* get the content of a text node, if any
|
|
12
|
+
*/
|
|
13
|
+
export declare function nodeVal(node: Element | null): string;
|
|
14
|
+
/**
|
|
15
|
+
* Get one Y child of X, if any, otherwise null
|
|
16
|
+
*/
|
|
17
|
+
export declare function get1(node: Element, tagName: string, callback?: (elem: Element) => unknown): Element | null;
|
|
18
|
+
export declare function get(node: Element | null, tagName: string, callback?: (elem: Element, properties: P) => P): {
|
|
19
|
+
[name: string]: any;
|
|
20
|
+
};
|
|
21
|
+
export declare function val1(node: Element, tagName: string, callback: (val: string) => P | void): P;
|
|
22
|
+
export declare function $num(node: Element, tagName: string, callback: (val: number) => Feature["properties"]): {
|
|
23
|
+
[name: string]: any;
|
|
24
|
+
} | undefined;
|
|
25
|
+
export declare function num1(node: Element, tagName: string, callback?: (val: number) => unknown): number | undefined;
|
|
26
|
+
export declare function getMulti(node: Element, propertyNames: string[]): P;
|
|
27
|
+
export declare function isElement(node: Node | null): node is Element;
|
package/dist/tcx.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Feature, FeatureCollection } from "geojson";
|
|
2
|
+
/**
|
|
3
|
+
* Incrementally convert a TCX document to GeoJSON. The
|
|
4
|
+
* first argument, `doc`, must be a TCX
|
|
5
|
+
* document as an XML DOM - not as a string.
|
|
6
|
+
*/
|
|
7
|
+
export declare function tcxGen(node: Document): Generator<Feature>;
|
|
8
|
+
/**
|
|
9
|
+
* Convert a TCX document to GeoJSON. The first argument, `doc`, must be a TCX
|
|
10
|
+
* document as an XML DOM - not as a string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function tcx(node: Document): FeatureCollection;
|