mirror of
https://github.com/maptiler/tileserver-gl.git
synced 2024-11-28 13:42:46 +03:00
Experimental integration of first plugin
This commit is contained in:
parent
bcac161a25
commit
1aaabd2dff
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,5 +3,6 @@ node_modules
|
||||
test_data
|
||||
data
|
||||
light
|
||||
plugins
|
||||
config.json
|
||||
*.mbtiles
|
||||
|
@ -36,6 +36,9 @@
|
||||
"sphericalmercator": "1.0.5",
|
||||
"tileserver-gl-styles": "0.3.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"tileshrink-gl": "./plugins/tileshrink-gl"
|
||||
},
|
||||
"devDependencies": {
|
||||
"should": "^10.0.0",
|
||||
"mocha": "^2.5.0",
|
||||
|
@ -7,9 +7,14 @@ var clone = require('clone'),
|
||||
express = require('express'),
|
||||
mbtiles = require('mbtiles');
|
||||
|
||||
var tileshrinkGl;
|
||||
try {
|
||||
tileshrinkGl = require('tileshrink-gl');
|
||||
} catch (e) {}
|
||||
|
||||
var utils = require('./utils');
|
||||
|
||||
module.exports = function(options, repo, params, id) {
|
||||
module.exports = function(options, repo, params, id, styles) {
|
||||
var app = express().disable('x-powered-by');
|
||||
|
||||
var mbtilesFile = path.resolve(options.paths.mbtiles, params.mbtiles);
|
||||
@ -17,6 +22,8 @@ module.exports = function(options, repo, params, id) {
|
||||
'tiles': params.domains || options.domains
|
||||
};
|
||||
|
||||
var shrinkers = {};
|
||||
|
||||
repo[id] = tileJSON;
|
||||
|
||||
var mbtilesFileStats = fs.statSync(mbtilesFile);
|
||||
@ -61,17 +68,40 @@ module.exports = function(options, repo, params, id) {
|
||||
} else {
|
||||
return res.status(500).send(err.message);
|
||||
}
|
||||
} else {
|
||||
if (data == null) {
|
||||
return res.status(404).send('Not found');
|
||||
} else {
|
||||
if (tileJSON['format'] == 'pbf') {
|
||||
headers['Content-Type'] = 'application/x-protobuf';
|
||||
headers['Content-Encoding'] = 'gzip';
|
||||
|
||||
var style = req.query.style;
|
||||
if (style && tileshrinkGl) {
|
||||
if (!shrinkers[style]) {
|
||||
var styleJSON = styles[style];
|
||||
if (styleJSON) {
|
||||
var sourceName = null;
|
||||
for (var sourceName_ in styleJSON.sources) {
|
||||
var source = styleJSON.sources[sourceName_];
|
||||
if (source &&
|
||||
source.type == 'vector' &&
|
||||
source.url.endsWith('/' + id + '.json')) {
|
||||
sourceName = sourceName_;
|
||||
}
|
||||
}
|
||||
shrinkers[style] = tileshrinkGl.createPBFShrinker(styleJSON, sourceName);
|
||||
}
|
||||
}
|
||||
if (shrinkers[style]) {
|
||||
data = shrinkers[style](data, z, tileJSON.maxzoom);
|
||||
//console.log(shrinkers[style].getStats());
|
||||
}
|
||||
}
|
||||
}
|
||||
delete headers['ETag']; // do not trust the tile ETag -- regenerate
|
||||
res.set(headers);
|
||||
|
||||
if (data == null) {
|
||||
return res.status(404).send('Not found');
|
||||
} else {
|
||||
return res.status(200).send(data);
|
||||
}
|
||||
}
|
||||
|
@ -53,10 +53,11 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||
|
||||
app.get('/' + id + '.json', function(req, res, next) {
|
||||
var fixUrl = function(url, opt_nokey) {
|
||||
var query = '';
|
||||
var queryParams = ['style=' + id];
|
||||
if (!opt_nokey && req.query.key) {
|
||||
query = '?key=' + req.query.key;
|
||||
queryParams.unshift('key=' + req.query.key);
|
||||
}
|
||||
var query = '?' + queryParams.join('&');
|
||||
return url.replace(
|
||||
'local://', req.protocol + '://' + req.headers.host + '/') + query;
|
||||
};
|
||||
|
@ -153,7 +153,7 @@ module.exports = function(opts, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.use('/data/', serve_data(options, serving.data, item, id));
|
||||
app.use('/data/', serve_data(options, serving.data, item, id, serving.styles));
|
||||
});
|
||||
|
||||
app.get('/styles.json', function(req, res, next) {
|
||||
|
@ -18,7 +18,14 @@ module.exports.getTileUrls = function(req, domains, path, format) {
|
||||
}
|
||||
|
||||
var key = req.query.key;
|
||||
var query = (key && key.length > 0) ? ('?key=' + key) : '';
|
||||
var queryParams = [];
|
||||
if (req.query.key) {
|
||||
queryParams.push('key=' + req.query.key);
|
||||
}
|
||||
if (req.query.style) {
|
||||
queryParams.push('style=' + req.query.style);
|
||||
}
|
||||
var query = queryParams.length > 0 ? ('?' + queryParams.join('&')) : '';
|
||||
|
||||
var uris = [];
|
||||
domains.forEach(function(domain) {
|
||||
|
Loading…
Reference in New Issue
Block a user