modifies controllers to use new mapbackend signatures
This commit is contained in:
parent
5a003a7cbe
commit
034f3c77ce
@ -41,9 +41,18 @@ NamedMapsController.prototype.tile = function(req, res) {
|
|||||||
var template;
|
var template;
|
||||||
var layergroupConfig;
|
var layergroupConfig;
|
||||||
var layergroupId;
|
var layergroupId;
|
||||||
var fakeReq;
|
var params;
|
||||||
var cacheChannel;
|
var cacheChannel;
|
||||||
|
|
||||||
|
var layergroupDecorator = {
|
||||||
|
beforeLayergroupCreate: function(requestMapConfig, callback) {
|
||||||
|
self.serverOptions.beforeLayergroupCreate(req, requestMapConfig, callback);
|
||||||
|
},
|
||||||
|
afterLayergroupCreate: function(layergroup, response, callback) {
|
||||||
|
self.serverOptions.afterLayergroupCreate(req, layergroup, response, callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
step(
|
step(
|
||||||
function reqParams() {
|
function reqParams() {
|
||||||
self.app.req2params(req, this);
|
self.app.req2params(req, this);
|
||||||
@ -106,22 +115,14 @@ NamedMapsController.prototype.tile = function(req, res) {
|
|||||||
function prepareLayergroup(err, layergroup) {
|
function prepareLayergroup(err, layergroup) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
layergroupConfig = layergroup;
|
layergroupConfig = layergroup;
|
||||||
fakeReq = {
|
params = _.extend({}, req.params, {
|
||||||
query: {},
|
user: req.params.user
|
||||||
params: _.extend({}, req.params, {
|
});
|
||||||
user: req.params.user
|
self.serverOptions.setDBParams(cdbUser, params, this);
|
||||||
}),
|
|
||||||
headers: _.clone(req.headers),
|
|
||||||
context: _.clone(req.context),
|
|
||||||
method: req.method,
|
|
||||||
res: res,
|
|
||||||
profiler: req.profiler
|
|
||||||
};
|
|
||||||
self.serverOptions.setDBParams(cdbUser, fakeReq.params, this);
|
|
||||||
},
|
},
|
||||||
function setApiKey(err){
|
function setApiKey(err){
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
self.mapBackend.createLayergroup(layergroupConfig, fakeReq, this);
|
self.mapBackend.createLayergroup(layergroupConfig, params, layergroupDecorator, this);
|
||||||
},
|
},
|
||||||
function prepareResponse(err, layergroup) {
|
function prepareResponse(err, layergroup) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
@ -139,9 +140,12 @@ NamedMapsController.prototype.tile = function(req, res) {
|
|||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
req.params.token = layergroupId;
|
req.params.token = layergroupId;
|
||||||
self.mapBackend.getTileOrGrid(req, res, this);
|
self.mapBackend.getTileOrGrid(req.params, this);
|
||||||
},
|
},
|
||||||
function handleImage(err, req, res, tile, headers) {
|
function handleImage(err, tile, headers, stats) {
|
||||||
|
if (req.profiler) {
|
||||||
|
req.profiler.add(stats);
|
||||||
|
}
|
||||||
if (err) {
|
if (err) {
|
||||||
if (!err.error) {
|
if (!err.error) {
|
||||||
err.error = err.message;
|
err.error = err.message;
|
||||||
@ -344,7 +348,7 @@ NamedMapsController.prototype.jsonp = function(req, res) {
|
|||||||
req.profiler.start('windshaft-cartodb.instance_template_get');
|
req.profiler.start('windshaft-cartodb.instance_template_get');
|
||||||
}
|
}
|
||||||
step(
|
step(
|
||||||
function instantiateTemplate() {
|
function jsonp$instantiateTemplate() {
|
||||||
if ( req.query.callback === undefined || req.query.callback.length === 0) {
|
if ( req.query.callback === undefined || req.query.callback.length === 0) {
|
||||||
throw new Error('callback parameter should be present and be a function name');
|
throw new Error('callback parameter should be present and be a function name');
|
||||||
}
|
}
|
||||||
@ -370,10 +374,21 @@ NamedMapsController.prototype.instantiateTemplate = function(req, res, template_
|
|||||||
|
|
||||||
this.app.doCORS(res);
|
this.app.doCORS(res);
|
||||||
|
|
||||||
|
var layergroupDecorator = {
|
||||||
|
beforeLayergroupCreate: function(requestMapConfig, callback) {
|
||||||
|
self.serverOptions.beforeLayergroupCreate(req, requestMapConfig, callback);
|
||||||
|
},
|
||||||
|
afterLayergroupCreate: function(layergroup, response, callback) {
|
||||||
|
self.serverOptions.afterLayergroupCreate(req, layergroup, response, callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var template;
|
var template;
|
||||||
var layergroup;
|
var layergroup;
|
||||||
var fakereq; // used for call to createLayergroup
|
|
||||||
var cdbuser = cdbRequest.userByReq(req);
|
var cdbuser = cdbRequest.userByReq(req);
|
||||||
|
var params = {
|
||||||
|
user: req.params.user
|
||||||
|
};
|
||||||
// Format of template_id: [<template_owner>]@<template_id>
|
// Format of template_id: [<template_owner>]@<template_id>
|
||||||
var tpl_id = templateName(req.params.template_id);
|
var tpl_id = templateName(req.params.template_id);
|
||||||
var auth_token = req.query.auth_token;
|
var auth_token = req.query.auth_token;
|
||||||
@ -416,18 +431,7 @@ NamedMapsController.prototype.instantiateTemplate = function(req, res, template_
|
|||||||
if ( req.profiler ) req.profiler.done('TemplateMaps_instance');
|
if ( req.profiler ) req.profiler.done('TemplateMaps_instance');
|
||||||
if ( err ) throw err;
|
if ( err ) throw err;
|
||||||
layergroup = instance;
|
layergroup = instance;
|
||||||
fakereq = {
|
self.serverOptions.setDBParams(cdbuser, params, this);
|
||||||
query: {},
|
|
||||||
params: {
|
|
||||||
user: req.params.user
|
|
||||||
},
|
|
||||||
headers: _.clone(req.headers),
|
|
||||||
context: _.clone(req.context),
|
|
||||||
method: req.method,
|
|
||||||
res: res,
|
|
||||||
profiler: req.profiler
|
|
||||||
};
|
|
||||||
self.serverOptions.setDBParams(cdbuser, fakereq.params, this);
|
|
||||||
},
|
},
|
||||||
function setApiKey(err){
|
function setApiKey(err){
|
||||||
if ( req.profiler ) req.profiler.done('setDBParams');
|
if ( req.profiler ) req.profiler.done('setDBParams');
|
||||||
@ -437,8 +441,8 @@ NamedMapsController.prototype.instantiateTemplate = function(req, res, template_
|
|||||||
function createLayergroup(err, val) {
|
function createLayergroup(err, val) {
|
||||||
if ( req.profiler ) req.profiler.done('getUserMapKey');
|
if ( req.profiler ) req.profiler.done('getUserMapKey');
|
||||||
if ( err ) throw err;
|
if ( err ) throw err;
|
||||||
fakereq.params.api_key = val;
|
params.api_key = val;
|
||||||
self.mapBackend.createLayergroup(layergroup, fakereq, this);
|
self.mapBackend.createLayergroup(layergroup, params, layergroupDecorator, this);
|
||||||
},
|
},
|
||||||
function prepareResponse(err, layergroup) {
|
function prepareResponse(err, layergroup) {
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
|
@ -36,8 +36,18 @@ NamedStaticMapsController.prototype.named = function(req, res) {
|
|||||||
var layergroupConfig;
|
var layergroupConfig;
|
||||||
var layergroupId;
|
var layergroupId;
|
||||||
var fakeReq;
|
var fakeReq;
|
||||||
|
var params;
|
||||||
var cacheChannel;
|
var cacheChannel;
|
||||||
|
|
||||||
|
var layergroupDecorator = {
|
||||||
|
beforeLayergroupCreate: function(requestMapConfig, callback) {
|
||||||
|
self.serverOptions.beforeLayergroupCreate(req, requestMapConfig, callback);
|
||||||
|
},
|
||||||
|
afterLayergroupCreate: function(layergroup, response, callback) {
|
||||||
|
self.serverOptions.afterLayergroupCreate(req, layergroup, response, callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
step(
|
step(
|
||||||
function reqParams() {
|
function reqParams() {
|
||||||
self.app.req2params(req, this);
|
self.app.req2params(req, this);
|
||||||
@ -100,22 +110,14 @@ NamedStaticMapsController.prototype.named = function(req, res) {
|
|||||||
function prepareLayergroup(err, layergroup) {
|
function prepareLayergroup(err, layergroup) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
layergroupConfig = layergroup;
|
layergroupConfig = layergroup;
|
||||||
fakeReq = {
|
params = {
|
||||||
query: {},
|
user: req.params.user
|
||||||
params: {
|
|
||||||
user: req.params.user
|
|
||||||
},
|
|
||||||
headers: _.clone(req.headers),
|
|
||||||
context: _.clone(req.context),
|
|
||||||
method: req.method,
|
|
||||||
res: res,
|
|
||||||
profiler: req.profiler
|
|
||||||
};
|
};
|
||||||
self.serverOptions.setDBParams(cdbUser, fakeReq.params, this);
|
self.serverOptions.setDBParams(cdbUser, params, this);
|
||||||
},
|
},
|
||||||
function setApiKey(err){
|
function setApiKey(err){
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
self.mapBackend.createLayergroup(layergroupConfig, fakeReq, this);
|
self.mapBackend.createLayergroup(layergroupConfig, params, layergroupDecorator, this);
|
||||||
},
|
},
|
||||||
function prepareResponse(err, layergroup) {
|
function prepareResponse(err, layergroup) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
@ -165,21 +167,18 @@ NamedStaticMapsController.prototype.named = function(req, res) {
|
|||||||
function getImage(err, imageOpts) {
|
function getImage(err, imageOpts) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
var staticImageReq = {
|
var imageParams = _.extend({}, params, {
|
||||||
headers: _.clone(fakeReq.headers),
|
token: layergroupId,
|
||||||
params: _.extend(_.clone(fakeReq.params), {
|
format: req.params.format
|
||||||
token: layergroupId,
|
});
|
||||||
format: req.params.format
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
var width = +req.params.width;
|
var width = +req.params.width;
|
||||||
var height = +req.params.height;
|
var height = +req.params.height;
|
||||||
|
|
||||||
if (!_.isUndefined(imageOpts.zoom) && imageOpts.center) {
|
if (!_.isUndefined(imageOpts.zoom) && imageOpts.center) {
|
||||||
self.staticMapBackend.getImage(staticImageReq, width, height, imageOpts.zoom, imageOpts.center, this);
|
self.staticMapBackend.getImage(imageParams, width, height, imageOpts.zoom, imageOpts.center, this);
|
||||||
} else {
|
} else {
|
||||||
self.staticMapBackend.getImage(staticImageReq, width, height, imageOpts.bounds, this);
|
self.staticMapBackend.getImage(imageParams, width, height, imageOpts.bounds, this);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function handleImage(err, image, headers, stats) {
|
function handleImage(err, image, headers, stats) {
|
||||||
|
Loading…
Reference in New Issue
Block a user