Fix incorrect TileSize in index.json and data.json data urls. Add TileSize option to index.json and rendered.json endpoints for rendered urls. (#1160)

* fix: tilesize should not be added to data endpoint

* fix: make tilesize and option of addtilejson urls

* docs: update tilesize info for index.json and rendered.json

* fix: lint
This commit is contained in:
Andrew Calcutt 2024-02-02 10:37:35 -05:00 committed by GitHub
parent c34c5786bd
commit fe111ed18f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 8 deletions

View File

@ -102,7 +102,9 @@ Source data
TileJSON arrays
===============
Array of all TileJSONs is at ``/index.json`` (``/rendered.json``; ``/data.json``)
Array of all TileJSONs is at ``[/{tileSize}]/index.json`` (``[/{tileSize}]/rendered.json``; ``/data.json``)
* The optional tile size ``/{tileSize}`` (ex. ``/256``, ``/512``). if omitted, tileSize defaults to 256.
List of available fonts
=======================

View File

@ -354,9 +354,8 @@ function start(opts) {
res.send(result);
});
const addTileJSONs = (arr, req, type) => {
const addTileJSONs = (arr, req, type, tileSize) => {
for (const id of Object.keys(serving[type])) {
const tileSize = 256;
const info = clone(serving[type][id].tileJSON);
let path = '';
if (type === 'rendered') {
@ -380,14 +379,23 @@ function start(opts) {
return arr;
};
app.get('/rendered.json', (req, res, next) => {
res.send(addTileJSONs([], req, 'rendered'));
app.get('/(:tileSize(256|512)/)?rendered.json', (req, res, next) => {
const tileSize = parseInt(req.params.tileSize, 10) || 256;
res.send(addTileJSONs([], req, 'rendered', tileSize));
});
app.get('/data.json', (req, res, next) => {
res.send(addTileJSONs([], req, 'data'));
res.send(addTileJSONs([], req, 'data', undefined));
});
app.get('/index.json', (req, res, next) => {
res.send(addTileJSONs(addTileJSONs([], req, 'rendered'), req, 'data'));
app.get('/(:tileSize(256|512)/)?index.json', (req, res, next) => {
const tileSize = parseInt(req.params.tileSize, 10) || 256;
res.send(
addTileJSONs(
addTileJSONs([], req, 'rendered', tileSize),
req,
'data',
undefined,
),
);
});
// ------------------------------------