var database = require("./database");
var utils = require("./utils");
var Promise = require("promise");
var _e = utils.escapeXml;
function _dataToText(fields, data) {
var text = [ ];
for(var i=0; i\n';
});
var typesObj = { };
var typesObjP = utils.streamEachPromise(database.getTypes(padId), function(type) {
typesObj[type.id] = type;
});
var typesMarkersLinesP = typesObjP.then(function() {
for(var i in typesObj) {
var type = typesObj[i];
types += '\n';
}
return Promise.all([
utils.streamEachPromise(database.getPadMarkers(padId), function(marker) {
markers += '\n' +
'\t' + _e(marker.name) + '\n' +
'\t' + _e(_dataToText(typesObj[marker.typeId].fields, marker.data)) + '\n' +
'\t\n' +
'\t\t' + _e(marker.colour) + '\n' +
'\t\n' +
'\n';
}),
utils.streamEachPromise(database.getPadLinesWithPoints(padId), function(line) {
var t = (useTracks || line.mode == "track");
lines += '<' + (t ? 'trk' : 'rte') + '>\n' +
'\t' + _e(line.name) + '\n' +
'\t' + _e(_dataToText(typesObj[line.typeId].fields, line.data)) + '\n' +
'\t\n' +
'\t\t' + _e(line.colour) + '\n' +
'\t\t' + _e(line.width) + '\n' +
'\t\t' + _e(line.mode) + '\n' +
(t && line.mode != 'track' ? '\t\t' + _e(JSON.stringify(line.routePoints)) + '\n' : '') +
'\t\n';
if(t) {
lines += '\t\n';
for(var i=0; i\n';
}
lines += '\t\n';
} else {
for(var i=0; i\n';
}
}
lines += '' + (t ? 'trk' : 'rte') + '>\n';
})
]);
});
return Promise.all([ padDataP, viewsP, typesMarkersLinesP ]).then(function(res) {
return '\n' +
'\n' +
'\t\n' +
'\t\t' + _e(res[0].name) + '\n' +
'\t\t\n' +
'\t\n' +
'\t\n' +
views.replace(/^(.)/gm, '\t\t$1') +
types.replace(/^(.)/gm, '\t\t$1') +
'\t\n' +
markers.replace(/^(.)/gm, '\t$1') +
lines.replace(/^(.)/gm, '\t$1') +
'';
});
}
module.exports = {
exportGpx : exportGpx
};