Implemented integration of turbo-cartocss for named maps
This commit is contained in:
@@ -255,22 +255,6 @@ MapController.prototype.instantiateTemplate = function(req, res, prepareParamsFn
|
||||
}
|
||||
);
|
||||
},
|
||||
function parseTurboCartoCss(err, requestMapConfig, datasource) {
|
||||
assert.ifError(err);
|
||||
|
||||
var next = this;
|
||||
self.turboCartoCssAdapter.getLayers(req.context.user, requestMapConfig.layers, function (err, layers) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (layers) {
|
||||
requestMapConfig.layers = layers;
|
||||
}
|
||||
|
||||
return next(null, requestMapConfig, datasource);
|
||||
});
|
||||
},
|
||||
function createLayergroup(err, mapConfig_, rendererParams) {
|
||||
assert.ifError(err);
|
||||
mapConfig = mapConfig_;
|
||||
|
||||
@@ -15,11 +15,12 @@ var userMiddleware = require('../middleware/user');
|
||||
* @param {TemplateMaps} templateMaps
|
||||
* @constructor
|
||||
*/
|
||||
function NamedMapsAdminController(authApi, pgConnection, templateMaps) {
|
||||
function NamedMapsAdminController(authApi, pgConnection, templateMaps, turboCartoCssAdapter) {
|
||||
BaseController.call(this, authApi, pgConnection);
|
||||
|
||||
this.authApi = authApi;
|
||||
this.templateMaps = templateMaps;
|
||||
this.turboCartoCssAdapter = turboCartoCssAdapter;
|
||||
}
|
||||
|
||||
util.inherits(NamedMapsAdminController, BaseController);
|
||||
@@ -44,11 +45,30 @@ NamedMapsAdminController.prototype.create = function(req, res) {
|
||||
function checkPerms(){
|
||||
self.authApi.authorizedByAPIKey(cdbuser, req, this);
|
||||
},
|
||||
function addTemplate(err, authenticated) {
|
||||
function parseTurboCartoCss(err, authenticated) {
|
||||
assert.ifError(err);
|
||||
|
||||
ifUnauthenticated(authenticated, 'Only authenticated users can get template maps');
|
||||
ifInvalidContentType(req, 'template POST data must be of type application/json');
|
||||
|
||||
var next = this;
|
||||
var cfg = req.body;
|
||||
|
||||
self.turboCartoCssAdapter.getLayers(req.context.user, cfg.layergroup.layers, function (err, layers) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (layers) {
|
||||
cfg.layergroup.layers = layers;
|
||||
}
|
||||
|
||||
return next(null, cfg);
|
||||
});
|
||||
},
|
||||
function addTemplate(err, cfg) {
|
||||
assert.ifError(err);
|
||||
|
||||
self.templateMaps.addTemplate(cdbuser, cfg, this);
|
||||
},
|
||||
function prepareResponse(err, tpl_id){
|
||||
|
||||
@@ -196,7 +196,7 @@ module.exports = function(serverOptions) {
|
||||
metadataBackend
|
||||
).register(app);
|
||||
|
||||
new controller.NamedMapsAdmin(authApi, pgConnection, templateMaps).register(app);
|
||||
new controller.NamedMapsAdmin(authApi, pgConnection, templateMaps, turboCartocssAdapter).register(app);
|
||||
|
||||
new controller.ServerInfo().register(app);
|
||||
|
||||
|
||||
@@ -32,7 +32,9 @@ TurboCartocssAdapter.prototype.getLayers = function (username, layers, callback)
|
||||
|
||||
TurboCartocssAdapter.prototype._parseCartoCss = function (username, layer, callback) {
|
||||
if (isNotLayerToParseCartocss(layer)) {
|
||||
return callback(null, layer);
|
||||
return process.nextTick(function () {
|
||||
callback(null, layer);
|
||||
});
|
||||
}
|
||||
|
||||
this.turboCartocssParser.process(username, layer.options.cartocss, layer.options.sql, function (err, cartocss) {
|
||||
@@ -46,7 +48,7 @@ TurboCartocssAdapter.prototype._parseCartoCss = function (username, layer, callb
|
||||
};
|
||||
|
||||
function isNotLayerToParseCartocss(layer) {
|
||||
if ( layer.type !== 'mapnik' && layer.type !== 'cartodb' && layer.type !== 'torque' ) {
|
||||
if (!layer || !layer.options || !layer.options.cartocss || !layer.options.sql) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user