Skip to content

Commit

Permalink
feat: Load TCX Courses (#53)
Browse files Browse the repository at this point in the history
* Also load TCX Courses

* Add name to properties
  • Loading branch information
kylebarron authored Aug 3, 2021
1 parent cf82603 commit 8924925
Show file tree
Hide file tree
Showing 3 changed files with 504 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/tcx.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ function getLap(node) {
const allExtendedProperties = [];
let line;
const properties = fromEntries(getProperties(node, LAP_ATTRIBUTES));

const nameElement = get1(node, 'Name')
if (nameElement) {
properties.name = nodeVal(nameElement)
}

for (let i = 0; i < segments.length; i++) {
line = getPoints(segments[i], "Trackpoint");
if (line) {
Expand Down Expand Up @@ -169,6 +175,13 @@ export function* tcxGen(doc) {
const feature = getLap(laps[i]);
if (feature) yield feature;
}

const courses = doc.getElementsByTagName("Courses");

for (let i = 0; i < courses.length; i++) {
const feature = getLap(courses[i]);
if (feature) yield feature;
}
}

export function tcx(doc) {
Expand Down
205 changes: 205 additions & 0 deletions tap-snapshots/test-index.test.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20979,6 +20979,211 @@ Object {
}
`

exports[`test/index.test.js TAP toGeoJSON > tcx-courses.tcx 1`] = `
Object {
"features": Array [
Object {
"geometry": Object {
"coordinates": Array [
Array [
-122.50564,
37.76683,
22.820000000000004,
],
Array [
-122.5046067,
37.76706,
24.12,
],
Array [
-122.5035733,
37.76729,
25.42,
],
Array [
-122.50254,
37.76752,
25.17,
],
Array [
-122.50253,
37.76752,
25.17,
],
Array [
-122.501644,
37.767794,
25.060000000000002,
],
Array [
-122.500758,
37.768068,
26.76,
],
Array [
-122.499872,
37.768342,
27.700000000000003,
],
Array [
-122.498986,
37.768616,
29.290000000000003,
],
Array [
-122.4981,
37.76889,
31.14,
],
Array [
-122.4976,
37.76902,
31.67,
],
Array [
-122.497045,
37.769135,
32.480000000000004,
],
Array [
-122.49649,
37.76925,
33.29,
],
Array [
-122.49616,
37.76927,
33.59,
],
Array [
-122.49556,
37.76937,
34.82,
],
Array [
-122.49527,
37.76945,
35.77,
],
Array [
-122.49497,
37.76956,
35.77,
],
Array [
-122.49411,
37.77008,
40.14,
],
Array [
-122.49371,
37.77028,
40.900000000000006,
],
Array [
-122.49285,
37.77058,
40.59,
],
Array [
-122.49196,
37.7708,
38.62,
],
Array [
-122.49123,
37.77093,
38.71,
],
Array [
-122.49092,
37.77096,
39.13,
],
Array [
-122.49056,
37.77096,
39.5,
],
Array [
-122.49021,
37.77093,
39.89,
],
Array [
-122.48923,
37.7708,
41.02,
],
Array [
-122.48888,
37.77077,
41.300000000000004,
],
Array [
-122.48851,
37.77076,
41.56,
],
Array [
-122.48815,
37.77078,
42.160000000000004,
],
Array [
-122.48774,
37.77083,
42.63,
],
],
"type": "LineString",
},
"properties": Object {
"coordinateProperties": Object {
"times": Array [
"2021-08-02T18:28:31+00:00",
"2021-08-02T18:28:38+00:00",
"2021-08-02T18:28:46+00:00",
"2021-08-02T18:28:54+00:00",
"2021-08-02T18:29:02+00:00",
"2021-08-02T18:29:10+00:00",
"2021-08-02T18:29:18+00:00",
"2021-08-02T18:29:26+00:00",
"2021-08-02T18:29:34+00:00",
"2021-08-02T18:29:42+00:00",
"2021-08-02T18:29:50+00:00",
"2021-08-02T18:29:58+00:00",
"2021-08-02T18:30:06+00:00",
"2021-08-02T18:30:14+00:00",
"2021-08-02T18:30:22+00:00",
"2021-08-02T18:30:30+00:00",
"2021-08-02T18:30:38+00:00",
"2021-08-02T18:30:46+00:00",
"2021-08-02T18:30:54+00:00",
"2021-08-02T18:31:02+00:00",
"2021-08-02T18:31:10+00:00",
"2021-08-02T18:31:18+00:00",
"2021-08-02T18:31:26+00:00",
"2021-08-02T18:31:34+00:00",
"2021-08-02T18:31:42+00:00",
"2021-08-02T18:31:50+00:00",
"2021-08-02T18:31:58+00:00",
"2021-08-02T18:32:06+00:00",
"2021-08-02T18:32:13+00:00",
"2021-08-02T18:32:21+00:00",
],
},
"distanceMeters": 1664.4491785197054,
"name": "Test TCX Route",
"totalTimeSeconds": 238.91313879712945,
},
"type": "Feature",
},
],
"type": "FeatureCollection",
}
`

exports[`test/index.test.js TAP toGeoJSON > timespan.kml 1`] = `
Object {
"features": Array [
Expand Down
Loading

0 comments on commit 8924925

Please sign in to comment.