Format Locus voice hint, with additional hint data
This commit is contained in:
parent
a9d27b4674
commit
fd0ece0d31
5 changed files with 152 additions and 39 deletions
|
|
@ -1,25 +1,29 @@
|
|||
BR.Gpx = {
|
||||
format: function (geoJson, turnInstructionMode = 0) {
|
||||
if (!geoJson) return '';
|
||||
format: function (geoJson, turnInstructionMode = 0, transportMode = 'bike') {
|
||||
if (!geoJson?.features) return '';
|
||||
|
||||
const trkNameTransform = {
|
||||
trk: function (trk, feature, coordsList) {
|
||||
// name as first tag, by using assign and in this order
|
||||
return Object.assign(
|
||||
{
|
||||
name: feature.properties.name,
|
||||
},
|
||||
trk
|
||||
);
|
||||
},
|
||||
};
|
||||
let gpxTransform = trkNameTransform;
|
||||
|
||||
if (turnInstructionMode > 0) {
|
||||
BR.Gpx._addVoiceHints(geoJson, turnInstructionMode);
|
||||
const voiceHints = BR.voiceHints(geoJson);
|
||||
gpxTransform = voiceHints.getGpxTransform(turnInstructionMode, transportMode);
|
||||
}
|
||||
|
||||
let gpx = togpx(geoJson, {
|
||||
featureTitle: function () {},
|
||||
featureDescription: function () {},
|
||||
transform: {
|
||||
trk: function (trk, feature, coordsList) {
|
||||
return {
|
||||
name: feature.properties.name,
|
||||
trkseg: trk.trkseg,
|
||||
};
|
||||
},
|
||||
wpt: function (wpt, feature, coord, index) {
|
||||
return Object.assign(wpt, feature.properties);
|
||||
},
|
||||
},
|
||||
transform: gpxTransform,
|
||||
});
|
||||
const statsComment = BR.Gpx._statsComment(geoJson);
|
||||
gpx = '<?xml version="1.0" encoding="UTF-8"?>' + statsComment + gpx;
|
||||
|
|
@ -27,13 +31,6 @@ BR.Gpx = {
|
|||
return gpx;
|
||||
},
|
||||
|
||||
_addVoiceHints: function (geoJson, turnInstructionMode) {
|
||||
if (!geoJson.features) return;
|
||||
|
||||
const voiceHints = BR.voiceHints(geoJson);
|
||||
voiceHints.add(turnInstructionMode);
|
||||
},
|
||||
|
||||
// <!-- track-length = 319 filtered ascend = 2 plain-ascend = -1 cost=533 energy=.0kwh time=44s -->
|
||||
_statsComment: function (geoJson) {
|
||||
const props = geoJson.features?.[0].properties;
|
||||
|
|
@ -68,8 +65,8 @@ BR.Gpx = {
|
|||
// Remove all the newlines and then remove all the spaces between tags
|
||||
xml = xml.replace(/\s*(\r\n|\n|\r)\s*/gm, ' ').replace(/>\s+</g, '><');
|
||||
|
||||
// break into lines, keep trkpt with subelement ele in single line
|
||||
const reg = /(>)(<)(?!ele|\/trkpt)(\/?)/g;
|
||||
// break into lines
|
||||
const reg = /(>)(<)(\/?)/g;
|
||||
let pad = 0;
|
||||
|
||||
xml = xml.replace('<metadata/>', '');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue