Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Jul 18, 2022
1 parent 83c0cd3 commit 04f52b0
Show file tree
Hide file tree
Showing 19 changed files with 444 additions and 370 deletions.
10 changes: 6 additions & 4 deletions packages/config/src/base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ export class ConfigInstance {
return s.type === TileSetType.Vector;
}

async getAllImagery(layers: ConfigLayer[], projection: Epsg): Promise<Map<string, ConfigImagery>> {
async getAllImagery(layers: ConfigLayer[], projections: Epsg[]): Promise<Map<string, ConfigImagery>> {
const imgIds = new Set<string>();
for (const layer of layers) {
const imgId = layer[projection.code];
if (imgId) imgIds.add(this.Imagery.id(imgId));
for (const projection of projections) {
for (const layer of layers) {
const imgId = layer[projection.code];
if (imgId) imgIds.add(this.Imagery.id(imgId));
}
}
return this.Imagery.getAll(imgIds);
}
Expand Down
22 changes: 22 additions & 0 deletions packages/config/src/config/tile.set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ export interface ConfigLayer extends Partial<Record<EpsgCode, string>> {
/** Layer name*/
name: string;

/** Human friendly display name for the layer */
title?: string;

/**
* Keywords used to categorize the tileset
* @example
* - Bathymetry
* - Satellite Imagery
*/
category?: string;

/** Minimal zoom to show the layer @default 0 */
minZoom?: number;

Expand All @@ -20,9 +31,19 @@ export interface ConfigLayer extends Partial<Record<EpsgCode, string>> {
export type TileResizeKernel = 'nearest' | 'lanczos3' | 'lanczos2';

export interface ConfigTileSetBase extends BaseConfig {
/** Human friendly display name for the tileset */
title?: string;

/** Human friendly description of the tileset */
description?: string;

/**
* Keywords used to categorize the tileset
* @example
* - Basemap
*/
category?: string;

/**
* The rendering layer for imagery in this tileset
*
Expand All @@ -33,6 +54,7 @@ export interface ConfigTileSetBase extends BaseConfig {

/** Minimum zoom level for this tileSet @default 0 */
minZoom?: number;

/** Maximum zoom level for this tileSet @default 30 */
maxZoom?: number;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ o.spec('ConfigProvider.Imagery', () => {

const layers = [{ [3857]: 'foo1' }, { [3857]: 'im_foo2' }, { [2193]: 'foo3', [3857]: 'im_foo4' }] as any;

const result = await Config.getAllImagery(layers, Epsg.Google);
const result = await Config.getAllImagery(layers, [Epsg.Google]);
o(get.callCount).equals(1);
o([...get.firstCall.firstArg.keys()]).deepEquals(['im_foo1', 'im_foo2', 'im_foo4']);
o(result.get('im_foo1')).deepEquals(item);
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export { ConfigProviderMemory, ConfigBundled } from './memory/memory.config.js';
export { TileSetNameComponents, TileSetNameParser } from './tile.set.name.js';
export { parseHex, parseRgba } from './color.js';
export { ConfigJson } from './json/json.config.js';
export { standardizeLayerName } from './json/name.convertor.js';
1 change: 1 addition & 0 deletions packages/config/src/json/json.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class ConfigJson {
}
if (ts.title) tileSet.title = ts.title;
if (ts.description) tileSet.description = ts.description;
if (ts.category) tileSet.category = ts.category;
if (ts.minZoom) tileSet.minZoom = ts.minZoom;
if (ts.maxZoom) tileSet.maxZoom = ts.maxZoom;
if (ts.background && tileSet.type === TileSetType.Raster) {
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/json/parse.tile.set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const zTileSetConfig = z.object({
type: z.nativeEnum(TileSetType),
id: z.string(),
title: z.string().optional(),
category: z.string().optional(),
description: z.string().optional(),
background: zBackground.optional(),
layers: z.array(zLayerConfig),
Expand Down
2 changes: 2 additions & 0 deletions packages/config/src/memory/memory.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export class ConfigProviderMemory extends BasemapsConfigProvider {
existing = {
type: TileSetType.Raster,
id: targetId,
title: i.title,
category: i.category,
name: targetName,
format: ImageFormat.Webp,
layers: [{ name: targetName, minZoom: 0, maxZoom: 32 }],
Expand Down
4 changes: 4 additions & 0 deletions packages/config/src/tile.set.name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @example
* `name:layer`
* `aerial:tasman_rural_2018-19_0-3m`
*
* @deprecated use direct tileset names `tasman-rural-2018-2019-0.3m`
*/
export interface TileSetNameComponents {
name: string;
Expand All @@ -20,6 +22,8 @@ export const TileSetNameParser = {
* aerial@head:tasman_rural_2018-19_0-3m => {name: aerial, tag: head, layer: tasman_rural_2018-19_0-3m}
*
* @param name String to parse
*
* @deprecated use direct tileset names `tasman-rural-2018-2019-0.3m`
*/
parse(name: string): TileSetNameComponents {
const output: TileSetNameComponents = { name };
Expand Down
68 changes: 1 addition & 67 deletions packages/lambda-tiler/src/__tests__/tile.set.cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ConfigImagery, ConfigTileSetRaster, TileSetType } from '@basemaps/config';
import { Epsg, GoogleTms, Nztm2000QuadTms } from '@basemaps/geo';
import { Config, TileSetName } from '@basemaps/shared';
import { GoogleTms } from '@basemaps/geo';
import o from 'ospec';
import sinon from 'sinon';
import { TileSets } from '../tile.set.cache.js';
Expand All @@ -15,14 +14,6 @@ o.spec('TileSetCache', () => {
uri: 's3://foo/bar',
} as ConfigImagery;

const imageTwo = {
id: 'im_id2',
name: 'wellington_urban_2018-19_0-3m',
bounds: { x: 123, y: 456, width: 200, height: 300 },
files: [{ name: 'foo', x: 123, y: 456, width: 200, height: 300 }],
uri: 's3://foo/bar',
} as ConfigImagery;

const imgMap = new Map<string, ConfigImagery>();
imgMap.set(imageOne.id, imageOne);

Expand Down Expand Up @@ -86,61 +77,4 @@ o.spec('TileSetCache', () => {
o(subTileSet).equals(null);
});
});

o.spec('loadTileSets', () => {
o('load all', async () => {
sandbox.stub(Config.TileSet, 'get');

TileSets.add(new TileSetRaster('aerial', GoogleTms));
TileSets.add(new TileSetRaster('aerial', Nztm2000QuadTms));
const tileSets = await TileSets.getAll('aerial', null);

o(tileSets.length).deepEquals(2);

o(tileSets[0].fullName).equals(TileSetName.aerial);
o(tileSets[0].components.name).equals(TileSetName.aerial);
o(tileSets[0].tileMatrix.projection.code).equals(3857);

o(tileSets[1].fullName).equals(TileSetName.aerial);
o(tileSets[1].components.name).equals(TileSetName.aerial);
o(tileSets[1].tileMatrix.projection.code).equals(2193);
});

o('load all subset projections', async () => {
sandbox.stub(Config.TileSet, 'get');

const ts1 = new TileSetRaster('aerial@head', Nztm2000QuadTms);
ts1.imagery = imgMap;
TileSets.add(ts1);
const ts2 = new TileSetRaster('aerial@head', GoogleTms);
ts2.imagery = imgMap;
TileSets.add(ts2);
const tileSets = await TileSets.getAll('aerial@head:tasman_rural_2018-19_0-3m', null);

o(tileSets.length).deepEquals(2);

o(tileSets[0].fullName).equals('aerial@head:tasman_rural_2018-19_0-3m');
o(tileSets[0].tileMatrix.projection).equals(Epsg.Google);
o(tileSets[1].fullName).equals('aerial@head:tasman_rural_2018-19_0-3m');
o(tileSets[1].tileMatrix.projection).equals(Epsg.Nztm2000);
});

o('load all @tag', async () => {
sandbox.stub(Config.TileSet, 'get');
const imgMap = new Map();
imgMap.set(imageOne.id, imageOne);
imgMap.set(imageTwo.id, imageTwo);
const ts1 = new TileSetRaster('aerial@head', Nztm2000QuadTms);
ts1.imagery = imgMap;
TileSets.add(ts1);

const tileSets = await TileSets.getAll('aerial@head', null);

o(tileSets.length).deepEquals(3);

o(tileSets[0].fullName).equals('aerial@head');
o(tileSets[1].fullName).equals('aerial@head:tasman_rural_2018-19_0-3m');
o(tileSets[2].fullName).equals('aerial@head:wellington_urban_2018-19_0-3m');
});
});
});
Loading

0 comments on commit 04f52b0

Please sign in to comment.