From dcec6d4b7776211fc718dda097d8de2de7eb3f1f Mon Sep 17 00:00:00 2001 From: Norbert Renner Date: Tue, 2 Aug 2022 20:02:23 +0200 Subject: [PATCH] Add GPX link (brouter#152) --- config.template.js | 2 ++ js/format/Gpx.js | 6 +++++- tests/format/Gpx.test.js | 21 ++++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/config.template.js b/config.template.js index 3a410e9..571ffbe 100644 --- a/config.template.js +++ b/config.template.js @@ -30,6 +30,8 @@ //BR.conf.profilesUrl = 'file://YOUR_PATH_TO/profiles2/'; } + // name of the web app/instance, e.g. used as GPX creator and link text + BR.conf.appName = 'BRouter-Web'; BR.conf.privacyPolicyUrl = '/privacypolicy.html'; // Set the initial position and zoom level of the map diff --git a/js/format/Gpx.js b/js/format/Gpx.js index 1e4ca80..9c65b69 100644 --- a/js/format/Gpx.js +++ b/js/format/Gpx.js @@ -36,6 +36,10 @@ BR.Gpx = { return Object.assign( { name: feature.properties.name, + link: { + '@href': location.href, + text: BR.conf.appName || 'BRouter-Web', + }, }, trk ); @@ -50,7 +54,7 @@ BR.Gpx = { const gpxTransform = new GpxTransform(voiceHintsTransform); let gpx = togpx(geoJson, { - creator: 'BRouter-Web ' + BR.version, + creator: (BR.conf.appName || 'BRouter-Web') + ' ' + BR.version, featureTitle: function () {}, featureDescription: function () {}, featureCoordTimes: function () {}, diff --git a/tests/format/Gpx.test.js b/tests/format/Gpx.test.js index 2809c9e..88f02fd 100644 --- a/tests/format/Gpx.test.js +++ b/tests/format/Gpx.test.js @@ -4,6 +4,7 @@ BR = {}; BR.version = '1.5.1'; +BR.conf = {}; turf = require('@turf/turf'); togpx = require('togpx'); require('leaflet'); @@ -48,15 +49,21 @@ function read(fileName, replaceCreator) { return adoptGpx(fs.readFileSync(path + fileName, 'utf8'), replaceCreator); } +function format(geoJson, turnInstructionMode) { + let gpx = BR.Gpx.format(geoJson, turnInstructionMode); + gpx = gpx.replace(/\s*?/, ''); + return gpx; +} + test('simple track', () => { const brouterGpx = read('track.gpx'); - const gpx = BR.Gpx.format(geoJson); + const gpx = format(geoJson); expect(gpx).toEqual(brouterGpx); }); test('waypoints', () => { const brouterGpx = BR.Xml.pretty(read('waypoints.gpx')); - const gpx = BR.Gpx.format(waypointsGeoJson, 5); + const gpx = format(waypointsGeoJson, 5); expect(gpx).toEqual(brouterGpx); }); @@ -71,13 +78,13 @@ describe('voice hints', () => { // ignore off by one due to times passed with 3 decimals brouterGpx = brouterGpx.replace('rteSpeed>9.361<', 'rteSpeed>9.360<'); - const gpx = BR.Gpx.format(geoJson, 2); + const gpx = format(geoJson, 2); expect(gpx).toEqual(brouterGpx); }); test('3-osmand', () => { const brouterGpx = BR.Xml.pretty(read('3-osmand.gpx', false)); - const gpx = BR.Gpx.format(geoJson, 3); + const gpx = format(geoJson, 3); expect(gpx).toEqual(brouterGpx); }); @@ -85,19 +92,19 @@ describe('voice hints', () => { let brouterGpx = read('4-comment.gpx'); brouterGpx = brouterGpx.replace(/;\s*([-0-9]+.[0-9]+?)0+;/g, (match, p1) => `;${p1.padStart(10)};`); // remove trailing zeros - const gpx = BR.Gpx.format(geoJson, 4); + const gpx = format(geoJson, 4); expect(gpx).toEqual(brouterGpx); }); test('5-gpsies', () => { const brouterGpx = read('5-gpsies.gpx'); - const gpx = BR.Gpx.format(geoJson, 5); + const gpx = format(geoJson, 5); expect(gpx).toEqual(brouterGpx); }); test('6-orux', () => { let brouterGpx = BR.Xml.pretty(read('6-orux.gpx')); - const gpx = BR.Gpx.format(geoJson, 6); + const gpx = format(geoJson, 6); expect(gpx).toEqual(brouterGpx); }); });