diff --git a/packages/lambda-tiler/src/routes/__tests__/wmts.test.ts b/packages/lambda-tiler/src/routes/__tests__/wmts.test.ts index 8376a9da3..ae2b510b5 100644 --- a/packages/lambda-tiler/src/routes/__tests__/wmts.test.ts +++ b/packages/lambda-tiler/src/routes/__tests__/wmts.test.ts @@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, it } from 'node:test'; import { ConfigProviderMemory, ConfigTileSetRaster } from '@basemaps/config'; import { Env } from '@basemaps/shared'; -import { Imagery2193, Imagery3857, Provider, TileSetAerial } from '../../__tests__/config.data.js'; +import { Imagery2193, Imagery3857, Provider, TileSetAerial, TileSetElevation } from '../../__tests__/config.data.js'; import { Api, mockUrlRequest } from '../../__tests__/xyz.util.js'; import { handler } from '../../index.js'; import { ConfigLoader } from '../../util/config.loader.js'; @@ -27,6 +27,28 @@ describe('WMTSRouting', () => { config.objects.clear(); }); + it('should support pipeline', async (t) => { + t.mock.method(Env, 'get', (arg: string) => { + if (arg === Env.PublicUrlBase) return 'https://tiles.test'; + return process.env[arg]; + }); + config.put(TileSetElevation); + t.mock.method(ConfigLoader, 'load', () => Promise.resolve(config)); + const req = mockUrlRequest( + '/v1/tiles/elevation/WebMercatorQuad/WMTSCapabilities.xml', + `tileFormat=png&api=${Api.key}&config=s3://linz-basemaps/config.json&pipeline=terrain-rgb`, + ); + const res = await handler.router.handle(req); + + assert.equal(res.status, 200); + const lines = Buffer.from(res.body, 'base64').toString().split('\n'); + const resourceUrl = lines.find((f) => f.includes('ResourceURL'))?.trim(); + + assert.ok(resourceUrl); + assert.ok(resourceUrl.includes('amp;pipeline=terrain-rgb'), `includes pipeline=terrain-rgb in ${resourceUrl}`); + assert.ok(resourceUrl.includes('.png'), `includes .png in ${resourceUrl}`); + }); + it('should default to the aerial layer', async (t) => { t.mock.method(Env, 'get', (arg: string) => { if (arg === Env.PublicUrlBase) return 'https://tiles.test'; diff --git a/packages/lambda-tiler/src/routes/tile.wmts.ts b/packages/lambda-tiler/src/routes/tile.wmts.ts index 5a3d99e53..7730c0476 100644 --- a/packages/lambda-tiler/src/routes/tile.wmts.ts +++ b/packages/lambda-tiler/src/routes/tile.wmts.ts @@ -69,6 +69,7 @@ export async function wmtsCapabilitiesGet(req: LambdaHttpRequest; + /** Default pipeline to use */ + pipeline?: string; } export class WmtsBuilder { httpBase: string; apiKey?: string; config?: string | null; + pipeline?: string; filters?: Record; /** All the imagery used by the tileSet and tileMatrixes */ @@ -58,7 +59,7 @@ export class WmtsBuilder { this.httpBase = params.httpBase; this.apiKey = params.apiKey; this.config = params.config; - this.filters = params.filters; + this.pipeline = params.pipeline; } addImagery(...imagery: ConfigImagery[]): void { @@ -153,17 +154,17 @@ export class WmtsBuilder { return V('Style', { isDefault: 'true' }, [V('ows:Title', 'Default Style'), V('ows:Identifier', 'default')]); } - buildResourceUrl(tileSetId: string, suffix: string, addFilter = false): VNodeElement { + buildResourceUrl(tileSetId: string, suffix: string): VNodeElement { return V('ResourceURL', { format: 'image/' + suffix, resourceType: 'tile', - template: this.buildTileUrl(tileSetId, suffix, addFilter), + template: this.buildTileUrl(tileSetId, suffix), }); } - buildTileUrl(tileSetId: string, suffix: string, addFilter = false): string { - let query = { api: this.apiKey, config: this.config }; - if (addFilter) query = { api: this.apiKey, config: this.config, ...this.filters }; + buildTileUrl(tileSetId: string, suffix: string): string { + // TODO this should restrict the output formats to supported formats in pipelines + const query = { api: this.apiKey, config: this.config, pipeline: this.pipeline }; return [ this.httpBase, @@ -239,6 +240,8 @@ export interface WmtsCapabilitiesParams { formats: ImageFormat[]; /** Specific layers to add to the WMTS */ layers?: ConfigLayer[]; + /** Default output pipeline to use */ + pipeline?: string | null; } /** @@ -277,6 +280,10 @@ export class WmtsCapabilities extends WmtsBuilder { this.provider = provider; } + addPipeline(pipeline: string): void { + this.pipeline = pipeline; + } + toProviderVNode(provider?: WmtsProvider): VNodeElement[] | [] { if (provider == null) return []; const { serviceIdentification, serviceProvider } = provider; @@ -338,7 +345,7 @@ export class WmtsCapabilities extends WmtsBuilder { this.buildStyle(), ...this.buildFormats(), ...this.buildTileMatrixLink(tileSet), - ...this.getFormats().map((fmt) => this.buildResourceUrl(layerNameId, fmt, true)), + ...this.getFormats().map((fmt) => this.buildResourceUrl(layerNameId, fmt)), ]); } @@ -408,5 +415,6 @@ export class WmtsCapabilities extends WmtsBuilder { this.addTileSet(params.tileSet); this.addLayers(params.layers); this.addProvider(params.provider); + if (params.pipeline) this.addPipeline(params.pipeline); } }