From a495993e68fbdbbd92fbd7c5356f5ac09119b629 Mon Sep 17 00:00:00 2001 From: Petr Sloup Date: Wed, 9 Mar 2016 17:10:27 +0100 Subject: [PATCH] Fix behavior of area-based static maps --- src/serve_raster.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/serve_raster.js b/src/serve_raster.js index 2138e51..e9a36e8 100644 --- a/src/serve_raster.js +++ b/src/serve_raster.js @@ -188,7 +188,8 @@ module.exports = function(maps, options, prefix) { if (Math.abs(lon) > 180 || Math.abs(lat) > 85.06) { return res.status(400).send('Invalid center'); } - if (width <= 0 || height <= 0 || width > 2048 || height > 2048) { + if (Math.min(width, height) <= 0 || + Math.max(width, height) * scale > 6000) { return res.status(400).send('Invalid size'); } if (format == 'png' || format == 'webp') { @@ -288,11 +289,15 @@ module.exports = function(maps, options, prefix) { FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN); app.get(util.format(staticPattern, boundsPattern), function(req, res, next) { + var bbox = [+req.params.minx, +req.params.miny, + +req.params.maxx, +req.params.maxy]; var z = req.params.z | 0, - x = ((+req.params.minx) + (+req.params.maxx)) / 2, - y = ((+req.params.miny) + (+req.params.maxy)) / 2, - w = req.params.width | 0, - h = req.params.height | 0, + x = (bbox[0] + bbox[2]) / 2, + y = (bbox[1] + bbox[3]) / 2; + var minCorner = mercator.px([bbox[0], bbox[3]], z), + maxCorner = mercator.px([bbox[2], bbox[1]], z); + var w = (maxCorner[0] - minCorner[0]) | 0, + h = (maxCorner[1] - minCorner[1]) | 0, scale = getScale(req.params.scale), format = req.params.format; return respondImage(z, x, y, w, h, scale, format, res, next);