Format POIs

This commit is contained in:
Norbert Renner 2021-03-19 10:23:37 +01:00
parent 7fc2f6bee5
commit da9ffd9224
5 changed files with 86 additions and 15 deletions

View file

@ -30,8 +30,20 @@ function adopt(total, brouterTotal) {
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(() => {
document.body = indexHtml.body.cloneNode(true);
track = turf.featureCollection([
turf.lineString([
[0, 0],
[1, 1],
[2, 2],
]),
]);
});
test('total track', () => {
@ -50,15 +62,7 @@ test('total track', () => {
});
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 trackFeature = turf.lineString([
[0, 0],
[1, 1],
[2, 2],
]);
const track = turf.featureCollection([trackFeature]);
const exportRoute = new BR.Export();
exportRoute.update(latLngs, null);
@ -75,3 +79,28 @@ test('include route points', () => {
expect(getProperty(2, 'type')).toEqual('via');
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');
});

View file

@ -8,6 +8,12 @@
<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.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">
<name>from</name>
<type>from</type>

View file

@ -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",
"properties": {