Format CSV

This commit is contained in:
Norbert Renner 2021-04-01 12:17:18 +02:00
parent 00f2cead36
commit 0fc468a682
2 changed files with 16 additions and 0 deletions

View file

@ -86,6 +86,8 @@ BR.Export = L.Class.extend({
return BR.Kml.format(track);
case 'geojson':
return JSON.stringify(track, null, 2);
case 'csv':
return BR.Csv.format(track);
default:
break;
}

14
js/format/Csv.js Normal file
View file

@ -0,0 +1,14 @@
BR.Csv = {
format: function (geoJson) {
const separator = '\t';
const newline = '\n';
const messages = geoJson.features[0].properties.messages;
let csv = '';
for (const entries of messages) {
csv += entries.join(separator) + newline;
}
return csv;
},
};