Skip to content

Commit

Permalink
feat: Preserve GPX linestring type in a _gpxType property that is eit…
Browse files Browse the repository at this point in the history
…her rte or trk
  • Loading branch information
jczaplew committed Aug 20, 2020
1 parent ae85f23 commit 54fa558
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ document as an XML DOM - not as a string. You can get this using jQuery's defaul
`.ajax` function or using a bare XMLHttpRequest with the `.response` property
holding an XML DOM.

The output is a JavaScript object of GeoJSON data, same as `.kml` outputs.
The output is a JavaScript object of GeoJSON data, same as `.kml` outputs, with the
addition of a `_gpxType` property on each `LineString` feature that indicates whether
the feature was encoded as a route (`rte`) or track (`trk`) in the GPX document.

### `toGeoJSON.gpxGen(doc)`

Expand Down
6 changes: 4 additions & 2 deletions lib/gpx.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ function getRoute(node) {
type: "Feature",
properties: Object.assign(
getProperties(node),
getLineStyle(get1(node, "extensions"))
getLineStyle(get1(node, "extensions")),
{"_gpxType": "rte"}
),
geometry: {
type: "LineString",
Expand Down Expand Up @@ -204,7 +205,8 @@ function getTrack(node) {
if (track.length === 0) return;
const properties = Object.assign(
getProperties(node),
getLineStyle(get1(node, "extensions"))
getLineStyle(get1(node, "extensions")),
{"_gpxType": "trk"}
);
if (times.length)
properties.coordTimes = track.length === 1 ? times[0] : times;
Expand Down

0 comments on commit 54fa558

Please sign in to comment.