Configurable optional alias for .pbf tiles (#109)
This commit is contained in:
parent
1079ece860
commit
6231f9f7a7
4 changed files with 24 additions and 9 deletions
|
@ -26,6 +26,7 @@ Example::
|
||||||
"png": 90
|
"png": 90
|
||||||
},
|
},
|
||||||
"maxSize": 2048,
|
"maxSize": 2048,
|
||||||
|
"pbfAlias": "pbf",
|
||||||
"serveAllFonts": false
|
"serveAllFonts": false
|
||||||
},
|
},
|
||||||
"styles": {
|
"styles": {
|
||||||
|
|
|
@ -50,14 +50,18 @@ module.exports = function(options, repo, params, id, styles) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var tilePattern = '/' + id + '/:z(\\d+)/:x(\\d+)/:y(\\d+).:format([\\w]+)';
|
var tilePattern = '/' + id + '/:z(\\d+)/:x(\\d+)/:y(\\d+).:format([\\w.]+)';
|
||||||
|
|
||||||
app.get(tilePattern, function(req, res, next) {
|
app.get(tilePattern, function(req, res, next) {
|
||||||
var z = req.params.z | 0,
|
var z = req.params.z | 0,
|
||||||
x = req.params.x | 0,
|
x = req.params.x | 0,
|
||||||
y = req.params.y | 0;
|
y = req.params.y | 0;
|
||||||
if (req.params.format != tileJSON.format &&
|
var format = req.params.format;
|
||||||
!(req.params.format == 'geojson' && tileJSON.format == 'pbf')) {
|
if (format == options.pbfAlias) {
|
||||||
|
format = 'pbf';
|
||||||
|
}
|
||||||
|
if (format != tileJSON.format &&
|
||||||
|
!(format == 'geojson' && tileJSON.format == 'pbf')) {
|
||||||
return res.status(404).send('Invalid format');
|
return res.status(404).send('Invalid format');
|
||||||
}
|
}
|
||||||
if (z < tileJSON.minzoom || 0 || x < 0 || y < 0 ||
|
if (z < tileJSON.minzoom || 0 || x < 0 || y < 0 ||
|
||||||
|
@ -106,9 +110,9 @@ module.exports = function(options, repo, params, id, styles) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (req.params.format == 'pbf') {
|
if (format == 'pbf') {
|
||||||
headers['Content-Type'] = 'application/x-protobuf';
|
headers['Content-Type'] = 'application/x-protobuf';
|
||||||
} else if (req.params.format == 'geojson') {
|
} else if (format == 'geojson') {
|
||||||
headers['Content-Type'] = 'application/json';
|
headers['Content-Type'] = 'application/json';
|
||||||
|
|
||||||
if (isGzipped) {
|
if (isGzipped) {
|
||||||
|
@ -150,7 +154,9 @@ module.exports = function(options, repo, params, id, styles) {
|
||||||
app.get('/' + id + '.json', function(req, res, next) {
|
app.get('/' + id + '.json', function(req, res, next) {
|
||||||
var info = clone(tileJSON);
|
var info = clone(tileJSON);
|
||||||
info.tiles = utils.getTileUrls(req, info.tiles,
|
info.tiles = utils.getTileUrls(req, info.tiles,
|
||||||
'data/' + id, info.format);
|
'data/' + id, info.format, {
|
||||||
|
'pbf': options.pbfAlias
|
||||||
|
});
|
||||||
return res.send(info);
|
return res.send(info);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -186,7 +186,9 @@ module.exports = function(opts, callback) {
|
||||||
} else {
|
} else {
|
||||||
path = type + '/' + id;
|
path = type + '/' + id;
|
||||||
}
|
}
|
||||||
info.tiles = utils.getTileUrls(req, info.tiles, path, info.format);
|
info.tiles = utils.getTileUrls(req, info.tiles, path, info.format, {
|
||||||
|
'pbf': options.pbfAlias
|
||||||
|
});
|
||||||
arr.push(info);
|
arr.push(info);
|
||||||
});
|
});
|
||||||
return arr;
|
return arr;
|
||||||
|
@ -287,7 +289,9 @@ module.exports = function(opts, callback) {
|
||||||
'/data/' + id + '.json' + query) + '/wmts';
|
'/data/' + id + '.json' + query) + '/wmts';
|
||||||
|
|
||||||
var tiles = utils.getTileUrls(
|
var tiles = utils.getTileUrls(
|
||||||
req, data_.tiles, 'data/' + id, data_.format);
|
req, data_.tiles, 'data/' + id, data_.format, {
|
||||||
|
'pbf': options.pbfAlias
|
||||||
|
});
|
||||||
data_.xyz_link = tiles[0];
|
data_.xyz_link = tiles[0];
|
||||||
}
|
}
|
||||||
if (data_.filesize) {
|
if (data_.filesize) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ var async = require('async'),
|
||||||
var clone = require('clone'),
|
var clone = require('clone'),
|
||||||
glyphCompose = require('glyph-pbf-composite');
|
glyphCompose = require('glyph-pbf-composite');
|
||||||
|
|
||||||
module.exports.getTileUrls = function(req, domains, path, format) {
|
module.exports.getTileUrls = function(req, domains, path, format, aliases) {
|
||||||
|
|
||||||
if (domains) {
|
if (domains) {
|
||||||
if (domains.constructor === String && domains.length > 0) {
|
if (domains.constructor === String && domains.length > 0) {
|
||||||
|
@ -28,6 +28,10 @@ module.exports.getTileUrls = function(req, domains, path, format) {
|
||||||
}
|
}
|
||||||
var query = queryParams.length > 0 ? ('?' + queryParams.join('&')) : '';
|
var query = queryParams.length > 0 ? ('?' + queryParams.join('&')) : '';
|
||||||
|
|
||||||
|
if (aliases && aliases[format]) {
|
||||||
|
format = aliases[format];
|
||||||
|
}
|
||||||
|
|
||||||
var uris = [];
|
var uris = [];
|
||||||
domains.forEach(function(domain) {
|
domains.forEach(function(domain) {
|
||||||
uris.push(req.protocol + '://' + domain + '/' + path +
|
uris.push(req.protocol + '://' + domain + '/' + path +
|
||||||
|
|
Loading…
Reference in a new issue