Skip to content

Commit

Permalink
feat(cli): Add disabled flag for the create pr cli, and bug fixes. (#…
Browse files Browse the repository at this point in the history
…2745)

* Support disabled flag and replacing the layer for reprocessed imagery

* remove the check for zoom layer and always add new layers at bottom of category

* Add Event Category and add new rural above first urban

* Update the disabled flag description

* Some refinements

* Set default config

* Revert comment out code

* wip

* Update the default setting as record.

* Set default config after check existing layer.
  • Loading branch information
Wentao-Kuang authored Mar 30, 2023
1 parent 1b34d9a commit 714a113
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 30 deletions.
23 changes: 22 additions & 1 deletion packages/cli/src/cli/cogify/action.make.cog.pr.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import { ConfigLayer } from '@basemaps/config';
import { fsa, LogConfig } from '@basemaps/shared';
import { CommandLineAction, CommandLineStringParameter } from '@rushstack/ts-command-line';
import { CommandLineAction, CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack/ts-command-line';
import { owner, repo } from '../github/github.js';
import { MakeCogGithub } from '../github/make.cog.pr.js';

export enum Category {
Urban = 'Urban Aerial Photos',
Rural = 'Rural Aerial Photos',
Satellite = 'Satellite Imagery',
Event = 'Event',
Other = 'New Aerial Photos',
}

export interface CategorySetting {
minZoom?: number;
disabled?: boolean;
}

export const DefaultCategorySetting: Record<Category, CategorySetting> = {
[Category.Urban]: { minZoom: 14 },
[Category.Rural]: { minZoom: 13 },
[Category.Satellite]: { minZoom: 5 },
[Category.Event]: { disabled: true },
[Category.Other]: { disabled: true },
};

export function parseCategory(category: string): Category {
const c = category.toLocaleLowerCase();
if (c.includes('urban')) return Category.Urban;
Expand All @@ -24,6 +38,7 @@ export class CommandCogPullRequest extends CommandLineAction {
private output: CommandLineStringParameter;
private jira: CommandLineStringParameter;
private category: CommandLineStringParameter;
private disabled: CommandLineFlagParameter;

public constructor() {
super({
Expand Down Expand Up @@ -58,6 +73,11 @@ export class CommandCogPullRequest extends CommandLineAction {
description: 'New Imagery Category, like Rural Aerial Photos, Urban Aerial Photos, Satellite Imagery',
required: false,
});
this.disabled = this.defineFlagParameter({
parameterLongName: '--disabled',
description: 'Disable the layer in the config',
required: false,
});
}

async onExecute(): Promise<void> {
Expand All @@ -73,6 +93,7 @@ export class CommandCogPullRequest extends CommandLineAction {
}

const git = new MakeCogGithub(layer.name, logger);
if (this.disabled.value) layer.disabled = true;
const prNumber = await git.createTileSetPullRequest(layer, this.jira.value, category);

const output = this.output.value;
Expand Down
76 changes: 47 additions & 29 deletions packages/cli/src/cli/github/make.cog.pr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigLayer, ConfigTileSetRaster } from '@basemaps/config';
import { LogType } from '@basemaps/shared';
import { Category } from '../cogify/action.make.cog.pr.js';
import { Category, DefaultCategorySetting } from '../cogify/action.make.cog.pr.js';
import { Github, owner, repo } from './github.js';

export class MakeCogGithub extends Github {
Expand Down Expand Up @@ -60,6 +60,36 @@ export class MakeCogGithub extends Github {
return prNumber;
}

/**
* Set the default setting for the category
*/
setDefaultConfig(layer: ConfigLayer, category: Category): ConfigLayer {
layer.category = category;
const defaultSetting = DefaultCategorySetting[category];
if (defaultSetting) {
if (defaultSetting.minZoom != null && layer.minZoom != null) layer.minZoom = defaultSetting.minZoom;
if (defaultSetting.minZoom != null && layer.minZoom != null) layer.disabled = defaultSetting.disabled;
}

return layer;
}

/**
* Add new layer at the bottom of related category
*/
addLayer(layer: ConfigLayer, tileSet: ConfigTileSetRaster, category: Category): ConfigTileSetRaster {
this.setDefaultConfig(layer, category);
for (let i = tileSet.layers.length - 1; i >= 0; i--) {
// Add new layer at the end of category
if (tileSet.layers[i].category === category) {
// Find first valid category and insert new record above that.
tileSet.layers.splice(i + 1, 0, layer);
break;
}
}
return tileSet;
}

/**
* Prepare aerial tileSet config json
*/
Expand All @@ -68,44 +98,32 @@ export class MakeCogGithub extends Github {
tileSet: ConfigTileSetRaster,
category: Category,
): Promise<ConfigTileSetRaster | undefined> {
// Reprocess existing layer
for (let i = 0; i < tileSet.layers.length; i++) {
if (tileSet.layers[i].name === layer.name) {
tileSet.layers[i] = layer;
return tileSet;
}
}

// Set default Config if not existing layer
this.setDefaultConfig(layer, category);

// Set layer zoom level and add to latest order
if (category === Category.Rural) {
layer.minZoom = 13;
layer.category = Category.Rural;
for (let i = 0; i < tileSet.layers.length; i++) {
// Add new layer at the end of rural
if (tileSet.layers[i].category === Category.Rural && tileSet.layers[i].minZoom === 14) {
// Add new layer above the first Urban
if (tileSet.layers[i].category === Category.Urban) {
// Find first valid Urban and insert new record above that.
tileSet.layers.splice(i, 0, layer);
break;
}
}
} else if (category === Category.Urban) {
layer.minZoom = 14;
layer.category = Category.Urban;
// Add new layer at the end of urban
for (let i = tileSet.layers.length - 1; i >= 0; i--) {
if (tileSet.layers[i].category === Category.Urban && tileSet.minZoom === 14) {
// Find first Urban from the bottom up and insert the record below that.
tileSet.layers.splice(i + 1, 0, layer);
break;
}
}
} else if (category === Category.Satellite) {
layer.minZoom = 5;
layer.category = Category.Satellite;
// Add new layer at the end of satellite
for (let i = tileSet.layers.length - 1; i >= 0; i--) {
// Find first Satellite imagery from bottom up and insert the record below that.
if (tileSet.layers[i].category === Category.Satellite) {
tileSet.layers.splice(i + 1, 0, layer);
break;
}
}
} else {
} else if (category === Category.Other) {
// Add new layer at the bottom
layer.category = Category.Other;
tileSet.layers.push(layer);
} else {
this.addLayer(layer, tileSet, category);
}

return tileSet;
Expand Down

0 comments on commit 714a113

Please sign in to comment.