Windshaft-cartodb/lib/api/middlewares/map-store-map-config-provider.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

'use strict';
const MapStoreMapConfigProvider = require('../../models/mapconfig/provider/map-store-provider');
module.exports = function createMapStoreMapConfigProvider (
mapStore,
userLimitsBackend,
pgConnection,
affectedTablesCache,
forcedFormat = null
) {
return function createMapStoreMapConfigProviderMiddleware (req, res, next) {
2019-11-14 18:36:47 +08:00
const { user, token, cache_buster: cacheBuster, api_key: apiKey } = res.locals;
const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
2019-11-14 18:36:47 +08:00
const { layer: layerFromParams, z, x, y, scale_factor: scaleFactor, format } = req.params;
const { layer: layerFromQuery } = req.query;
const params = {
2019-10-22 01:07:24 +08:00
user,
token,
2019-11-14 18:36:47 +08:00
cache_buster: cacheBuster,
api_key: apiKey,
2019-10-22 01:07:24 +08:00
dbuser,
dbname,
dbpassword,
dbhost,
dbport,
layer: (layerFromQuery || layerFromParams),
z,
x,
y,
2019-11-14 18:36:47 +08:00
scale_factor: scaleFactor,
2019-10-22 01:07:24 +08:00
format
};
if (forcedFormat) {
params.format = forcedFormat;
params.layer = params.layer || 'all';
}
res.locals.mapConfigProvider = new MapStoreMapConfigProvider(
mapStore,
user,
userLimitsBackend,
pgConnection,
affectedTablesCache,
params
);
next();
};
};