add map metadata enpoind and move all responsiblity for infowindow and metadata to here
This commit is contained in:
parent
2e1b36a1a4
commit
de8508ed57
10
README.md
10
README.md
@ -3,7 +3,7 @@ Windshaft-CartoDB
|
|||||||
|
|
||||||
This is the CartoDB map tiler.
|
This is the CartoDB map tiler.
|
||||||
|
|
||||||
Look at lob/cartodb/server_options to see how we configure windshaft
|
Look at lib/cartodb/server_options to see how we configure windshaft
|
||||||
|
|
||||||
|
|
||||||
Install
|
Install
|
||||||
@ -14,10 +14,6 @@ npm install
|
|||||||
node app.js [development | production]
|
node app.js [development | production]
|
||||||
```
|
```
|
||||||
|
|
||||||
Dependencies
|
|
||||||
------------
|
|
||||||
Mapnik r
|
|
||||||
|
|
||||||
|
|
||||||
Core features
|
Core features
|
||||||
-------------
|
-------------
|
||||||
@ -25,7 +21,7 @@ Core features
|
|||||||
* configures windshaft to publish cartodb_id as the interactivity layer
|
* configures windshaft to publish cartodb_id as the interactivity layer
|
||||||
* gets the default geometry type from the cartodb redis store
|
* gets the default geometry type from the cartodb redis store
|
||||||
* provides an ultra basic infowindow endpoint for windshaft
|
* provides an ultra basic infowindow endpoint for windshaft
|
||||||
|
* provides an ultra basic map_metadata endpoint for windshaft
|
||||||
|
|
||||||
URLs
|
URLs
|
||||||
----
|
----
|
||||||
@ -60,4 +56,4 @@ Args:
|
|||||||
* infowindow - returns contents of infowindow from CartoDB.
|
* infowindow - returns contents of infowindow from CartoDB.
|
||||||
|
|
||||||
|
|
||||||
All GET requests are wrappable with JSONp using callback argument, including the UTFGrid map tile call.
|
All GET requests are wrappable with JSONP using callback argument, including the UTFGrid map tile call.
|
64
app.js
64
app.js
@ -1,22 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
* Windshaft
|
* Windshaft-CartoDB
|
||||||
* ===============
|
* ===============
|
||||||
*
|
*
|
||||||
* ./app.js [environment]
|
* ./app.js [environment]
|
||||||
*
|
*
|
||||||
* environments: [development, production]
|
* environments: [development, production]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
var ENV = process.argv[2]
|
var ENV = process.argv[2]
|
||||||
if (ENV != 'development' && ENV != 'production'){
|
if (ENV != 'development' && ENV != 'production'){
|
||||||
console.error("\nnode app.js [environment]");
|
console.error("\nnode app.js [environment]");
|
||||||
console.error("environments: [development, production]\n");
|
console.error("environments: [development, production]\n");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = require('underscore');
|
var _ = require('underscore')
|
||||||
|
, Step = require('step')
|
||||||
|
, cartoData = require('./lib/cartodb/carto_data');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// set environment specific variables
|
// set environment specific variables
|
||||||
global.settings = require(__dirname + '/config/settings');
|
global.settings = require(__dirname + '/config/settings');
|
||||||
@ -28,6 +32,44 @@ var serverOptions = require('./lib/cartodb/server_options');
|
|||||||
|
|
||||||
// boot
|
// boot
|
||||||
var ws = new Windshaft.Server(serverOptions);
|
var ws = new Windshaft.Server(serverOptions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to allow access to the layer to be used in the maps infowindow popup.
|
||||||
|
*/
|
||||||
|
ws.get(serverOptions.base_url + '/infowindow', function(req, res){
|
||||||
|
Step(
|
||||||
|
function(){
|
||||||
|
serverOptions.getInfowindow(req, this);
|
||||||
|
},
|
||||||
|
function(err, data){
|
||||||
|
if (err){
|
||||||
|
res.send(err.message, 400);
|
||||||
|
} else {
|
||||||
|
res.send({infowindow: data}, 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to allow access to metadata to be used in embedded maps.
|
||||||
|
*/
|
||||||
|
ws.get(serverOptions.base_url + '/map_metadata', function(req, res){
|
||||||
|
Step(
|
||||||
|
function(){
|
||||||
|
serverOptions.getMapMetadata(req, this);
|
||||||
|
},
|
||||||
|
function(err, data){
|
||||||
|
if (err){
|
||||||
|
res.send(err.message, 400);
|
||||||
|
} else {
|
||||||
|
res.send({map_metadata: data}, 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
ws.listen(global.environment.windshaft_port);
|
ws.listen(global.environment.windshaft_port);
|
||||||
console.log("Windshaft tileserver started on port " + global.environment.windshaft_port);
|
console.log("Windshaft tileserver started on port " + global.environment.windshaft_port);
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ module.exports = function() {
|
|||||||
function(err, data) {
|
function(err, data) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
var redisKey = _.template(that.table_key, {database_name: data, table_name: req.params.table});
|
var redisKey = _.template(that.table_key, {database_name: data, table_name: req.params.table});
|
||||||
|
|
||||||
that.retrieve(that.table_metadata_db, redisKey, 'infowindow', this);
|
that.retrieve(that.table_metadata_db, redisKey, 'infowindow', this);
|
||||||
},
|
},
|
||||||
function(err, data){
|
function(err, data){
|
||||||
@ -155,6 +155,26 @@ module.exports = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
me.getMapMetadata = function(req, callback){
|
||||||
|
var that = this;
|
||||||
|
|
||||||
|
Step(
|
||||||
|
function(){
|
||||||
|
that.getDatabase(req, this);
|
||||||
|
},
|
||||||
|
function(err, data) {
|
||||||
|
if (err) throw err;
|
||||||
|
var redisKey = _.template(that.table_key, {database_name: data, table_name: req.params.table});
|
||||||
|
|
||||||
|
that.retrieve(that.table_metadata_db, redisKey, 'map_metadata', this);
|
||||||
|
},
|
||||||
|
function(err, data){
|
||||||
|
if (err) throw err;
|
||||||
|
callback(err, data);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a HASH data access call to Redis
|
* Make a HASH data access call to Redis
|
||||||
|
@ -79,5 +79,24 @@ me.getInfowindow = function(req, callback){
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Little helper method to get map metadata and return to client
|
||||||
|
* @param req
|
||||||
|
* @param callback
|
||||||
|
*/
|
||||||
|
me.getMapMetadata = function(req, callback){
|
||||||
|
var that = this;
|
||||||
|
|
||||||
|
Step(
|
||||||
|
function(){
|
||||||
|
that.req2params(req, this);
|
||||||
|
},
|
||||||
|
function(err, data){
|
||||||
|
if (err) throw err;
|
||||||
|
cartoData.getMapMetadata(data, callback);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return me;
|
return me;
|
||||||
}();
|
}();
|
Loading…
Reference in New Issue
Block a user