Add GPX link (brouter#152)

This commit is contained in:
Norbert Renner 2022-08-02 20:02:23 +02:00
parent 86bd64a43f
commit dcec6d4b77
3 changed files with 21 additions and 8 deletions

View file

@ -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

View file

@ -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 () {},

View file

@ -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*?<link [\s\S]*?<\/link>/, '');
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);
});
});