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

fix(lambda-tiler): correctly build WMTS for child tile sets #1607

Merged
merged 1 commit into from
May 13, 2021
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
7 changes: 7 additions & 0 deletions packages/lambda-tiler/src/__test__/tile.set.cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ o.spec('TileSetCache', () => {
if (parentTileSet == null || parentTileSet.isVector()) throw new Error('null parentTileSet');
parentTileSet.imagery = imgMap;
parentTileSet.tileSet = {
name: 'parent',
title: 'parent aerial title',
background: { r: 200, g: 50, b: 100, alpha: 0.5 },
} as ConfigTileSetRaster;
Expand Down Expand Up @@ -76,6 +77,12 @@ o.spec('TileSetCache', () => {
const aTiff = subTileSet.getTiffsForTile({ x: 0, y: 0, z: 0 });
o(aTiff.length).equals(1);
o(aTiff[0].source.uri).equals('s3://foo/bar/foo.tiff');

TileSets.cache.delete(subTileSet.id);
delete parentTileSet.tileSet.title;
const subTileSetB = await TileSets.get('aerial@head:tasman_rural_2018-19_0-3m', GoogleTms);
if (subTileSetB == null || subTileSetB.isVector()) throw new Error('null subTileSetB');
o(subTileSetB.title).equals('parent Tasman rural 2018-19 0.3m');
});
});

Expand Down
27 changes: 27 additions & 0 deletions packages/lambda-tiler/src/__test__/wmts.capability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,33 @@ o.spec('WmtsCapabilities', () => {
o(layers[1].find('TileMatrixSet')?.textContent).equals('EPSG:2193');
});

o('should support child tile sets', () => {
const ts = [
new FakeTileSet(
`${TileSetName.aerial}:wairoa_urban_2014-2015_0-10m_RGBA`,
Nztm2000Tms,
'wairoa_urban_2014-2015_0-10m_RGBA',
),
new FakeTileSet(
`${TileSetName.aerial}:west-coast_rural_2016-17_0-3m`,
Nztm2000Tms,
'west-coast_rural_2016-17_0-3m',
),
];
const nodes = new WmtsCapabilities('basemaps.test', Provider, ts).toVNode();
const layers = tags(nodes, 'Layer');

o(layers.length).equals(2);

const boundingBoxes = tags(layers[0], 'ows:BoundingBox');
o(boundingBoxes.length).equals(1);

const firstTitle = layers[0].children[0].textContent;
o(firstTitle).equals('wairoa_urban_2014-2015_0-10m_RGBA');
const secondTitle = layers[1].children[0].textContent;
o(secondTitle).equals('west-coast_rural_2016-17_0-3m');
});

o('should support multiple different projections on different tiles sets', () => {
const ts = [
new FakeTileSet(TileSetName.aerial, Nztm2000Tms, TileSetName.aerial),
Expand Down
5 changes: 5 additions & 0 deletions packages/lambda-tiler/src/routes/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export async function tile(req: LambdaContext): Promise<LambdaHttpResponse> {
}

async function wmtsLoadTileSets(name: string, tileMatrix: TileMatrixSet | null): Promise<TileSetRaster[]> {
if (tileMatrix != null) {
const ts = await TileSets.get(name, tileMatrix);
if (ts == null || ts.isVector()) return [];
return [ts];
}
if (name === '') name = TileSetName.aerial;
return (await TileSets.getAll(name, tileMatrix)).filter((f) => f.type === 'raster') as TileSetRaster[];
}
Expand Down
3 changes: 2 additions & 1 deletion packages/lambda-tiler/src/tile.set.raster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ export class TileSetRaster extends TileSetHandler<ConfigTileSetRaster> {
// use parent data as prototype for child;
child.tileSet = { ...this.tileSet };
child.tileSet.background = undefined;
child.tileSet.title = `${this.tileSet?.title} ${titleizeImageryName(image.name)}`;
const title = this.tileSet?.title ?? this.tileSet?.name;
child.tileSet.title = `${title} ${titleizeImageryName(image.name)}`;
child.extentOverride = Bounds.fromJson(image.bounds);

const layer: ConfigLayer = { name: image.name, minZoom: 0, maxZoom: 100 };
Expand Down
4 changes: 2 additions & 2 deletions packages/lambda-tiler/src/wmts.capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export class WmtsCapabilities {

for (const layer of layers) {
// TODO is grouping by name the best option
let existing = this.layers.get(layer.components.name);
let existing = this.layers.get(layer.fullName);
if (existing == null) {
existing = [];
this.layers.set(layer.components.name, existing);
this.layers.set(layer.fullName, existing);
}
// TODO should a error be thrown here if the projection is invalid
existing.push(layer);
Expand Down