Add concept of data decorator function
This commit is contained in:
@@ -50,6 +50,10 @@ module.exports = function(options, repo, params, id, styles) {
|
||||
|
||||
Object.assign(tileJSON, params.tilejson || {});
|
||||
utils.fixTileJSONCenter(tileJSON);
|
||||
|
||||
if (options.dataDecoratorFunc) {
|
||||
tileJSON = options.dataDecoratorFunc(id, 'tilejson', tileJSON);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
@@ -114,6 +118,13 @@ module.exports = function(options, repo, params, id, styles) {
|
||||
//console.log(shrinkers[style].getStats());
|
||||
}
|
||||
}
|
||||
if (options.dataDecoratorFunc) {
|
||||
if (isGzipped) {
|
||||
data = zlib.unzipSync(data);
|
||||
isGzipped = false;
|
||||
}
|
||||
data = options.dataDecoratorFunc(id, 'data', data, z, x, y);
|
||||
}
|
||||
}
|
||||
if (format == 'pbf') {
|
||||
headers['Content-Type'] = 'application/x-protobuf';
|
||||
|
||||
@@ -100,7 +100,8 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
});
|
||||
} else if (protocol == 'mbtiles') {
|
||||
var parts = req.url.split('/');
|
||||
var source = map.sources[parts[2]];
|
||||
var sourceId = parts[2];
|
||||
var source = map.sources[sourceId];
|
||||
var z = parts[3] | 0,
|
||||
x = parts[4] | 0,
|
||||
y = parts[5].split('.')[0] | 0,
|
||||
@@ -118,6 +119,10 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
|
||||
if (format == 'pbf') {
|
||||
response.data = zlib.unzipSync(data);
|
||||
if (options.dataDecoratorFunc) {
|
||||
response.data = options.dataDecoratorFunc(
|
||||
sourceId, 'data', response.data, z, x, y);
|
||||
}
|
||||
} else {
|
||||
response.data = data;
|
||||
}
|
||||
@@ -258,6 +263,11 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||
'mbtiles://' + name + '/{z}/{x}/{y}.' + (info.format || 'pbf')
|
||||
];
|
||||
delete source.scheme;
|
||||
|
||||
if (options.dataDecoratorFunc) {
|
||||
source = options.dataDecoratorFunc(name, 'tilejson', source);
|
||||
}
|
||||
|
||||
if (source.format == 'pbf') {
|
||||
map.sources[name].emptyTile = new Buffer(0);
|
||||
} else {
|
||||
|
||||
@@ -89,6 +89,12 @@ function start(opts) {
|
||||
checkPath('sprites');
|
||||
checkPath('mbtiles');
|
||||
|
||||
if (options.dataDecorator) {
|
||||
try {
|
||||
options.dataDecoratorFunc = require(path.resolve(paths.root, options.dataDecorator));
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
var data = clone(config.data || {});
|
||||
|
||||
if (opts.cors) {
|
||||
|
||||
Reference in New Issue
Block a user