adding api key to tiles base urls
This commit is contained in:
parent
f0d190d157
commit
762dce7853
@ -1,6 +1,6 @@
|
|||||||
module.exports = function setMetadataToLayergroup (layergroupMetadata, includeQuery) {
|
module.exports = function setMetadataToLayergroup (layergroupMetadata, includeQuery) {
|
||||||
return function setMetadataToLayergroupMiddleware (req, res, next) {
|
return function setMetadataToLayergroupMiddleware (req, res, next) {
|
||||||
const { user, mapConfig, analysesResults = [], context } = res.locals;
|
const { user, mapConfig, analysesResults = [], context, api_key: userApiKey } = res.locals;
|
||||||
const layergroup = res.body;
|
const layergroup = res.body;
|
||||||
|
|
||||||
layergroupMetadata.addDataviewsAndWidgetsUrls(user, layergroup, mapConfig.obj());
|
layergroupMetadata.addDataviewsAndWidgetsUrls(user, layergroup, mapConfig.obj());
|
||||||
@ -8,7 +8,7 @@ module.exports = function setMetadataToLayergroup (layergroupMetadata, includeQu
|
|||||||
layergroupMetadata.addTurboCartoContextMetadata(layergroup, mapConfig.obj(), context);
|
layergroupMetadata.addTurboCartoContextMetadata(layergroup, mapConfig.obj(), context);
|
||||||
layergroupMetadata.addAggregationContextMetadata(layergroup, mapConfig.obj(), context);
|
layergroupMetadata.addAggregationContextMetadata(layergroup, mapConfig.obj(), context);
|
||||||
layergroupMetadata.addDateWrappingMetadata (layergroup, mapConfig.obj());
|
layergroupMetadata.addDateWrappingMetadata (layergroup, mapConfig.obj());
|
||||||
layergroupMetadata.addTileJsonMetadata(layergroup, user, mapConfig);
|
layergroupMetadata.addTileJsonMetadata(layergroup, user, mapConfig, userApiKey);
|
||||||
|
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
@ -84,16 +84,18 @@ module.exports = class LayergroupMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addTileJsonMetadata (layergroup, user, mapconfig) {
|
addTileJsonMetadata (layergroup, user, mapconfig, userApiKey = null) {
|
||||||
const isVectorOnlyMapConfig = mapconfig.isVectorOnlyMapConfig();
|
const isVectorOnlyMapConfig = mapconfig.isVectorOnlyMapConfig();
|
||||||
let hasMapnikLayers = false;
|
let hasMapnikLayers = false;
|
||||||
|
const apiKey = userApiKey ? `?api_key=${userApiKey}` : '';
|
||||||
|
|
||||||
layergroup.metadata.layers.forEach((layerMetadata, index) => {
|
layergroup.metadata.layers.forEach((layerMetadata, index) => {
|
||||||
const layerId = mapconfig.getLayerId(index);
|
const layerId = mapconfig.getLayerId(index);
|
||||||
const rasterResource = `${layergroup.layergroupid}/${layerId}/{z}/{x}/{y}.png`;
|
const rasterResource = `${layergroup.layergroupid}/${layerId}/{z}/{x}/{y}.png${apiKey}`;
|
||||||
|
|
||||||
if (mapconfig.layerType(index) === 'mapnik') {
|
if (mapconfig.layerType(index) === 'mapnik') {
|
||||||
hasMapnikLayers = true;
|
hasMapnikLayers = true;
|
||||||
const vectorResource = `${layergroup.layergroupid}/${layerId}/{z}/{x}/{y}.mvt`;
|
const vectorResource = `${layergroup.layergroupid}/${layerId}/{z}/{x}/{y}.mvt${apiKey}`;
|
||||||
const layerTilejson = {
|
const layerTilejson = {
|
||||||
vector: this._getTilejson(this.resourceLocator.getTileUrls(user, vectorResource))
|
vector: this._getTilejson(this.resourceLocator.getTileUrls(user, vectorResource))
|
||||||
};
|
};
|
||||||
@ -101,7 +103,7 @@ module.exports = class LayergroupMetadata {
|
|||||||
let grids = null;
|
let grids = null;
|
||||||
const layer = mapconfig.getLayer(index);
|
const layer = mapconfig.getLayer(index);
|
||||||
if (layer.options.interactivity) {
|
if (layer.options.interactivity) {
|
||||||
const gridResource = `${layergroup.layergroupid}/${layerId}/{z}/{x}/{y}.grid.json`;
|
const gridResource = `${layergroup.layergroupid}/${layerId}/{z}/{x}/{y}.grid.json${apiKey}`;
|
||||||
grids = this.resourceLocator.getTileUrls(user, gridResource);
|
grids = this.resourceLocator.getTileUrls(user, gridResource);
|
||||||
}
|
}
|
||||||
layerTilejson.raster = this._getTilejson(
|
layerTilejson.raster = this._getTilejson(
|
||||||
@ -121,14 +123,14 @@ module.exports = class LayergroupMetadata {
|
|||||||
const url = {};
|
const url = {};
|
||||||
|
|
||||||
if (hasMapnikLayers) {
|
if (hasMapnikLayers) {
|
||||||
const vectorResource = `${layergroup.layergroupid}/{z}/{x}/{y}.mvt`;
|
const vectorResource = `${layergroup.layergroupid}/{z}/{x}/{y}.mvt${apiKey}`;
|
||||||
tilejson.vector = this._getTilejson(
|
tilejson.vector = this._getTilejson(
|
||||||
this.resourceLocator.getTileUrls(user, vectorResource)
|
this.resourceLocator.getTileUrls(user, vectorResource)
|
||||||
);
|
);
|
||||||
url.vector = this._getTemplateUrl(this.resourceLocator.getTemplateUrls(user, vectorResource));
|
url.vector = this._getTemplateUrl(this.resourceLocator.getTemplateUrls(user, vectorResource));
|
||||||
|
|
||||||
if (!isVectorOnlyMapConfig) {
|
if (!isVectorOnlyMapConfig) {
|
||||||
const rasterResource = `${layergroup.layergroupid}/{z}/{x}/{y}.png`;
|
const rasterResource = `${layergroup.layergroupid}/{z}/{x}/{y}.png${apiKey}`;
|
||||||
tilejson.raster = this._getTilejson(
|
tilejson.raster = this._getTilejson(
|
||||||
this.resourceLocator.getTileUrls(user, rasterResource)
|
this.resourceLocator.getTileUrls(user, rasterResource)
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user