diff options
Diffstat (limited to '')
-rw-r--r-- | src/nodejs/xmlGenerator.js | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/src/nodejs/xmlGenerator.js b/src/nodejs/xmlGenerator.js index 17143a8..08ea833 100644 --- a/src/nodejs/xmlGenerator.js +++ b/src/nodejs/xmlGenerator.js @@ -8,6 +8,27 @@ var log4js = require('log4js')(); //note the need to call the function var log = log4js.getLogger('xmlGenerator'); log.setLevel(config.logLevel); +function toISO8601(date) { + //2007-03-31T00:09:22+01:00 + var pad_two = function(n) { + return (n < 10 ? '0' : '') + n; + }; + + return [ + date.getUTCFullYear(), + '-', + pad_two(date.getUTCMonth() + 1), + '-', + pad_two(date.getUTCDate()), + 'T', + pad_two(date.getUTCHours()), + ':', + pad_two(date.getUTCMinutes()), + ':', + pad_two(date.getUTCSeconds()), + '+01:00' //FIX ME + ].join(''); +} exports.createNode = function (row) { log.debug(row); @@ -20,52 +41,34 @@ exports.createNode = function (row) { .att('lon', row.lon); if(row.tags != '{}') { var temp = row.tags.replace("{","").replace("}","").split(","); - for(var x=0;x<temp.length;x=x+2) + for(var x=0;x<temp.length;x=x+2){ node.ele('tag') .att('k',escape(temp[x])) .att('v',escape(temp[x+1])); + } } return builder.toString({ pretty: true }); }; exports.createWay = function (row) { + var temp; var way = builder.begin('way') .att('id', row.id) .att('timestamp', toISO8601(row.tstamp)) .att('version', row.version) .att('changeset', row.changeset_id); if(row.tags != '{}') { - var temp = row.tags.replace("{","").replace("}","").split(","); - for(var x=0;x<temp.length;x=x+2) + temp = row.tags.replace("{","").replace("}","").split(","); + for(var x=0;x<temp.length;x=x+2){ way.ele('tag') .att('k',escape(temp[x])) .att('v',escape(temp[x+1])); + } } - var temp = row.nodes.replace("{","").replace("}","").split(","); + temp = row.nodes.replace("{","").replace("}","").split(","); for(var i=0;i<temp.length;i++) { way.ele('nd').att('ref',temp[i]); } return builder.toString({pretty:'true'}); }; -function toISO8601(date) { - //2007-03-31T00:09:22+01:00 - var pad_two = function(n) { - return (n < 10 ? '0' : '') + n; - }; - - return [ - date.getUTCFullYear(), - '-', - pad_two(date.getUTCMonth() + 1), - '-', - pad_two(date.getUTCDate()), - 'T', - pad_two(date.getUTCHours()), - ':', - pad_two(date.getUTCMinutes()), - ':', - pad_two(date.getUTCSeconds()), - '+01:00' //FIX ME - ].join(''); -} |