Push image encoding down to tile render, and do async

This commit is contained in:
Tom Russell 2019-02-24 13:49:16 +00:00
parent 228530cb88
commit af46067018
2 changed files with 7 additions and 7 deletions

View File

@ -162,15 +162,15 @@ function render_tile(tileset, z, x, y, geometry_id, cb){
path.join(__dirname, '..', 'map_styles', 'polygon.xml'), path.join(__dirname, '..', 'map_styles', 'polygon.xml'),
{ strict: true }, { strict: true },
function(err, map){ function(err, map){
if (err) { if (err) throw err
console.error(err);
return
}
map.add_layer(layer) map.add_layer(layer)
const im = new mapnik.Image(map.width, map.height) const im = new mapnik.Image(map.width, map.height)
map.extent = bbox map.extent = bbox
map.render(im, cb); map.render(im, {}, (err, rendered) => {
if (err) throw err
rendered.encode('png', cb)
});
} }
) )
} catch(err) { } catch(err) {

View File

@ -55,7 +55,7 @@ function handle_tile_request(tileset, req, res) {
if (err) throw err if (err) throw err
res.writeHead(200, {'Content-Type': 'image/png'}) res.writeHead(200, {'Content-Type': 'image/png'})
res.end(im.encodeSync('png')) res.end(im)
}) })
} }
@ -82,7 +82,7 @@ function handle_highlight_tile_request(req, res) {
if (err) throw err if (err) throw err
res.writeHead(200, {'Content-Type': 'image/png'}) res.writeHead(200, {'Content-Type': 'image/png'})
res.end(im.encodeSync('png')) res.end(im)
}) })
} }