From af46067018eb57125915766b85c0ccd1c77e047c Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Sun, 24 Feb 2019 13:49:16 +0000 Subject: [PATCH] Push image encoding down to tile render, and do async --- app/src/tiles/tile.js | 10 +++++----- app/src/tiles/tileserver.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/tiles/tile.js b/app/src/tiles/tile.js index e4370418..d4ec7f84 100644 --- a/app/src/tiles/tile.js +++ b/app/src/tiles/tile.js @@ -162,15 +162,15 @@ function render_tile(tileset, z, x, y, geometry_id, cb){ path.join(__dirname, '..', 'map_styles', 'polygon.xml'), { strict: true }, function(err, map){ - if (err) { - console.error(err); - return - } + if (err) throw err map.add_layer(layer) const im = new mapnik.Image(map.width, map.height) map.extent = bbox - map.render(im, cb); + map.render(im, {}, (err, rendered) => { + if (err) throw err + rendered.encode('png', cb) + }); } ) } catch(err) { diff --git a/app/src/tiles/tileserver.js b/app/src/tiles/tileserver.js index c3ef3e1c..74fbd5f1 100644 --- a/app/src/tiles/tileserver.js +++ b/app/src/tiles/tileserver.js @@ -55,7 +55,7 @@ function handle_tile_request(tileset, req, res) { if (err) throw err 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 res.writeHead(200, {'Content-Type': 'image/png'}) - res.end(im.encodeSync('png')) + res.end(im) }) }