From 4b38b5fe6f89a19841b4f93d1a45cddecd284b1a Mon Sep 17 00:00:00 2001 From: slomo Date: Fri, 21 Jan 2011 17:26:10 +0100 Subject: replaced tabs with whitespaces --- src/nodejs/no1.js | 190 +++++++++++++++++++++++++++--------------------------- 1 file changed, 95 insertions(+), 95 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js index 112d736..d63a8bb 100644 --- a/src/nodejs/no1.js +++ b/src/nodejs/no1.js @@ -47,18 +47,18 @@ function toISO8601(date) { pad_two(date.getUTCMinutes()), ':', pad_two(date.getUTCSeconds()), - '+01:00' //FIX ME + '+01:00' //FIX ME ].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(" + - left + "," + bottom + "),4326), st_setsrid(st_makepoint(" + right + "," + top + "),4326)),4326));"; + 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(" + - left + "," + bottom + "),4326), st_setsrid(st_makepoint(" + right + "," + top + "),4326)),4326));"; + left + "," + bottom + "),4326), st_setsrid(st_makepoint(" + right + "," + top + "),4326)),4326));"; } function createNodesForWayQuery(nodes) { @@ -73,38 +73,38 @@ function nodeWorldHandler(req, res, key, value) { function nodeBboxHandler(req, res, key, value, left, bottom, right, top) { log.error("nodeBboxHandler"); db_connect(res, function(client) { - log.info(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) { - log.error(err); - res.writeHead(404,{}); - res.end('\n'); - }); - - query.on('end', function() { - //console.log("end event\n"); - if(success) { - res.write(""); - res.end(); - } - else { - //empty response - res.writeHead(404,{}); - res.end(); - //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(""); - } - res.write(createXmlNode(row)); - }); + log.info(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) { + log.error(err); + res.writeHead(404,{}); + res.end('\n'); + }); + + query.on('end', function() { + //console.log("end event\n"); + if(success) { + res.write(""); + res.end(); + } + else { + //empty response + res.writeHead(404,{}); + res.end(); + //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(""); + } + res.write(createXmlNode(row)); + }); }); } @@ -138,13 +138,13 @@ function createXmlWay(row) { for(var x=0;x"); - res.end(); - } - //res.write(""); - //res.end(); //problem!!! - } - else { - res.writeHead(404,{}); - res.end(); - //perhaps write 404? - } - }); - - query.on('row', function(row) { - if(!success) { - success = true; - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write(""); - } - //console.log(row); - if(row.nodes != '{}') { - count++; - var subquery = client.query(createNodesForWayQuery(row.nodes)); - subquery.on('error',function(err) {}); - subquery.on('end', function() { - count--; - if(count==0) - res.write(""); - res.end(); - }); - subquery.on('row', function(row) { - res.write(createXmlNode(row)); - }); - - //console.log(createNodesForWayQuery(row.nodes)); - } + 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) { + log.error(err); + res.writeHead(404,{}); + res.end(); + }); + + query.on('end', function() { + if(success) { + if(count == 0) { + res.write(""); + res.end(); + } + //res.write(""); + //res.end(); //problem!!! + } + else { + res.writeHead(404,{}); + res.end(); + //perhaps write 404? + } + }); + + query.on('row', function(row) { + if(!success) { + success = true; + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.write(""); + } + //console.log(row); + if(row.nodes != '{}') { + count++; + var subquery = client.query(createNodesForWayQuery(row.nodes)); + subquery.on('error',function(err) {}); + subquery.on('end', function() { + count--; + if(count==0) + res.write(""); + res.end(); + }); + subquery.on('row', function(row) { + res.write(createXmlNode(row)); + }); + + //console.log(createNodesForWayQuery(row.nodes)); + } res.write(createXmlWay(row)); - }); + }); }); } -- cgit v1.2.3