aboutsummaryrefslogtreecommitdiffstats
path: root/src/nodejs
diff options
context:
space:
mode:
authorPhilipp Borgers <borgers@mi.fu-berlin.de>2011-01-15 18:38:02 +0100
committerPhilipp Borgers <borgers@mi.fu-berlin.de>2011-01-15 18:38:02 +0100
commit647032e7aa10ce75483bfc80b0857fcafe7b7da8 (patch)
treeabc493ffa8f04e835e3241a997de843f4cdccaec /src/nodejs
parent0857764cec6cc564a6ba24bc81a358429c447fcb (diff)
downloadosm-xapi-647032e7aa10ce75483bfc80b0857fcafe7b7da8.tar.gz
osm-xapi-647032e7aa10ce75483bfc80b0857fcafe7b7da8.tar.xz
osm-xapi-647032e7aa10ce75483bfc80b0857fcafe7b7da8.zip
broken code for way requests, subquery problem...
Diffstat (limited to 'src/nodejs')
-rw-r--r--src/nodejs/no1.js47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js
index ab903fe..a5a33be 100644
--- a/src/nodejs/no1.js
+++ b/src/nodejs/no1.js
@@ -22,6 +22,10 @@ function createNodeBboxQuery(key, value, left, bottom, right, top) {
left + "," + bottom + "),4326), st_setsrid(st_makepoint(" + right + "," + top + "),4326)),4326));";
}
+function createNodesForWayQuery(nodes) {
+ return "SELECT id, tstamp, version, changeset_id, hstore_to_array(tags) as tags, X(geom) as lat, Y(geom) as lon FROM nodes WHERE id = ANY('" + nodes + "');";
+}
+
function nodeWorldHandler(req, res, key, value) {
@@ -109,7 +113,7 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) {
}
else {
var success = false;
- console.log(createWayBboxQuery(key, value, left, bottom, right, top));
+ //console.log(createWayBboxQuery(key, value, left, bottom, right, top));
var query = client.query(createWayBboxQuery(key, value, left, bottom, right, top));
query.on('error', function(err) {
@@ -121,7 +125,7 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) {
query.on('end', function() {
if(success) {
res.write("</xml>");
- res.end();
+ res.end(); //problem!!!
}
else {
res.end();
@@ -135,15 +139,48 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("<xml>");
}
- console.log(row);
+ //console.log(row);
+ if(row.nodes != '{}') {
+
+ var subquery = client.query(createNodesForWayQuery(row.nodes));
+ subquery.on('error',function(err) {});
+ subquery.on('row', function(row) {
+ console.log(row);
+ var node = builder.begin('node')
+ .att('id', row.id)
+ .att('timetamp', row.tstamp)
+ .att('version', row.version)
+ .att('changeset', row.changeset_id)
+ .att('lat', row.lat)
+ .att('lon', row.lon);
+ var temp = row.tags.replace("{","").replace("}","").split(",");
+ for(var x=0;x<temp.length;x=x+2)
+ node.ele('tag')
+ .att('k',escape(temp[x]))
+ .att('v',escape(temp[x+1]));
+
+ res.write(builder.toString({pretty:'true'}));
+ });
+ //console.log(createNodesForWayQuery(row.nodes));
+ }
- builder.begin('way')
+ var way = builder.begin('way')
.att('id', row.id)
.att('timetamp', row.tstamp)
.att('version', row.version)
.att('changeset', row.changeset_id);
+ 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());
+ res.write(builder.toString({pretty:'true'}));
});
}