aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/nodejs/no1.js38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js
index 94ca59e..edb7110 100644
--- a/src/nodejs/no1.js
+++ b/src/nodejs/no1.js
@@ -55,12 +55,12 @@ function toISO8601(date) {
].join('');
}
function createWayBboxQuery(key, value, left, bottom, right, top) {
- return "SELECT id,tstamp,version,changeset_id, nodes, user_id, hstore_to_array(tags) as tags FROM ways WHERE (tags @> hstore('" + key + "','" + value + "') AND linestring && st_setsrid(st_makebox2d(st_setsrid(st_makepoint(" +
+ return "SELECT id,tstamp,version,changeset_id, nodes, user_id, hstore_to_array(tags) as tags FROM ways WHERE (tags @> hstore('" + key + "','" + value + "') AND linestring && st_setsrid(st_makebox2d(st_setsrid(st_makepoint(" +
left + "," + bottom + "),4326), st_setsrid(st_makepoint(" + right + "," + top + "),4326)),4326));";
}
function createNodeBboxQuery(key, value, left, bottom, right, top) {
- return "SELECT id, user_id,tstamp,version,changeset_id, hstore_to_array(tags) as tags, X(geom) as lat, Y(geom) as lon FROM nodes WHERE (tags @> hstore('" + key + "','" + value + "') AND geom && st_setsrid(st_makebox2d(st_setsrid(st_makepoint(" +
+ return "SELECT id, user_id,tstamp,version,changeset_id, hstore_to_array(tags) as tags, X(geom) as lat, Y(geom) as lon FROM nodes WHERE (tags @> hstore('" + key + "','" + value + "') AND geom && st_setsrid(st_makebox2d(st_setsrid(st_makepoint(" +
left + "," + bottom + "),4326), st_setsrid(st_makepoint(" + right + "," + top + "),4326)),4326));";
}
@@ -79,14 +79,14 @@ function nodeBboxHandler(req, res, key, value, left, bottom, right, top) {
//console.log(createNodeBboxQuery(key, value, left, bottom, right, top));
var success = false;
var query = client.query(createNodeBboxQuery(key, value, left, bottom, right, top));
-
+
query.on('error', function(err) {
-
+
console.log(err);
res.writeHead(404,{});
res.end('\n');
});
-
+
query.on('end', function() {
//console.log("end event\n");
if(success) {
@@ -100,17 +100,17 @@ function nodeBboxHandler(req, res, key, value, left, bottom, right, top) {
//perhaps write 404? is error also raised?
}
});
-
+
query.on('row', function(row) {
-
+
if(!success) {
success = true;
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("<xml>");
}
-
+
console.log(row);
-
+
var node = builder.begin('node')
.att('id', row.id)
.att('timetamp', toISO8601(row.tstamp))
@@ -124,7 +124,7 @@ function nodeBboxHandler(req, res, key, value, left, bottom, right, top) {
node.ele('tag')
.att('k',escape(temp[x]))
.att('v',escape(temp[x+1]));
- }
+ }
res.write(builder.toString({ pretty: true }));
});
@@ -158,13 +158,13 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) {
var success = false;
//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) {
console.log(err);
res.writeHead(404,{});
res.end();
});
-
+
query.on('end', function() {
if(success) {
if(count == 0) {
@@ -180,7 +180,7 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) {
//perhaps write 404?
}
});
-
+
query.on('row', function(row) {
if(!success) {
success = true;
@@ -216,10 +216,10 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) {
}
res.write(builder.toString({pretty:'true'}));
});
-
+
//console.log(createNodesForWayQuery(row.nodes));
}
-
+
var way = builder.begin('way')
.att('id', row.id)
.att('timetamp', toISO8601(row.tstamp))
@@ -232,19 +232,19 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) {
.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'}));
});
- });
+ });
}
function relationWorldHandler(req, res, key, value) {
-
+
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(' key:' +key +' value:'+value+'!\n');
}