Add GPX link (brouter#152)
This commit is contained in:
parent
86bd64a43f
commit
dcec6d4b77
3 changed files with 21 additions and 8 deletions
|
|
@ -30,6 +30,8 @@
|
||||||
//BR.conf.profilesUrl = 'file://YOUR_PATH_TO/profiles2/';
|
//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';
|
BR.conf.privacyPolicyUrl = '/privacypolicy.html';
|
||||||
|
|
||||||
// Set the initial position and zoom level of the map
|
// Set the initial position and zoom level of the map
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ BR.Gpx = {
|
||||||
return Object.assign(
|
return Object.assign(
|
||||||
{
|
{
|
||||||
name: feature.properties.name,
|
name: feature.properties.name,
|
||||||
|
link: {
|
||||||
|
'@href': location.href,
|
||||||
|
text: BR.conf.appName || 'BRouter-Web',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
trk
|
trk
|
||||||
);
|
);
|
||||||
|
|
@ -50,7 +54,7 @@ BR.Gpx = {
|
||||||
const gpxTransform = new GpxTransform(voiceHintsTransform);
|
const gpxTransform = new GpxTransform(voiceHintsTransform);
|
||||||
|
|
||||||
let gpx = togpx(geoJson, {
|
let gpx = togpx(geoJson, {
|
||||||
creator: 'BRouter-Web ' + BR.version,
|
creator: (BR.conf.appName || 'BRouter-Web') + ' ' + BR.version,
|
||||||
featureTitle: function () {},
|
featureTitle: function () {},
|
||||||
featureDescription: function () {},
|
featureDescription: function () {},
|
||||||
featureCoordTimes: function () {},
|
featureCoordTimes: function () {},
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
BR = {};
|
BR = {};
|
||||||
BR.version = '1.5.1';
|
BR.version = '1.5.1';
|
||||||
|
BR.conf = {};
|
||||||
turf = require('@turf/turf');
|
turf = require('@turf/turf');
|
||||||
togpx = require('togpx');
|
togpx = require('togpx');
|
||||||
require('leaflet');
|
require('leaflet');
|
||||||
|
|
@ -48,15 +49,21 @@ function read(fileName, replaceCreator) {
|
||||||
return adoptGpx(fs.readFileSync(path + fileName, 'utf8'), 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', () => {
|
test('simple track', () => {
|
||||||
const brouterGpx = read('track.gpx');
|
const brouterGpx = read('track.gpx');
|
||||||
const gpx = BR.Gpx.format(geoJson);
|
const gpx = format(geoJson);
|
||||||
expect(gpx).toEqual(brouterGpx);
|
expect(gpx).toEqual(brouterGpx);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('waypoints', () => {
|
test('waypoints', () => {
|
||||||
const brouterGpx = BR.Xml.pretty(read('waypoints.gpx'));
|
const brouterGpx = BR.Xml.pretty(read('waypoints.gpx'));
|
||||||
const gpx = BR.Gpx.format(waypointsGeoJson, 5);
|
const gpx = format(waypointsGeoJson, 5);
|
||||||
expect(gpx).toEqual(brouterGpx);
|
expect(gpx).toEqual(brouterGpx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -71,13 +78,13 @@ describe('voice hints', () => {
|
||||||
// ignore off by one due to times passed with 3 decimals
|
// ignore off by one due to times passed with 3 decimals
|
||||||
brouterGpx = brouterGpx.replace('rteSpeed>9.361<', 'rteSpeed>9.360<');
|
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);
|
expect(gpx).toEqual(brouterGpx);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('3-osmand', () => {
|
test('3-osmand', () => {
|
||||||
const brouterGpx = BR.Xml.pretty(read('3-osmand.gpx', false));
|
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);
|
expect(gpx).toEqual(brouterGpx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -85,19 +92,19 @@ describe('voice hints', () => {
|
||||||
let brouterGpx = read('4-comment.gpx');
|
let brouterGpx = read('4-comment.gpx');
|
||||||
brouterGpx = brouterGpx.replace(/;\s*([-0-9]+.[0-9]+?)0+;/g, (match, p1) => `;${p1.padStart(10)};`); // remove trailing zeros
|
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);
|
expect(gpx).toEqual(brouterGpx);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('5-gpsies', () => {
|
test('5-gpsies', () => {
|
||||||
const brouterGpx = read('5-gpsies.gpx');
|
const brouterGpx = read('5-gpsies.gpx');
|
||||||
const gpx = BR.Gpx.format(geoJson, 5);
|
const gpx = format(geoJson, 5);
|
||||||
expect(gpx).toEqual(brouterGpx);
|
expect(gpx).toEqual(brouterGpx);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('6-orux', () => {
|
test('6-orux', () => {
|
||||||
let brouterGpx = BR.Xml.pretty(read('6-orux.gpx'));
|
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);
|
expect(gpx).toEqual(brouterGpx);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue