Skip to content

Commit

Permalink
feat: Add coordinate properties for times and heartRates (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
RalucaNicola authored Mar 31, 2021
1 parent 8e00733 commit 5e3958b
Show file tree
Hide file tree
Showing 4 changed files with 3,612 additions and 3,548 deletions.
31 changes: 20 additions & 11 deletions lib/gpx.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ function getTrack(node) {
{ _gpxType: "trk" },
times.length
? {
coordTimes: multi ? times : times[0],
coordinateProperties: {
times: multi ? times : times[0],
}
}
: {}
);
Expand All @@ -176,14 +178,21 @@ function getTrack(node) {
const line = extractedLines[i];
track.push(line.line);
for (const [name, val] of Object.entries(line.extendedValues)) {
let props = properties;
if (name === "heartRates") {
if (!properties.coordinateProperties) {
properties.coordinateProperties = {};
}
props = properties.coordinateProperties;
}
if (multi) {
if (!properties[name])
properties[name] = extractedLines.map((line) =>
if (!props[name])
props[name] = extractedLines.map((line) =>
new Array(line.line.length).fill(null)
);
properties[name][i] = val;
props[name][i] = val;
} else {
properties[name] = val;
props[name] = val;
}
}
}
Expand All @@ -193,13 +202,13 @@ function getTrack(node) {
properties: properties,
geometry: multi
? {
type: "MultiLineString",
coordinates: track,
}
type: "MultiLineString",
coordinates: track,
}
: {
type: "LineString",
coordinates: track[0],
},
type: "LineString",
coordinates: track[0],
},
};
}

Expand Down
7 changes: 4 additions & 3 deletions lib/kml.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,11 @@ function getPlacemark(root, styleIndex, styleMapIndex, styleByHash) {
properties.visibility = nodeVal(visibility);
}
if (geomsAndTimes.coordTimes.length) {
properties.coordTimes =
geomsAndTimes.coordTimes.length === 1
properties.coordinateProperties = {
times: geomsAndTimes.coordTimes.length === 1
? geomsAndTimes.coordTimes[0]
: geomsAndTimes.coordTimes;
: geomsAndTimes.coordTimes
};
}
const feature = {
type: "Feature",
Expand Down
20 changes: 16 additions & 4 deletions lib/tcx.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,22 @@ function getLap(node) {
}
}
if (track.length === 0) return;
if (times.length)
properties.coordTimes = track.length === 1 ? times[0] : times;
if (heartRates.length)
properties.heartRates = track.length === 1 ? heartRates[0] : heartRates;

if (times.length || heartRates.length) {
properties.coordinateProperties = Object.assign(
times.length
? {
times: track.length === 1 ? times[0] : times,
}
: {},
heartRates.length
? {
heartRates: track.length === 1 ? heartRates[0] : heartRates,
}
: {}
);
}

return {
type: "Feature",
properties: properties,
Expand Down
Loading

0 comments on commit 5e3958b

Please sign in to comment.