aboutsummaryrefslogtreecommitdiffstats
path: root/src/nodejs
diff options
context:
space:
mode:
authorslomo <steve.harrison@gmx.net>2011-01-21 15:57:36 +0100
committerslomo <steve.harrison@gmx.net>2011-01-21 15:57:36 +0100
commit3cdab5dcde696223cf240aedbe774951da1ad7bb (patch)
tree3a69397b64f7eb226171dd687be8067700c2afda /src/nodejs
parent509d0a07c6131c50454f91ef1f0d0085b551b95f (diff)
parentef31bee06ce4517e83de01f9f13f6c96a77a0b5f (diff)
downloadosm-xapi-3cdab5dcde696223cf240aedbe774951da1ad7bb.tar.gz
osm-xapi-3cdab5dcde696223cf240aedbe774951da1ad7bb.tar.xz
osm-xapi-3cdab5dcde696223cf240aedbe774951da1ad7bb.zip
Merge branch 'master' of github.com:slomo/osm-spline-xapi
Diffstat (limited to 'src/nodejs')
-rw-r--r--src/nodejs/no1.js55
1 files changed, 23 insertions, 32 deletions
diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js
index f55f736..94ca59e 100644
--- a/src/nodejs/no1.js
+++ b/src/nodejs/no1.js
@@ -68,23 +68,15 @@ 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) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(' key:' +key +' value:'+value+'\n');
}
function nodeBboxHandler(req, res, key, value, left, bottom, right, top) {
- pg.connect(connectionString, function(err,client) {
-
- if (err) {
- console.log(err);
- res.writeHead(404,{});
- res.end('\n');
- }
- else {
- //console.log(createNodeBboxQuery(key, value, left, bottom, right, top));
+ console.log("nodeBboxHandler");
+ db_connect(res, function() {
+ //console.log(createNodeBboxQuery(key, value, left, bottom, right, top));
var success = false;
var query = client.query(createNodeBboxQuery(key, value, left, bottom, right, top));
@@ -133,33 +125,36 @@ function nodeBboxHandler(req, res, key, value, left, bottom, right, top) {
.att('k',escape(temp[x]))
.att('v',escape(temp[x+1]));
}
- //for(var x=0; x< tags.length;x++)
- //console.log(tags[x]);
- /*node.ele('tag')
- .att('k',tags[x][0])
- .att('v',tags[x][1]);
- */
+
res.write(builder.toString({ pretty: true }));
- //res.write(builder.toString());
- });
- }
+ });
});
}
function wayWorldHandler(req, res, key, value) {
-
res.writeHead(200, {'Content-Type': 'text/plain'});
-
}
-function wayBboxHandler(req, res, key, value, left, bottom, right, top) {
- pg.connect(connectionString, function(err,client) {
+
+function connectionError(err, res) {
+ console.log(err);
+ console.log("foobar");
+}
+
+function db_connect(res, callback) {
+ pg.connect(connectionString, function(err, client) {
if(err) {
- console.log(err);
+ console.log(err['message']);
res.writeHead(404,{});
res.end();
+ } else {
+ callback();
}
- else {
- var count = 0;
+ });
+}
+
+function wayBboxHandler(req, res, key, value, left, bottom, right, top) {
+ db_connect(res, function() {
+ var count = 0;
var success = false;
//console.log(createWayBboxQuery(key, value, left, bottom, right, top));
var query = client.query(createWayBboxQuery(key, value, left, bottom, right, top));
@@ -245,11 +240,7 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) {
res.write(builder.toString({pretty:'true'}));
});
-
- }
-
- });
-
+ });
}
function relationWorldHandler(req, res, key, value) {