Fix unzip bug
This commit is contained in:
parent
99af9eae23
commit
d3a685e51c
1 changed files with 18 additions and 3 deletions
|
@ -77,7 +77,8 @@ module.exports = function(options, repo, params, id, styles) {
|
||||||
return res.status(404).send('Not found');
|
return res.status(404).send('Not found');
|
||||||
} else {
|
} else {
|
||||||
if (tileJSON['format'] == 'pbf') {
|
if (tileJSON['format'] == 'pbf') {
|
||||||
data = zlib.unzipSync(data);
|
var isGzipped = data.slice(0,2).indexOf(
|
||||||
|
new Buffer([0x1f, 0x8b])) === 0;
|
||||||
var style = req.query.style;
|
var style = req.query.style;
|
||||||
if (style && tileshrinkGl) {
|
if (style && tileshrinkGl) {
|
||||||
if (!shrinkers[style]) {
|
if (!shrinkers[style]) {
|
||||||
|
@ -96,6 +97,10 @@ module.exports = function(options, repo, params, id, styles) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shrinkers[style]) {
|
if (shrinkers[style]) {
|
||||||
|
if (isGzipped) {
|
||||||
|
data = zlib.unzipSync(data);
|
||||||
|
isGzipped = false;
|
||||||
|
}
|
||||||
data = shrinkers[style](data, z, tileJSON.maxzoom);
|
data = shrinkers[style](data, z, tileJSON.maxzoom);
|
||||||
//console.log(shrinkers[style].getStats());
|
//console.log(shrinkers[style].getStats());
|
||||||
}
|
}
|
||||||
|
@ -106,7 +111,12 @@ module.exports = function(options, repo, params, id, styles) {
|
||||||
} else if (req.params.format == 'geojson') {
|
} else if (req.params.format == 'geojson') {
|
||||||
headers['Content-Type'] = 'application/json';
|
headers['Content-Type'] = 'application/json';
|
||||||
|
|
||||||
var tile = new VectorTile(new pbf(zlib.unzipSync(data)));
|
if (isGzipped) {
|
||||||
|
data = zlib.unzipSync(data);
|
||||||
|
isGzipped = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tile = new VectorTile(new pbf(data));
|
||||||
var geojson = {
|
var geojson = {
|
||||||
"type": "FeatureCollection",
|
"type": "FeatureCollection",
|
||||||
"features": []
|
"features": []
|
||||||
|
@ -126,7 +136,12 @@ module.exports = function(options, repo, params, id, styles) {
|
||||||
headers['Content-Encoding'] = 'gzip';
|
headers['Content-Encoding'] = 'gzip';
|
||||||
res.set(headers);
|
res.set(headers);
|
||||||
|
|
||||||
return res.status(200).send(zlib.gzipSync(data));
|
if (!isGzipped) {
|
||||||
|
data = zlib.gzipSync(data);
|
||||||
|
isGzipped = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).send(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue