Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added export format tcx (incl. pace in kmh) #313

Merged
merged 6 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ <h1 ng-bind-html="('DOWNLOAD_ROUTE' | translate)">
</div>
</div>
</div>
<div ng-if="$ctrl.tcxOptShow">
<br>
<label ng-bind-html="('PACE_SPEED_INKMH' | translate)">
</label>
<div class="ui input">
<input ng-model="$ctrl.speedInKmh" required="" select-on-click="" type="number" step="0.1" min="1" max="50">
</div>
</div>
<div class="ui divider">
</div>
<button class="ui mini button" ng-bind-html="('DOWNLOAD' | translate)" ng-click="$ctrl.exportRoute()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ angular
ctrl.elevation = true;
ctrl.instructions = false;
ctrl.toGpx = true;
ctrl.speedInKmh = 9.5;
ctrl.filename = "ors-export-linestring";
ctrl.gpxOptShow = true;
ctrl.tcxOptShow = false;
Expand All @@ -26,6 +27,10 @@ angular
text: "Keyhole Markup Language (.kml)",
value: "kml"
},
{
text: "GarminTCX (.tcx)",
value: "tcx"
},
{
text: "GeoJSON (.geojson)",
value: "geojson"
Expand Down Expand Up @@ -90,7 +95,8 @@ angular
let options = {
elevation: ctrl.elevation,
instructions: ctrl.instructions,
toGpx: ctrl.toGpx
toGpx: ctrl.toGpx,
speedInKmh: ctrl.speedInKmh
};
let currentRoute = null;
if (ctrl.currentFileFormat === "rawjson") {
Expand Down
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<script src="bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.js"></script>
<script src="node_modules/@angular/router/angular1/angular_1_router.js"></script>
<script src="node_modules/geojson/geojson.min.js"></script>
<script src="node_modules/jxon/jxon.js"></script>
<script src="node_modules/togpx/togpx.js"></script>
<script src="node_modules/xml-js/dist/xml-js.min.js"></script>
<script src="node_modules/tokml/tokml.js"></script>
Expand Down
87 changes: 87 additions & 0 deletions app/infrastructure/ors-importexport-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,90 @@ angular
);
};

// create a simple Course TCX file (MARQ24)
// see https://www8.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd
let toTcx = (name, speedInKmPerH) => {
let version = "0.4.1"
let pointInformation = orsRouteService.data.features[orsRouteService.getCurrentRouteIdx()].point_information
let [majorV, minorV, patchV] = version.split('.')
let garminPartNumber = `ORS-0${majorV}${minorV}${patchV}0-DE`
let tcx = {
TrainingCenterDatabase: {
"@xsi:schemaLocation":
"http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd",
"@xmlns":
"http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2",
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
Courses: { Course: [] },
Author: {
"@xsi:type": "Application_t",
Name: "openrouteservice.org",
Build: {
Version: {
VersionMajor: majorV,
VersionMinor: minorV,
BuildMajor: patchV,
BuildMinor: "0"
},
Type: "Release",
Time: "Jan 26 2020, 10:00:00",
Builder: "mcp"
},
LangID: "DE", PartNumber: garminPartNumber // The formatted XXX-XXXXX-XX Garmin part number of a PC application
}
}
};

let speedInMPerS = speedInKmPerH / 3.6; // need to convert in m per sec
let courseObj = {
Name: name,
Lap: {
TotalTimeSeconds: "",
DistanceMeters: pointInformation[pointInformation.length - 1].distance,
BeginPosition: {
LatitudeDegrees: pointInformation[0].coords[0],
LongitudeDegrees: pointInformation[0].coords[1]
},
EndPosition: {
LatitudeDegrees: pointInformation[pointInformation.length - 1].coords[0],
LongitudeDegrees: pointInformation[pointInformation.length - 1].coords[1]
},
Intensity: "Active"
},
Track: { Trackpoint: [] }
}
let duration
for (const data of pointInformation) {
if (data.distance !== undefined) {
duration = data.distance / speedInMPerS;
const seconds = duration.toFixed(3) || 0
const milliSeconds = seconds.split('.')[1] || 0
let durationDate = new Date(2010,0,1,12,0,seconds, milliSeconds)
let tp = {
Time: durationDate.toISOString(),
Position: {
LatitudeDegrees: data.coords[0],
LongitudeDegrees: data.coords[1]
}
}
if (
data.heights &&
data.heights.height !== undefined
) {
tp.AltitudeMeters = data.heights.height;
}
tp.DistanceMeters = data.distance;
courseObj.Track.Trackpoint.push(tp);
}
}
courseObj.Lap.TotalTimeSeconds = duration.toFixed(1);
tcx.TrainingCenterDatabase.Courses.Course.push(courseObj);

JXON.config({ attrPrefix: "@" });
const tcx_str = JXON.stringify(tcx)
return '<?xml version="1.0" encoding="UTF-8"?>' + tcx_str;
};

let orsExportFactory = {};
/**
* Export any vector element on the map to file
Expand Down Expand Up @@ -110,6 +194,9 @@ angular
geojsonData = L.polyline(geometry).toGeoJSON();
exportData = tokml(geojsonData);
break;
case "tcx":
exportData = toTcx(filename, options.speedInKmh);
break;
case "rawjson":
// removing nodes from the geometry data that is for sure not needed
// by 3'rd party...
Expand Down
3 changes: 2 additions & 1 deletion app/languages/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,6 @@
"ROUNDTRIP_PREVIOUS": "Letzter Rundweg",
"ROUNDTRIP_NEXT": "Nächster Rundweg",
"ROUNDTRIP": "Rundweg (experimentell)",
"ROUNDTRIP_DO": "Rundweg generieren"
"ROUNDTRIP_DO": "Rundweg generieren",
"PACE_SPEED_INKMH": "Pace in km/h"
}
3 changes: 2 additions & 1 deletion app/languages/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,6 @@
"ROUNDTRIP_PREVIOUS": "Previous round trip",
"ROUNDTRIP_NEXT": "Next round trip",
"ROUNDTRIP": "Round trip (experimental)",
"ROUNDTRIP_DO": "Do round trip"
"ROUNDTRIP_DO": "Do round trip",
"PACE_SPEED_INKMH": "Pace in km/h"
}
3 changes: 2 additions & 1 deletion app/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,6 @@
"ROUNDTRIP_PREVIOUS": "Previous round trip",
"ROUNDTRIP_NEXT": "Next round trip",
"ROUNDTRIP": "Round trip (experimental)",
"ROUNDTRIP_DO": "Do round trip"
"ROUNDTRIP_DO": "Do round trip",
"PACE_SPEED_INKMH": "Pace in km/h"
}
3 changes: 2 additions & 1 deletion app/languages/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,6 @@
"ROUNDTRIP_PREVIOUS": "Previous round trip",
"ROUNDTRIP_NEXT": "Next round trip",
"ROUNDTRIP": "Round trip (experimental)",
"ROUNDTRIP_DO": "Do round trip"
"ROUNDTRIP_DO": "Do round trip",
"PACE_SPEED_INKMH": "Pace in km/h"
}
3 changes: 2 additions & 1 deletion app/languages/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,6 @@
"ROUNDTRIP_PREVIOUS": "Previous round trip",
"ROUNDTRIP_NEXT": "Next round trip",
"ROUNDTRIP": "Round trip (experimental)",
"ROUNDTRIP_DO": "Do round trip"
"ROUNDTRIP_DO": "Do round trip",
"PACE_SPEED_INKMH": "Pace in km/h"
}
3 changes: 2 additions & 1 deletion app/languages/hu-HU.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,6 @@
"ROUNDTRIP_PREVIOUS": "Previous round trip",
"ROUNDTRIP_NEXT": "Next round trip",
"ROUNDTRIP": "Round trip (experimental)",
"ROUNDTRIP_DO": "Do round trip"
"ROUNDTRIP_DO": "Do round trip",
"PACE_SPEED_INKMH": "Pace in km/h"
}
3 changes: 2 additions & 1 deletion app/languages/id-ID.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,6 @@
"ROUNDTRIP_PREVIOUS": "Previous round trip",
"ROUNDTRIP_NEXT": "Next round trip",
"ROUNDTRIP": "Round trip (experimental)",
"ROUNDTRIP_DO": "Do round trip"
"ROUNDTRIP_DO": "Do round trip",
"PACE_SPEED_INKMH": "Pace in km/h"
}
3 changes: 2 additions & 1 deletion app/languages/it-IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,6 @@
"ROUNDTRIP_PREVIOUS": "Previous round trip",
"ROUNDTRIP_NEXT": "Next round trip",
"ROUNDTRIP": "Round trip (experimental)",
"ROUNDTRIP_DO": "Do round trip"
"ROUNDTRIP_DO": "Do round trip",
"PACE_SPEED_INKMH": "Pace in km/h"
}
3 changes: 2 additions & 1 deletion app/languages/pl-PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,6 @@
"ROUNDTRIP_PREVIOUS": "Previous round trip",
"ROUNDTRIP_NEXT": "Next round trip",
"ROUNDTRIP": "Round trip (experimental)",
"ROUNDTRIP_DO": "Do round trip"
"ROUNDTRIP_DO": "Do round trip",
"PACE_SPEED_INKMH": "Pace in km/h"
}
3 changes: 2 additions & 1 deletion app/languages/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,6 @@
"ROUNDTRIP_PREVIOUS": "Previous round trip",
"ROUNDTRIP_NEXT": "Next round trip",
"ROUNDTRIP": "Round trip (experimental)",
"ROUNDTRIP_DO": "Do round trip"
"ROUNDTRIP_DO": "Do round trip",
"PACE_SPEED_INKMH": "Pace in km/h"
}
3 changes: 2 additions & 1 deletion app/languages/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,6 @@
"ROUNDTRIP_PREVIOUS": "Previous round trip",
"ROUNDTRIP_NEXT": "Next round trip",
"ROUNDTRIP": "Round trip (experimental)",
"ROUNDTRIP_DO": "Do round trip"
"ROUNDTRIP_DO": "Do round trip",
"PACE_SPEED_INKMH": "Pace in km/h"
}
3 changes: 2 additions & 1 deletion app/languages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,6 @@
"ROUNDTRIP_PREVIOUS": "Previous round trip",
"ROUNDTRIP_NEXT": "Next round trip",
"ROUNDTRIP": "Round trip (experimental)",
"ROUNDTRIP_DO": "Do round trip"
"ROUNDTRIP_DO": "Do round trip",
"PACE_SPEED_INKMH": "Pace in km/h"
}