diff --git a/docs/endpoints.rst b/docs/endpoints.rst index 57361fd..0076779 100644 --- a/docs/endpoints.rst +++ b/docs/endpoints.rst @@ -13,10 +13,11 @@ Styles Rendered tiles ============== -* Rendered tiles are served at ``/styles/{id}/{z}/{x}/{y}[@2x].{format}`` +* Rendered tiles are served at ``/styles/{id}/{tileSize}/{z}/{x}/{y}[@2x].{format}`` * The optional ``@2x`` (or ``@3x``, ``@4x``) part can be used to render HiDPI (retina) tiles * Available formats: ``png``, ``jpg`` (``jpeg``), ``webp`` + * Tile sizes: ``256``, ``512`` * TileJSON at ``/styles/{id}.json`` * The rendered tiles are not available in the ``tileserver-gl-light`` version. diff --git a/public/templates/wmts.tmpl b/public/templates/wmts.tmpl index 683c3ac..a9b3a81 100644 --- a/public/templates/wmts.tmpl +++ b/public/templates/wmts.tmpl @@ -36,8 +36,8 @@ - - {{name}} + + {{name}}-256 {{id}} -180 -85.051128779807 @@ -48,13 +48,30 @@ image/png - GoogleMapsCompatible + GoogleMapsCompatible_256 - - - GoogleMapsCompatible - GoogleMapsCompatible EPSG:3857 - GoogleMapsCompatible + + + + {{name}}-512 + {{id}} + + -180 -85.051128779807 + 180 85.051128779807 + + + image/png + + GoogleMapsCompatible_512 + + + + + GoogleMapsCompatible_256 + GoogleMapsCompatible_256 EPSG:3857 + GoogleMapsCompatible_256 urn:ogc:def:crs:EPSG::3857 0 @@ -226,10 +243,189 @@ 256 262144 262144 - - WGS84 - WGS84 EPSG:4326 - WGS84 + + + + GoogleMapsCompatible_512 + GoogleMapsCompatible_512 EPSG:3857 + GoogleMapsCompatible_512 + urn:ogc:def:crs:EPSG::3857 + + 0 + 279541132.0143589 + -20037508.34 20037508.34 + 512 + 512 + 1 + 1 + + + 1 + 139770566.0071794 + -20037508.34 20037508.34 + 512 + 512 + 2 + 2 + + + 2 + 69885283.00358972 + -20037508.34 20037508.34 + 512 + 512 + 4 + 4 + + + 3 + 34942641.501795 + -20037508.34 20037508.34 + 512 + 512 + 8 + 8 + + + 4 + 17471320.750897 + -20037508.34 20037508.34 + 512 + 512 + 16 + 16 + + + 5 + 8735660.3754487 + -20037508.34 20037508.34 + 512 + 512 + 32 + 32 + + + 6 + 4367830.1877244 + -20037508.34 20037508.34 + 512 + 512 + 64 + 64 + + + 7 + 2183915.0938622 + -20037508.34 20037508.34 + 512 + 512 + 128 + 128 + + + 8 + 1091957.5469311 + -20037508.34 20037508.34 + 512 + 512 + 256 + 256 + + + 9 + 545978.77346554 + -20037508.34 20037508.34 + 512 + 512 + 512 + 512 + + + 10 + 272989.38673277 + -20037508.34 20037508.34 + 512 + 512 + 1024 + 1024 + + + 11 + 136494.69336639 + -20037508.34 20037508.34 + 512 + 512 + 2048 + 2048 + + + 12 + 68247.346683193 + -20037508.34 20037508.34 + 512 + 512 + 4096 + 4096 + + + 13 + 34123.673341597 + -20037508.34 20037508.34 + 512 + 512 + 8192 + 8192 + + + 14 + 17061.836670798 + -20037508.34 20037508.34 + 512 + 512 + 16384 + 16384 + + + 15 + 8530.9183353991 + -20037508.34 20037508.34 + 512 + 512 + 32768 + 32768 + + + 16 + 4265.4591676996 + -20037508.34 20037508.34 + 512 + 512 + 65536 + 65536 + + + 17 + 2132.7295838498 + -20037508.34 20037508.34 + 512 + 512 + 131072 + 131072 + + + 18 + 1066.364791924892 + -20037508.34 20037508.34 + 512 + 512 + 262144 + 262144 + + + + WGS84_256 + WGS84_256 EPSG:4326 + WGS84_256 urn:ogc:def:crs:EPSG::4326 0 @@ -401,7 +597,185 @@ 256 524288 262144 - + + + + WGS84_512 + WGS84_512 EPSG:4326 + WGS84_512 + urn:ogc:def:crs:EPSG::4326 + + 0 + 139770566.00718 + 90 -180 + 512 + 512 + 2 + 1 + + + 1 + 69885283.00359 + 90 -180 + 512 + 512 + 4 + 2 + + + 2 + 34942641.501795 + 90 -180 + 512 + 512 + 8 + 4 + + + 3 + 17471320.750897 + 90 -180 + 512 + 512 + 16 + 8 + + + 4 + 8735660.3754487 + 90 -180 + 512 + 512 + 32 + 16 + + + 5 + 4367830.1877244 + 90 -180 + 512 + 512 + 64 + 32 + + + 6 + 2183915.0938622 + 90 -180 + 512 + 512 + 128 + 64 + + + 7 + 1091957.5469311 + 90 -180 + 512 + 512 + 256 + 128 + + + 8 + 545978.77346554 + 90 -180 + 512 + 512 + 512 + 256 + + + 9 + 272989.38673277 + 90 -180 + 512 + 512 + 1024 + 512 + + + 10 + 136494.69336639 + 90 -180 + 512 + 512 + 2048 + 1024 + + + 11 + 68247.346683193 + 90 -180 + 512 + 512 + 4096 + 2048 + + + 12 + 34123.673341597 + 90 -180 + 512 + 512 + 8192 + 4096 + + + 13 + 17061.836670798 + 90 -180 + 512 + 512 + 16384 + 8192 + + + 14 + 8530.9183353991 + 90 -180 + 512 + 512 + 32768 + 16384 + + + 15 + 4265.4591676996 + 90 -180 + 512 + 512 + 65536 + 32768 + + + 16 + 2132.7295838498 + 90 -180 + 512 + 512 + 131072 + 65536 + + + 17 + 1066.3647919249 + 90 -180 + 512 + 512 + 262144 + 131072 + + + 18 + 533.182 + 90 -180 + 512 + 512 + 524288 + 262144 + + diff --git a/src/serve_rendered.js b/src/serve_rendered.js index 11b6bfb..fdc015c 100644 --- a/src/serve_rendered.js +++ b/src/serve_rendered.js @@ -356,7 +356,7 @@ module.exports = { }); }; - app.get(`/:id/:z(\\d+)/:x(\\d+)/:y(\\d+):scale(${scalePattern})?.:format([\\w]+)`, (req, res, next) => { + app.get(`/:id/:tileSize(256|512)/:z(\\d+)/:x(\\d+)/:y(\\d+):scale(${scalePattern})?.:format([\\w]+)`, (req, res, next) => { const item = repo[req.params.id]; if (!item) { return res.sendStatus(404); @@ -373,16 +373,19 @@ module.exports = { x = req.params.x | 0, y = req.params.y | 0, scale = getScale(req.params.scale), - format = req.params.format; + format = req.params.format, + tileSize = parseInt(req.params.tileSize, 10) || 256; + if (z < 0 || x < 0 || y < 0 || z > 22 || x >= Math.pow(2, z) || y >= Math.pow(2, z)) { return res.status(404).send('Out of bounds'); - } - const tileSize = 256; + }; + const tileCenter = mercator.ll([ - ((x + 0.5) / (1 << z)) * (256 << z), - ((y + 0.5) / (1 << z)) * (256 << z) + ((x + 0.5) / (1 << z)) * (tileSize << z), + ((y + 0.5) / (1 << z)) * (tileSize << z) ], z); + return respondImage(item, z, tileCenter[0], tileCenter[1], 0, 0, tileSize, tileSize, scale, format, res, next); }); diff --git a/src/server.js b/src/server.js index 9fedc02..d27f648 100644 --- a/src/server.js +++ b/src/server.js @@ -342,7 +342,8 @@ function start(opts) { style.viewer_hash = `#${center[2]}/${center[1].toFixed(5)}/${center[0].toFixed(5)}`; const centerPx = mercator.px([center[0], center[1]], center[2]); - style.thumbnail = `${center[2]}/${Math.floor(centerPx[0] / 256)}/${Math.floor(centerPx[1] / 256)}.png`; + // Set thumbnail default size to be 256px x 256px + style.thumbnail = `256/${center[2]}/${Math.floor(centerPx[0] / 256)}/${Math.floor(centerPx[1] / 256)}.png`; } style.xyz_link = utils.getTileUrls( diff --git a/src/utils.js b/src/utils.js index 6037e20..8deda88 100644 --- a/src/utils.js +++ b/src/utils.js @@ -6,11 +6,9 @@ const fs = require('fs'); const clone = require('clone'); const glyphCompose = require('@mapbox/glyph-pbf-composite'); - module.exports.getPublicUrl = (publicUrl, req) => publicUrl || `${req.protocol}://${req.headers.host}/`; module.exports.getTileUrls = (req, domains, path, format, publicUrl, aliases) => { - if (domains) { if (domains.constructor === String && domains.length > 0) { domains = domains.split(','); @@ -51,13 +49,18 @@ module.exports.getTileUrls = (req, domains, path, format, publicUrl, aliases) => format = aliases[format]; } + let tileParams = '{z}/{x}/{y}'; + if (['png', 'jpg', 'jpeg', 'webp'].includes(format)) { + tileParams = '256/{z}/{x}/{y}'; + } + const uris = []; if (!publicUrl) { for (const domain of domains) { - uris.push(`${req.protocol}://${domain}/${path}/{z}/{x}/{y}.${format}${query}`); + uris.push(`${req.protocol}://${domain}/${path}/${tileParams}.${format}${query}`); } } else { - uris.push(`${publicUrl}${path}/{z}/{x}/{y}.${format}${query}`) + uris.push(`${publicUrl}${path}/${tileParams}.${format}${query}`) } return uris;