diff --git a/js/control/Export.js b/js/control/Export.js index f59f305..55fac1a 100644 --- a/js/control/Export.js +++ b/js/control/Export.js @@ -69,11 +69,10 @@ BR.Export = L.Class.extend({ _formatTrack: function (format, name, includeWaypoints) { const track = BR.Export._concatTotalTrack(this.segments); + this._addPois(track); if (includeWaypoints) { this._addRouteWaypoints(track); } - //console.log('GeoJson: ', trackGeoJson); - //console.log('GeoJson: ', JSON.stringify(trackGeoJson, null, 4)); switch (format) { case 'gpx': const turnInstructionMode = +this.profile.getProfileVar('turnInstructionMode'); @@ -88,8 +87,16 @@ BR.Export = L.Class.extend({ 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) { - const routePoints = []; for (const [i, latLng] of this.latLngs.entries()) { let name = 'via' + i; let type = 'via'; @@ -101,9 +108,9 @@ BR.Export = L.Class.extend({ type = 'to'; } 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 () { diff --git a/js/format/Gpx.js b/js/format/Gpx.js index b3ad6d4..8c6c295 100644 --- a/js/format/Gpx.js +++ b/js/format/Gpx.js @@ -22,8 +22,9 @@ BR.Gpx = { if (feature.properties.name) { wpt.name = feature.properties.name; } - if (feature.properties.type) { - wpt.type = feature.properties.type; + const type = feature.properties.type; + if (type && type !== 'poi') { + wpt.type = type; } return wpt; } diff --git a/tests/control/Export.test.js b/tests/control/Export.test.js index e95b9b3..72b003d 100644 --- a/tests/control/Export.test.js +++ b/tests/control/Export.test.js @@ -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'); +}); diff --git a/tests/format/data/waypoints.gpx b/tests/format/data/waypoints.gpx index 865da04..86ac624 100644 --- a/tests/format/data/waypoints.gpx +++ b/tests/format/data/waypoints.gpx @@ -8,6 +8,12 @@ rightrightRight leftleftLeft leftleftLeft + + poi 1 + + + poi 2 + from from diff --git a/tests/format/data/waypoints.json b/tests/format/data/waypoints.json index 3df0648..51ef8fb 100644 --- a/tests/format/data/waypoints.json +++ b/tests/format/data/waypoints.json @@ -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": {