From 819d0fbf22dbe4f102b657183ef5a20ef1728c57 Mon Sep 17 00:00:00 2001 From: Norbert Renner Date: Mon, 1 Mar 2021 10:16:02 +0100 Subject: [PATCH] Format OruxMaps voice hints --- js/format/VoiceHints.js | 30 +++++++++++++++++++++++++++++- tests/format/Gpx.test.js | 7 +++++++ tests/format/data/6-orux.gpx | 30 ++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/format/data/6-orux.gpx diff --git a/js/format/VoiceHints.js b/js/format/VoiceHints.js index b1796f7..030b02c 100644 --- a/js/format/VoiceHints.js +++ b/js/format/VoiceHints.js @@ -190,6 +190,26 @@ }, }); + BR.OruxVoiceHints = BR.WaypointVoiceHints.extend({ + _getWpt: function (hint, cmd, coord) { + const wpt = { + ele: coord[2], + extensions: { + 'om:oruxmapsextensions': { + '@xmlns:om': 'http://www.oruxmaps.com/oruxmapsextensions/1/0', + 'om:ext': { '@type': 'ICON', '@subtype': 0, _: cmd.orux }, + }, + }, + }; + + if (wpt.ele === undefined || wpt.ele === null) { + delete wpt.ele; + } + + return wpt; + }, + }); + BR.LocusVoiceHints = BR.WaypointVoiceHints.extend({ _addToTransform: function (transform) { transform.gpx = function (gpx, features) { @@ -219,11 +239,17 @@ } extensions['locus:rtePointAction'] = cmd.locus; - return { + const wpt = { ele: coord[2], name: cmd.message, extensions: extensions, }; + + if (wpt.ele === undefined || wpt.ele === null) { + delete wpt.ele; + } + + return wpt; }, _getTrk: function () { @@ -355,6 +381,8 @@ return new BR.CommentVoiceHints(geoJson, turnInstructionMode, transportMode); case 5: return new BR.GpsiesVoiceHints(geoJson, turnInstructionMode, transportMode); + case 6: + return new BR.OruxVoiceHints(geoJson, turnInstructionMode, transportMode); default: console.error('unhandled turnInstructionMode: ' + turnInstructionMode); return new BR.VoiceHints(geoJson, turnInstructionMode, transportMode); diff --git a/tests/format/Gpx.test.js b/tests/format/Gpx.test.js index 1fbdb4b..4b13234 100644 --- a/tests/format/Gpx.test.js +++ b/tests/format/Gpx.test.js @@ -72,4 +72,11 @@ describe('voice hints', () => { const gpx = BR.Gpx.format(geoJson, 5); expect(gpx).toEqual(brouterGpx); }); + + test('6-orux', () => { + let brouterGpx = read('6-orux.gpx'); + brouterGpx = brouterGpx.replace(/<(\/?)om:/g, '<$1'); // TODO namespace + const gpx = BR.Gpx.format(geoJson, 6); + expect(gpx).toEqual(brouterGpx); + }); }); diff --git a/tests/format/data/6-orux.gpx b/tests/format/data/6-orux.gpx new file mode 100644 index 0000000..32482cd --- /dev/null +++ b/tests/format/data/6-orux.gpx @@ -0,0 +1,30 @@ + + + + 101.5 + +1001 + + + 103.5 + +1000 + + + + 6-orux + + 101.5 + 101.5 + 101.5 + 101.5 + 101.75 + 103.5 + 99.75 + + +