aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Engel <mark.c.engel@gmail.com>2011-01-21 17:20:43 +0100
committerMark Engel <mark.c.engel@gmail.com>2011-01-21 17:20:43 +0100
commit9636bac02a2cf59fa573314a5f15de1d835260a2 (patch)
tree3adf08eb309896f6392fca6dfa6079d9e914da86
parentbe4bf1e3bc92921c502508072cd75196238a3fca (diff)
downloadosm-xapi-9636bac02a2cf59fa573314a5f15de1d835260a2.tar.gz
osm-xapi-9636bac02a2cf59fa573314a5f15de1d835260a2.tar.xz
osm-xapi-9636bac02a2cf59fa573314a5f15de1d835260a2.zip
refactored creation of xml way to own function
-rw-r--r--src/nodejs/no1.js49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js
index c31bc5f..047b9a2 100644
--- a/src/nodejs/no1.js
+++ b/src/nodejs/no1.js
@@ -99,12 +99,12 @@ function nodeBboxHandler(req, res, key, value, left, bottom, right, top) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("<xml>");
}
- res.write(createXmlFromRow(row));
+ res.write(createXmlNode(row));
});
});
}
-function createXmlFromRow(row) {
+function createXmlNode(row) {
console.log(row);
var node = builder.begin('node')
.att('id', row.id)
@@ -123,6 +123,28 @@ function createXmlFromRow(row) {
return builder.toString({ pretty: true });
}
+function createXmlWay(row) {
+ 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)
+ way.ele('tag')
+ .att('k',escape(temp[x]))
+ .att('v',escape(temp[x+1]));
+ }
+
+ var temp = row.nodes.replace("{","").replace("}","").split(",");
+ for(var x=0;x<temp.length;x++) {
+ way.ele('nd')
+ .att('ref',temp[x]);
+ }
+ return builder.toString({pretty:'true'});
+}
+
function wayWorldHandler(req, res, key, value) {
res.writeHead(200, {'Content-Type': 'text/plain'});
}
@@ -192,31 +214,12 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) {
res.end();
});
subquery.on('row', function(row) {
- res.write(createXmlFromRow(row));
+ res.write(createXmlNode(row));
});
//console.log(createNodesForWayQuery(row.nodes));
}
-
- var way = builder.begin('way')
- .att('id', row.id)
- .att('timetamp', 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)
- way.ele('tag')
- .att('k',escape(temp[x]))
- .att('v',escape(temp[x+1]));
- }
-
- var temp = row.nodes.replace("{","").replace("}","").split(",");
- for(var x=0;x<temp.length;x++)
- way.ele('nd')
- .att('ref',temp[x]);
-
- res.write(builder.toString({pretty:'true'}));
+ res.write(createXmlWay(row));
});
});
}