Format POIs
This commit is contained in:
parent
7fc2f6bee5
commit
da9ffd9224
5 changed files with 86 additions and 15 deletions
|
|
@ -69,11 +69,10 @@ BR.Export = L.Class.extend({
|
||||||
|
|
||||||
_formatTrack: function (format, name, includeWaypoints) {
|
_formatTrack: function (format, name, includeWaypoints) {
|
||||||
const track = BR.Export._concatTotalTrack(this.segments);
|
const track = BR.Export._concatTotalTrack(this.segments);
|
||||||
|
this._addPois(track);
|
||||||
if (includeWaypoints) {
|
if (includeWaypoints) {
|
||||||
this._addRouteWaypoints(track);
|
this._addRouteWaypoints(track);
|
||||||
}
|
}
|
||||||
//console.log('GeoJson: ', trackGeoJson);
|
|
||||||
//console.log('GeoJson: ', JSON.stringify(trackGeoJson, null, 4));
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case 'gpx':
|
case 'gpx':
|
||||||
const turnInstructionMode = +this.profile.getProfileVar('turnInstructionMode');
|
const turnInstructionMode = +this.profile.getProfileVar('turnInstructionMode');
|
||||||
|
|
@ -88,8 +87,16 @@ BR.Export = L.Class.extend({
|
||||||
console.error('Export format not implemented: ' + format);
|
console.error('Export format not implemented: ' + format);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_addPois: function (track) {
|
||||||
|
const markers = this.pois.getMarkers();
|
||||||
|
for (const poi of markers) {
|
||||||
|
const properties = { name: poi.name, type: 'poi' };
|
||||||
|
const point = turf.point([poi.latlng.lng, poi.latlng.lat], properties);
|
||||||
|
track.features.push(point);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_addRouteWaypoints: function (track) {
|
_addRouteWaypoints: function (track) {
|
||||||
const routePoints = [];
|
|
||||||
for (const [i, latLng] of this.latLngs.entries()) {
|
for (const [i, latLng] of this.latLngs.entries()) {
|
||||||
let name = 'via' + i;
|
let name = 'via' + i;
|
||||||
let type = 'via';
|
let type = 'via';
|
||||||
|
|
@ -101,9 +108,9 @@ BR.Export = L.Class.extend({
|
||||||
type = 'to';
|
type = 'to';
|
||||||
}
|
}
|
||||||
const properties = { name, type };
|
const properties = { name, type };
|
||||||
routePoints.push(turf.point([latLng.lng, latLng.lat], properties));
|
const point = turf.point([latLng.lng, latLng.lat], properties);
|
||||||
|
track.features.push(point);
|
||||||
}
|
}
|
||||||
track.features.push(...routePoints);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_validationMessage: function () {
|
_validationMessage: function () {
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,9 @@ BR.Gpx = {
|
||||||
if (feature.properties.name) {
|
if (feature.properties.name) {
|
||||||
wpt.name = feature.properties.name;
|
wpt.name = feature.properties.name;
|
||||||
}
|
}
|
||||||
if (feature.properties.type) {
|
const type = feature.properties.type;
|
||||||
wpt.type = feature.properties.type;
|
if (type && type !== 'poi') {
|
||||||
|
wpt.type = type;
|
||||||
}
|
}
|
||||||
return wpt;
|
return wpt;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,20 @@ function adopt(total, brouterTotal) {
|
||||||
total.features[0].properties.name = brouterTotal.features[0].properties.name;
|
total.features[0].properties.name = brouterTotal.features[0].properties.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let track;
|
||||||
|
const getLngCoord = (i) => track.features[i].geometry.coordinates[0];
|
||||||
|
const getProperty = (i, p) => track.features[i].properties[p];
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
document.body = indexHtml.body.cloneNode(true);
|
document.body = indexHtml.body.cloneNode(true);
|
||||||
|
|
||||||
|
track = turf.featureCollection([
|
||||||
|
turf.lineString([
|
||||||
|
[0, 0],
|
||||||
|
[1, 1],
|
||||||
|
[2, 2],
|
||||||
|
]),
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('total track', () => {
|
test('total track', () => {
|
||||||
|
|
@ -50,15 +62,7 @@ test('total track', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('include route points', () => {
|
test('include route points', () => {
|
||||||
const getLngCoord = (i) => track.features[i].geometry.coordinates[0];
|
|
||||||
const getProperty = (i, p) => track.features[i].properties[p];
|
|
||||||
const latLngs = [L.latLng(0, 0), L.latLng(1, 1), L.latLng(2, 2)];
|
const latLngs = [L.latLng(0, 0), L.latLng(1, 1), L.latLng(2, 2)];
|
||||||
const trackFeature = turf.lineString([
|
|
||||||
[0, 0],
|
|
||||||
[1, 1],
|
|
||||||
[2, 2],
|
|
||||||
]);
|
|
||||||
const track = turf.featureCollection([trackFeature]);
|
|
||||||
const exportRoute = new BR.Export();
|
const exportRoute = new BR.Export();
|
||||||
|
|
||||||
exportRoute.update(latLngs, null);
|
exportRoute.update(latLngs, null);
|
||||||
|
|
@ -75,3 +79,28 @@ test('include route points', () => {
|
||||||
expect(getProperty(2, 'type')).toEqual('via');
|
expect(getProperty(2, 'type')).toEqual('via');
|
||||||
expect(getProperty(3, 'type')).toEqual('to');
|
expect(getProperty(3, 'type')).toEqual('to');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('pois', () => {
|
||||||
|
const markers = [
|
||||||
|
{
|
||||||
|
latlng: L.latLng(1, 1),
|
||||||
|
name: 'poi 1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
latlng: L.latLng(2, 2),
|
||||||
|
name: 'poi 2',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const pois = { getMarkers: () => markers };
|
||||||
|
const exportRoute = new BR.Export(null, pois, null);
|
||||||
|
|
||||||
|
exportRoute._addPois(track);
|
||||||
|
|
||||||
|
expect(track.features[0].geometry.type).toEqual('LineString');
|
||||||
|
expect(getLngCoord(1)).toEqual(1);
|
||||||
|
expect(getLngCoord(2)).toEqual(2);
|
||||||
|
expect(getProperty(1, 'name')).toEqual('poi 1');
|
||||||
|
expect(getProperty(2, 'name')).toEqual('poi 2');
|
||||||
|
expect(getProperty(1, 'type')).toEqual('poi');
|
||||||
|
expect(getProperty(2, 'type')).toEqual('poi');
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,12 @@
|
||||||
<wpt lon="8.468340" lat="49.488794"><name>right</name><sym>right</sym><type>Right</type></wpt>
|
<wpt lon="8.468340" lat="49.488794"><name>right</name><sym>right</sym><type>Right</type></wpt>
|
||||||
<wpt lon="8.469971" lat="49.488151"><name>left</name><sym>left</sym><type>Left</type></wpt>
|
<wpt lon="8.469971" lat="49.488151"><name>left</name><sym>left</sym><type>Left</type></wpt>
|
||||||
<wpt lon="8.470671" lat="49.488909"><name>left</name><sym>left</sym><type>Left</type></wpt>
|
<wpt lon="8.470671" lat="49.488909"><name>left</name><sym>left</sym><type>Left</type></wpt>
|
||||||
|
<wpt lon="8.469279" lat="49.487399">
|
||||||
|
<name>poi 1</name>
|
||||||
|
</wpt>
|
||||||
|
<wpt lon="8.469021" lat="49.489532">
|
||||||
|
<name>poi 2</name>
|
||||||
|
</wpt>
|
||||||
<wpt lon="8.467712" lat="49.488117">
|
<wpt lon="8.467712" lat="49.488117">
|
||||||
<name>from</name>
|
<name>from</name>
|
||||||
<type>from</type>
|
<type>from</type>
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,34 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "Feature",
|
||||||
|
"properties": {
|
||||||
|
"name": "poi 1",
|
||||||
|
"type": "poi"
|
||||||
|
},
|
||||||
|
"geometry": {
|
||||||
|
"type": "Point",
|
||||||
|
"coordinates": [
|
||||||
|
8.469279,
|
||||||
|
49.487399
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Feature",
|
||||||
|
"properties": {
|
||||||
|
"name": "poi 2",
|
||||||
|
"type": "poi"
|
||||||
|
},
|
||||||
|
"geometry": {
|
||||||
|
"type": "Point",
|
||||||
|
"coordinates": [
|
||||||
|
8.469021,
|
||||||
|
49.489532
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "Feature",
|
"type": "Feature",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue