Fix interim empty tile generation for raster layers

This commit is contained in:
Petr Sloup 2017-01-10 15:47:56 +01:00
parent 4082828790
commit b9930dd195
2 changed files with 6 additions and 4 deletions

View file

@ -25,7 +25,7 @@
"base64url": "2.0.0", "base64url": "2.0.0",
"canvas": "1.6.2", "canvas": "1.6.2",
"clone": "2.1.0", "clone": "2.1.0",
"color": "1.0.2", "color": "1.0.3",
"cors": "2.8.1", "cors": "2.8.1",
"express": "4.14.0", "express": "4.14.0",
"glyph-pbf-composite": "0.0.2", "glyph-pbf-composite": "0.0.2",

View file

@ -230,16 +230,18 @@ module.exports = function(options, repo, params, id, dataResolver) {
if (source.format == 'pbf') { if (source.format == 'pbf') {
map.sources[name].emptyTile = new Buffer(0); map.sources[name].emptyTile = new Buffer(0);
} else { } else {
var color = new Color(source.color || '#fff'); var color = new Color(source.color || 'rgba(255,255,255,0)');
var format = source.format; var format = source.format;
if (format == 'jpg') { if (format == 'jpg') {
format = 'jpeg'; format = 'jpeg';
} }
sharp(new Buffer(color.rgbArray()), { var array = color.array();
var channels = array.length == 4 && format != 'jpeg' ? 4 : 3;
sharp(new Buffer(array), {
raw: { raw: {
width: 1, width: 1,
height: 1, height: 1,
channels: 3 channels: channels
} }
}).toFormat(format).toBuffer(function(err, buffer, info) { }).toFormat(format).toBuffer(function(err, buffer, info) {
map.sources[name].emptyTile = buffer; map.sources[name].emptyTile = buffer;