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(config): Create an all tileset from imagery configs. BM-805 #2794

Merged
merged 16 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 13 additions & 3 deletions packages/config/src/memory/__tests__/memory.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ o.spec('MemoryConfig', () => {
config.createVirtualTileSets();

const cfg = config.toJson();
o(cfg.tileSet.length).equals(2);
o(cfg.tileSet.length).equals(3);
o(cfg.tileSet[0].id).equals('ts_Image123');
o(cfg.tileSet[1].id).equals('ts_ōtorohanga-urban-2021-0.1m');
o(cfg.tileSet[2].id).equals('ts_all');
const allTileSet = cfg.tileSet[2];
o(allTileSet.layers.length).equals(1);
o(allTileSet.layers[0].name).equals('ōtorohanga-urban-2021-0.1m');
});

o('should create virtual tilesets by name', async () => {
Expand Down Expand Up @@ -94,10 +98,16 @@ o.spec('MemoryConfig', () => {
const cfg = config.toJson();
// 1 tileset per imagery id (2x)
// 1 tileset per imagery name (1x)
o(cfg.tileSet.length).equals(3);
o(cfg.tileSet.length).equals(4);
o(cfg.tileSet[0].id).equals('ts_Image123');
o(cfg.tileSet[1].id).equals('ts_ōtorohanga-urban-2021-0.1m');
o(cfg.tileSet[2].id).equals('ts_Image234');
o(cfg.tileSet[3].id).equals('ts_all');
o(cfg.tileSet[3].layers.length).equals(1);
o(cfg.tileSet[3].layers[0][2193]).equals('im_Image234');
o(cfg.tileSet[3].layers[0][3857]).equals('im_Image123');
o(cfg.tileSet[3].layers[0].maxZoom).equals(undefined);
o(cfg.tileSet[3].layers[0].minZoom).equals(32);
});

o('virtual tilesets should overwrite existing projections', async () => {
Expand Down Expand Up @@ -135,7 +145,6 @@ o.spec('MemoryConfig', () => {
config.put({ ...baseImg, id: 'im_image-3857', projection: 3857 } as ConfigImagery);

o(config.toJson().tileSet.length).equals(1);

config.createVirtualTileSets();

const tileSets = config.toJson().tileSet.map((c) => c.id);
Expand All @@ -146,6 +155,7 @@ o.spec('MemoryConfig', () => {
'ts_image-2193', // By image id
'ts_ōtorohanga-urban-2021-0.1m', // By name
'ts_image-3857', // By image id
'ts_all',
]);

const target = await config.TileSet.get('ts_aerial:ōtorohanga_urban_2021_0-1m_RGB');
Expand Down
28 changes: 27 additions & 1 deletion packages/config/src/memory/memory.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class ConfigProviderMemory extends BasemapsConfigProvider {

/** Find all imagery inside this configuration and create a virtual tile set for it */
createVirtualTileSets(): void {
const allLayers: ConfigLayer[] = [];
blacha marked this conversation as resolved.
Show resolved Hide resolved
for (const obj of this.objects.values()) {
// Limit child tileset generation to `aerial` layers only
if (isConfigTileSet(obj) && obj.name === 'aerial') {
Expand All @@ -115,9 +116,34 @@ export class ConfigProviderMemory extends BasemapsConfigProvider {
} else if (isConfigImagery(obj)) {
// TODO should this really overwrite existing tilesets
this.put(ConfigProviderMemory.imageryToTileSet(obj));
this.imageryToTileSetByName(obj);
const tileSet = this.imageryToTileSetByName(obj);
allLayers.push(tileSet.layers[0]);
}
}
// Create an all tileset contains all raster layers
if (allLayers.length) this.createVirtualAllTileSet(allLayers);
}

createVirtualAllTileSet(layers: ConfigLayer[]): void {
const layerByName = new Map<string, ConfigLayer>();
// Set all layers as minZoom:32
for (const l of layers) {
const newLayer = { ...l, maxZoom: undefined, minZoom: 32 };
// TODO: This might overwrite the layer id for duplicated configImagery
if (layerByName.has(newLayer.name))
blacha marked this conversation as resolved.
Show resolved Hide resolved
layerByName.set(newLayer.name, { ...layerByName.get(newLayer.name), ...newLayer });
else layerByName.set(newLayer.name, newLayer);
}
const allTileset: ConfigTileSet = {
type: TileSetType.Raster,
id: 'ts_all',
name: 'all_imagery',
title: 'All Imagery Basemaps',
category: 'Basemaps',
format: ImageFormat.Webp,
layers: Array.from(layerByName.values()),
};
this.put(allTileset);
}

/** Create a tileset by the standardized name */
Expand Down