From 102244f46717b3616fb8e11a846b2bf5e1076752 Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Wed, 6 Jun 2018 13:50:11 +0200 Subject: [PATCH] Regression: Accept layer option in the static map urls --- docs/static_maps_api.md | 5 ++++- .../map-store-map-config-provider.js | 5 +++-- test/acceptance/analysis/named-maps.js | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/static_maps_api.md b/docs/static_maps_api.md index 34e4e907..554f892d 100644 --- a/docs/static_maps_api.md +++ b/docs/static_maps_api.md @@ -11,7 +11,7 @@ Begin by instantiating either a Named or Anonymous Map using the `layergroupid t #### Definition ```bash -GET /api/v1/map/static/center/{token}/{z}/{lat}/{lng}/{width}/{height}.{format} +GET /api/v1/map/static/center/{token}/{z}/{lat}/{lng}/{width}/{height}.{format}{{?}extra_options} ``` #### Params @@ -58,6 +58,9 @@ Note: you can see this endpoint as GET /api/v1/map/static/bbox/{token}/{west},{south},{east},{north}/{width}/{height}.{format}` ``` +#### Extra options + * Layer: List of layers to be shown in the image (by default `all`), for example `?layer=0,1`. + ### Named Map #### Definition diff --git a/lib/cartodb/api/middlewares/map-store-map-config-provider.js b/lib/cartodb/api/middlewares/map-store-map-config-provider.js index 58cdb79e..a5b4b1f6 100644 --- a/lib/cartodb/api/middlewares/map-store-map-config-provider.js +++ b/lib/cartodb/api/middlewares/map-store-map-config-provider.js @@ -10,12 +10,13 @@ module.exports = function createMapStoreMapConfigProvider ( return function createMapStoreMapConfigProviderMiddleware (req, res, next) { const { user, token, cache_buster, api_key } = res.locals; const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals; - const { layer, z, x, y, scale_factor, format } = req.params; + const { layer: layerFromParams, z, x, y, scale_factor, format } = req.params; + const { layer: layerFromQuery } = req.query; const params = { user, token, cache_buster, api_key, dbuser, dbname, dbpassword, dbhost, dbport, - layer, z, x, y, scale_factor, format + layer: (layerFromQuery || layerFromParams), z, x, y, scale_factor, format }; if (forcedFormat) { diff --git a/test/acceptance/analysis/named-maps.js b/test/acceptance/analysis/named-maps.js index 98316d2d..5172b110 100644 --- a/test/acceptance/analysis/named-maps.js +++ b/test/acceptance/analysis/named-maps.js @@ -261,6 +261,27 @@ describe('named-maps analysis', function() { ); }); + it('should fail to retrieve static map preview via layergroup ' + + 'when filtering by invalid layers', function(done) { + assert.response( + server, + { + url: '/api/v1/map/static/center/' + layergroupid + '/4/42/-3/320/240.png?layer=1', + method: 'GET', + encoding: 'binary', + headers: { + host: username + } + }, + { + status: 400 + }, + function(res, err) { + done(err); + } + ); + }); + it('should return and an error requesting unsupported image format', function(done) { assert.response( server,