2018-10-23 23:45:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-03-29 01:11:19 +08:00
|
|
|
module.exports = function getNamedMapProvider ({ namedMapProviderCache, label, forcedFormat = null }) {
|
|
|
|
return function getNamedMapProviderMiddleware (req, res, next) {
|
2019-11-14 18:36:47 +08:00
|
|
|
const { user, token, cache_buster: cacheBuster, api_key: apiKey } = res.locals;
|
2018-03-29 01:11:19 +08:00
|
|
|
const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
|
2019-11-14 18:36:47 +08:00
|
|
|
const { template_id: templateId, layer: layerFromParams, z, x, y, format } = req.params;
|
2018-03-29 01:11:19 +08:00
|
|
|
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,
|
2019-11-14 18:36:47 +08:00
|
|
|
template_id: templateId,
|
2019-10-22 01:07:24 +08:00
|
|
|
layer: (layerFromQuery || layerFromParams),
|
|
|
|
z,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
format
|
2018-03-29 01:11:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (forcedFormat) {
|
|
|
|
params.format = forcedFormat;
|
|
|
|
params.layer = params.layer || 'all';
|
|
|
|
}
|
|
|
|
|
2019-11-14 18:36:47 +08:00
|
|
|
const { config, auth_token: authToken } = req.query;
|
2018-03-29 01:11:19 +08:00
|
|
|
|
2019-11-14 18:36:47 +08:00
|
|
|
namedMapProviderCache.get(user, templateId, config, authToken, params, (err, namedMapProvider) => {
|
2018-03-29 01:11:19 +08:00
|
|
|
if (err) {
|
|
|
|
err.label = label;
|
|
|
|
return next(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.mapConfigProvider = namedMapProvider;
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|