Skip to content

Commit

Permalink
fix(lambda-tiler): missing tilesets should 404 not 500 (#2149)
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha authored Apr 10, 2022
1 parent 034afcc commit a3420bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
11 changes: 11 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 @@ -74,6 +74,17 @@ o.spec('TileSetCache', () => {
if (subTileSetB == null || subTileSetB.type === TileSetType.Vector) throw new Error('null subTileSetB');
o(subTileSetB.title).equals('parent Tasman rural 2018-19 0.3m');
});

o('should not throw if child does not exist', async () => {
TileSets.add(new TileSetRaster('aerial@head', GoogleTms));

const parentTileSet = await TileSets.get('aerial@head', GoogleTms);
if (parentTileSet == null || parentTileSet.type === TileSetType.Vector) throw new Error('null parentTileSet');
parentTileSet.imagery = imgMap;

const subTileSet = await TileSets.get('aerial@head:fake', GoogleTms);
o(subTileSet).equals(null);
});
});

o.spec('loadTileSets', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/lambda-tiler/src/tile.set.cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export class TileSetCache {
if (nameComp.layer != null) {
parent.components.name = nameComp.name;
} else if (parent.imagery != null && parent.imagery.size > 1) {
for (const imageId of parent.imagery.keys()) tileSets.push(parent.child(imageId));
for (const imageId of parent.imagery.keys()) {
const childImg = parent.child(imageId);
if (childImg == null) continue;
tileSets.push(childImg);
}
}
}
return tileSets.sort((a, b) => a.title.localeCompare(b.title));
Expand Down
6 changes: 2 additions & 4 deletions packages/lambda-tiler/src/tile.set.raster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,9 @@ export class TileSetRaster {
return null;
}

child(imgId: string): TileSetRaster {
child(imgId: string): TileSetRaster | null {
const image = this.findImagery(imgId);
if (image == null) {
throw new Error('Failed to create child tile set ' + this.fullName + ' Missing imagery ' + imgId);
}
if (image == null) return null;
const childName = TileSetNameParser.componentsToName({ ...this.components, layer: image.name });
const child = new TileSetRaster(childName, this.tileMatrix);
// use parent data as prototype for child;
Expand Down

0 comments on commit a3420bc

Please sign in to comment.