From 9d362a5b5ed6171a1b7944673e5ee72220b0cb5c Mon Sep 17 00:00:00 2001 From: Petr Sloup Date: Mon, 5 Dec 2016 23:02:48 +0100 Subject: [PATCH] Experimental static endpoints working with raw mercator coordinates --- src/serve_rendered.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/serve_rendered.js b/src/serve_rendered.js index 337b05b..14f74f6 100644 --- a/src/serve_rendered.js +++ b/src/serve_rendered.js @@ -446,18 +446,19 @@ module.exports = function(options, repo, params, id, dataResolver) { }; var staticPattern = - '/static/%s/:width(\\d+)x:height(\\d+)' + + '/static/:raw([\\w]+)?/%s/:width(\\d+)x:height(\\d+)' + ':scale(' + SCALE_PATTERN + ')?\.:format([\\w]+)'; var centerPattern = - util.format(':lon(%s),:lat(%s),:z(%s)(@:bearing(%s)(,:pitch(%s))?)?', + util.format(':x(%s),:y(%s),:z(%s)(@:bearing(%s)(,:pitch(%s))?)?', FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN); app.get(util.format(staticPattern, centerPattern), function(req, res, next) { + var raw = req.params.raw; var z = +req.params.z, - x = +req.params.lon, - y = +req.params.lat, + x = +req.params.x, + y = +req.params.y, bearing = +(req.params.bearing || '0'), pitch = +(req.params.pitch || '0'), w = req.params.width | 0, @@ -469,6 +470,12 @@ module.exports = function(options, repo, params, id, dataResolver) { return res.status(404).send('Invalid zoom'); } + if (raw) { + var ll = mercator.inverse([x, y]); + x = ll[0]; + y = ll[1]; + } + var path = extractPathFromQuery(req.query); var overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale, path, req.query); @@ -482,8 +489,19 @@ module.exports = function(options, repo, params, id, dataResolver) { FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN); app.get(util.format(staticPattern, boundsPattern), function(req, res, next) { + var raw = req.params.raw; var bbox = [+req.params.minx, +req.params.miny, +req.params.maxx, +req.params.maxy]; + + if (raw) { + var minCorner = mercator.inverse(bbox.slice(0, 2)); + var maxCorner = mercator.inverse(bbox.slice(2)); + bbox[0] = minCorner[0]; + bbox[1] = minCorner[1]; + bbox[2] = maxCorner[0]; + bbox[3] = maxCorner[1]; + } + var w = req.params.width | 0, h = req.params.height | 0, scale = getScale(req.params.scale), @@ -510,6 +528,7 @@ module.exports = function(options, repo, params, id, dataResolver) { return res.status(400).send('Invalid path'); } + var raw = req.params.raw; var w = req.params.width | 0, h = req.params.height | 0, bearing = 0, @@ -529,6 +548,12 @@ module.exports = function(options, repo, params, id, dataResolver) { x = (bbox[0] + bbox[2]) / 2, y = (bbox[1] + bbox[3]) / 2; + if (raw) { + var ll = mercator.inverse([x, y]); + x = ll[0]; + y = ll[1]; + } + var overlay = renderOverlay(z, x, y, bearing, pitch, w, h, scale, path, req.query);