Going green: be able to request defaul named tiles in vector format
This commit is contained in:
@@ -41,14 +41,18 @@ function NamedMapsController(prepareContext, namedMapProviderCache, tileBackend,
|
||||
module.exports = NamedMapsController;
|
||||
|
||||
NamedMapsController.prototype.register = function(app) {
|
||||
const tileOptions = {
|
||||
label: 'NAMED_MAP_TILE'
|
||||
};
|
||||
|
||||
app.get(
|
||||
app.base_url_templated + '/:template_id/:layer/:z/:x/:y.(:format)',
|
||||
cors(),
|
||||
userMiddleware,
|
||||
this.prepareContext,
|
||||
this.getNamedMapProvider('NAMED_MAP_TILE'),
|
||||
this.getNamedMapProvider(tileOptions),
|
||||
this.getAffectedTables(),
|
||||
this.getTile('NAMED_MAP_TILE'),
|
||||
this.getTile(tileOptions),
|
||||
this.setSurrogateKey(),
|
||||
this.setCacheChannelHeader(),
|
||||
this.setLastModifiedHeader(),
|
||||
@@ -58,18 +62,23 @@ NamedMapsController.prototype.register = function(app) {
|
||||
vectorError()
|
||||
);
|
||||
|
||||
const staticOptions = {
|
||||
forcedFormat: 'png',
|
||||
label: 'STATIC_VIZ_MAP'
|
||||
};
|
||||
|
||||
app.get(
|
||||
app.base_url_mapconfig + '/static/named/:template_id/:width/:height.:format',
|
||||
cors(),
|
||||
userMiddleware,
|
||||
allowQueryParams(['layer', 'zoom', 'lon', 'lat', 'bbox']),
|
||||
this.prepareContext,
|
||||
this.getNamedMapProvider('STATIC_VIZ_MAP'),
|
||||
this.getNamedMapProvider(staticOptions),
|
||||
this.getAffectedTables(),
|
||||
this.getTemplate('STATIC_VIZ_MAP'),
|
||||
this.prepareLayerFilterFromPreviewLayers('STATIC_VIZ_MAP'),
|
||||
this.getTemplate(staticOptions),
|
||||
this.prepareLayerFilterFromPreviewLayers(staticOptions),
|
||||
this.getStaticImageOptions(),
|
||||
this.getImage('STATIC_VIZ_MAP'),
|
||||
this.getImage(staticOptions),
|
||||
this.incrementMapViews(),
|
||||
this.setSurrogateKey(),
|
||||
this.setCacheChannelHeader(),
|
||||
@@ -80,16 +89,16 @@ NamedMapsController.prototype.register = function(app) {
|
||||
);
|
||||
};
|
||||
|
||||
NamedMapsController.prototype.getNamedMapProvider = function (label) {
|
||||
NamedMapsController.prototype.getNamedMapProvider = function ({ label, forcedFormat }) {
|
||||
return function getNamedMapProviderMiddleware (req, res, next) {
|
||||
const { user } = res.locals;
|
||||
const { config, auth_token } = req.query;
|
||||
const { template_id } = req.params;
|
||||
|
||||
// We force always the tile to be generated using PNG because
|
||||
// is the only format we support by now
|
||||
res.locals.format = 'png';
|
||||
res.locals.layer = res.locals.layer || 'all';
|
||||
if (forcedFormat) {
|
||||
res.locals.format = forcedFormat;
|
||||
res.locals.layer = res.locals.layer || 'all';
|
||||
}
|
||||
|
||||
const params = getRequestParams(res.locals);
|
||||
|
||||
@@ -124,7 +133,7 @@ NamedMapsController.prototype.getAffectedTables = function () {
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
NamedMapsController.prototype.getTemplate = function (label) {
|
||||
NamedMapsController.prototype.getTemplate = function ({ label }) {
|
||||
return function getTemplateMiddleware (req, res, next) {
|
||||
const { namedMapProvider } = res.locals;
|
||||
|
||||
@@ -141,7 +150,7 @@ NamedMapsController.prototype.getTemplate = function (label) {
|
||||
};
|
||||
};
|
||||
|
||||
NamedMapsController.prototype.prepareLayerFilterFromPreviewLayers = function (label) {
|
||||
NamedMapsController.prototype.prepareLayerFilterFromPreviewLayers = function ({ label }) {
|
||||
return function prepareLayerFilterFromPreviewLayersMiddleware (req, res, next) {
|
||||
const { user, template } = res.locals;
|
||||
const { template_id } = req.params;
|
||||
@@ -183,7 +192,7 @@ NamedMapsController.prototype.prepareLayerFilterFromPreviewLayers = function (la
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
NamedMapsController.prototype.getTile = function (label) {
|
||||
NamedMapsController.prototype.getTile = function ({ label }) {
|
||||
return function getTileMiddleware (req, res, next) {
|
||||
const { namedMapProvider } = res.locals;
|
||||
|
||||
@@ -306,7 +315,7 @@ function getImageOptionsFromBoundingBox (bbox = '') {
|
||||
}
|
||||
}
|
||||
|
||||
NamedMapsController.prototype.getImage = function (label) {
|
||||
NamedMapsController.prototype.getImage = function ({ label }) {
|
||||
return function getImageMiddleware (req, res, next) {
|
||||
const { imageOpts, namedMapProvider } = res.locals;
|
||||
const { zoom, center, bounds } = imageOpts;
|
||||
|
||||
Reference in New Issue
Block a user