Skip to content

Commit

Permalink
Fix incorrect TileSize in index.json and data.json data urls. Add Til…
Browse files Browse the repository at this point in the history
…eSize 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
  • Loading branch information
acalcutt authored Feb 2, 2024
1 parent c34c578 commit fe111ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 3 additions & 1 deletion docs/endpoints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======================
Expand Down
22 changes: 15 additions & 7 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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,
),
);
});

// ------------------------------------
Expand Down

0 comments on commit fe111ed

Please sign in to comment.