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
Changes from 1 commit
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
39 changes: 23 additions & 16 deletions packages/config/src/memory/memory.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface ConfigBundled {
style: ConfigVectorStyle[];
provider: ConfigProvider[];
tileSet: ConfigTileSet[];
duplicateImagery: ConfigTileSet[];
}

function isConfigImagery(i: BaseConfig): i is ConfigImagery {
Expand All @@ -31,6 +32,21 @@ function isConfigTileSet(i: BaseConfig): i is ConfigTileSet {
return ConfigId.getPrefix(i.id) === ConfigPrefix.TileSet;
}

/** Get the last id from the s3 path and compare to get the latest id based on the timestamp */
function findLatestId(idA: string, idB: string): string {
const ulidA = ConfigId.unprefix(ConfigPrefix.Imagery, idA);
const ulidB = ConfigId.unprefix(ConfigPrefix.Imagery, idB);
try {
const timeA = decodeTime(ulidA);
const timeB = decodeTime(ulidB);
if (timeA >= timeB) return idA;
else return idB;
} finally {
//If not ulid return the return id alphabetically.
return idA.localeCompare(idB) ? idA : idB;
blacha marked this conversation as resolved.
Show resolved Hide resolved
}
}

/** Force a unknown object into a Record<string, unknown> type */
export function isObject(obj: unknown): obj is Record<string, unknown> {
if (typeof obj !== 'object') return false;
Expand Down Expand Up @@ -61,6 +77,9 @@ export class ConfigProviderMemory extends BasemapsConfigProvider {
/** Asset path from the config bundle */
assets: string;

/** Catch configs with the same imagery that using the different imagery ids. */
duplicateImagery: ConfigTileSet[];

put(obj: BaseConfig): void {
this.objects.set(obj.id, obj);
}
Expand All @@ -74,6 +93,7 @@ export class ConfigProviderMemory extends BasemapsConfigProvider {
style: [],
provider: [],
tileSet: [],
duplicateImagery: this.duplicateImagery,
};

for (const val of this.objects.values()) {
Expand Down Expand Up @@ -123,21 +143,6 @@ export class ConfigProviderMemory extends BasemapsConfigProvider {
if (allLayers.length) this.createVirtualAllTileSet(allLayers);
}

/** Get the last id from the s3 path and compare to get the latest id based on the timestamp */
findLatestId(idA: string, idB: string): string {
const ulidA = ConfigId.unprefix(ConfigPrefix.Imagery, idA);
const ulidB = ConfigId.unprefix(ConfigPrefix.Imagery, idB);
try {
const timeA = decodeTime(ulidA);
const timeB = decodeTime(ulidB);
if (timeA >= timeB) return idA;
else return idB;
} finally {
//If not ulid return the idB
return idB;
}
}

createVirtualAllTileSet(layers: ConfigLayer[]): void {
const layerByName = new Map<string, ConfigLayer>();
// Set all layers as minZoom:32
Expand Down Expand Up @@ -176,11 +181,13 @@ export class ConfigProviderMemory extends BasemapsConfigProvider {
} as ConfigTileSet;
removeUndefined(existing);
this.put(existing);
} else {
this.duplicateImagery.push(existing);
Wentao-Kuang marked this conversation as resolved.
Show resolved Hide resolved
}
// The latest imagery overwrite the earlier ones.
const existingImageryId = existing.layers[0][i.projection];
if (existingImageryId) {
existing.layers[0][i.projection] = this.findLatestId(existingImageryId, i.id);
existing.layers[0][i.projection] = findLatestId(existingImageryId, i.id);
} else {
existing.layers[0][i.projection] = i.id;
}
Expand Down
Loading