Windshaft-cartodb/lib/models/mapconfig/adapter/sql-wrap-mapconfig-adapter.js

27 lines
880 B
JavaScript
Raw Normal View History

'use strict';
2019-10-22 01:07:24 +08:00
function SqlWrapMapConfigAdapter () {
}
module.exports = SqlWrapMapConfigAdapter;
2019-10-22 01:07:24 +08:00
SqlWrapMapConfigAdapter.prototype.getMapConfig = function (user, requestMapConfig, params, context, callback) {
if (requestMapConfig && Array.isArray(requestMapConfig.layers)) {
2019-10-22 01:07:24 +08:00
requestMapConfig.layers = requestMapConfig.layers.map(function (layer) {
if (layer.options) {
var sqlQueryWrap = layer.options.sql_wrap;
if (sqlQueryWrap) {
var layerSql = layer.options.sql;
if (layerSql) {
layer.options.sql_raw = layerSql;
layer.options.sql = sqlQueryWrap.replace(/<%=\s*sql\s*%>/g, layerSql);
}
}
}
return layer;
});
}
return callback(null, requestMapConfig);
};