Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(landing): Load config into debug pages. #2486

Merged
merged 7 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/lambda-tiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { arcgisInfoGet } from './arcgis/arcgis.info.js';
import { arcgisStyleJsonGet } from './arcgis/arcgis.style.json.js';
import { arcgisTileServerGet } from './arcgis/vector.tile.server.js';
import { tileAttributionGet } from './routes/attribution.js';
import { configImageryGet, configTileSetGet } from './routes/config.js';
import { fontGet, fontList } from './routes/fonts.js';
import { healthGet } from './routes/health.js';
import { imageryGet } from './routes/imagery.js';
Expand Down Expand Up @@ -70,6 +71,10 @@ handler.router.get('/v1/version', versionGet);
// Image Metadata
handler.router.get('/v1/imagery/:imageryId/:fileName', imageryGet);

// Config
handler.router.get('/v1/config/:tileSet.json', configTileSetGet);
handler.router.get('/v1/config/:tileSet/:imageryId.json', configImageryGet);

// Sprites
handler.router.get('/v1/sprites/:spriteName', spriteGet);

Expand Down
83 changes: 83 additions & 0 deletions packages/lambda-tiler/src/routes/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { standardizeLayerName } from '@basemaps/config';
import { GoogleTms, TileMatrixSets } from '@basemaps/geo';
import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
import { ConfigLoader } from '../util/config.loader.js';
import { Etag } from '../util/etag.js';
import { NotFound, NotModified } from '../util/response.js';

async function sendJson(req: LambdaHttpRequest, toSend: unknown): Promise<LambdaHttpResponse> {
const data = Buffer.from(JSON.stringify(toSend));

const cacheKey = Etag.key(data);
if (Etag.isNotModified(req, cacheKey)) return NotModified();

const response = new LambdaHttpResponse(200, 'ok');
response.header(HttpHeader.ETag, cacheKey);
response.header(HttpHeader.CacheControl, 'no-store');
response.buffer(data, 'application/json');
req.set('bytes', data.byteLength);
return response;
}

interface ConfigTileSetGet {
Params: {
tileSet: string;
};
}

export async function configTileSetGet(req: LambdaHttpRequest<ConfigTileSetGet>): Promise<LambdaHttpResponse> {
const config = await ConfigLoader.load(req);

req.timer.start('tileset:load');
const tileSet = await config.TileSet.get(config.TileSet.id(req.params.tileSet));
req.timer.end('tileset:load');
if (tileSet == null) return NotFound();

return sendJson(req, tileSet);
}

interface ConfigImageryGet {
Params: {
tileSet: string;
imageryId: string;
};
}

/**
* Load the imagery configuration by either name or id
*
* @param req
* @returns
*/
export async function configImageryGet(req: LambdaHttpRequest<ConfigImageryGet>): Promise<LambdaHttpResponse> {
const config = await ConfigLoader.load(req);

req.timer.start('tileset:load');
const tileSet = await config.TileSet.get(config.TileSet.id(req.params.tileSet));
req.timer.end('tileset:load');
if (tileSet == null) return NotFound();

req.timer.start('imagery:load');
let imagery = await config.Imagery.get(config.Imagery.id(req.params.imageryId));
req.timer.end('imagery:load');

if (imagery == null) {
const imageryLayer = tileSet.layers.find(
(f) => f.name === req.params.imageryId || standardizeLayerName(f.name) === req.params.imageryId,
);
if (imageryLayer == null) return NotFound();

const tileMatrix = TileMatrixSets.find(req.query.get('tileMatrix') ?? GoogleTms.identifier);
if (tileMatrix == null) return NotFound();

const imageryId = imageryLayer[tileMatrix.projection.code];
if (imageryId == null) return NotFound();

req.timer.start('imagery:load:sub');
imagery = await config.Imagery.get(config.Imagery.id(imageryId));
req.timer.end('imagery:load:sub');
}

if (imagery == null) return NotFound();
return sendJson(req, imagery);
}
1 change: 1 addition & 0 deletions packages/landing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
],
"devDependencies": {
"@basemaps/attribution": "^6.32.1",
"@basemaps/config": "^6.34.0",
"@basemaps/geo": "^6.32.1",
"@basemaps/infra": "^6.34.0",
"@basemaps/shared": "^6.34.0",
Expand Down
Loading