var database = require("./database"); var utils = require("./utils"); var async = require("async"); var _e = utils.escapeXml; function _dataToText(fields, data) { var text = [ ]; for(var i=0; i\n'; next(); }, function(err) { next(err, views); }); }, typesObj : function(next) { var types = { }; utils.asyncStreamEach(database.getTypes(padId), function(type, next) { types[type.id] = type; next(); }, function(err) { next(err, types); }); }, types : [ "typesObj", function(res, next) { var types = ''; for(var i in res.typesObj) { var type = res.typesObj[i]; types += '\n'; } next(null, types); } ], markers : [ "typesObj", function(res, next) { var markers = ''; utils.asyncStreamEach(database.getPadMarkers(padId), function(marker, next) { markers += '\n' + '\t' + _e(marker.name) + '\n' + '\t' + _e(_dataToText(res.typesObj[marker.typeId].fields, marker.data)) + '\n' + '\t\n' + '\t\t' + _e(marker.colour) + '\n' + '\t\n' + '\n'; next(); }, function(err) { next(err, markers); }); } ], lines : [ "typesObj", function(res, next) { var lines = ''; utils.asyncStreamEach(database.getPadLinesWithPoints(padId), function(line, next) { var t = (useTracks || line.mode == "track"); lines += '<' + (t ? 'trk' : 'rte') + '>\n' + '\t' + _e(line.name) + '\n' + '\t' + _e(_dataToText(res.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 += '\n'; next(); }, function(err) { next(err, lines); }); } ] }, function(err, res) { if(err) return callback(err); var gpx = '\n' + '\n' + '\t\n' + '\t\t' + _e(res.padData.name) + '\n' + '\t\t\n' + '\t\n' + '\t\n' + res.views.replace(/^(.)/gm, '\t\t$1') + res.types.replace(/^(.)/gm, '\t\t$1') + '\t\n' + res.markers.replace(/^(.)/gm, '\t$1') + res.lines.replace(/^(.)/gm, '\t$1') + ''; console.log(gpx); callback(null, gpx); }); } module.exports = { exportGpx : exportGpx };