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(cli): include urlPreview for preview links #2938

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
40 changes: 24 additions & 16 deletions packages/cli/src/cli/config/action.imagery.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class CommandImageryConfig extends CommandLineAction {
files.push({ name: tif.source.uri.replace(path, ''), ...imgBounds });
}
if (bounds == null) throw new Error('Failed to extract imagery bounds');
if (gsd == null) throw new Error('Failed to get imagery GSD');

const provider = new ConfigProviderMemory();
const id = ulid();
Expand All @@ -94,7 +95,7 @@ export class CommandImageryConfig extends CommandLineAction {
logger.warn({ path, id }, `Unable to extract the imagery name from path, use uild id instead.`);
name = id;
}
const imagery: ConfigImagery = {
const im: ConfigImagery = {
id: provider.Imagery.id(id),
name: nameImageryTitle(title),
title,
Expand All @@ -105,9 +106,9 @@ export class CommandImageryConfig extends CommandLineAction {
bounds: bounds.toJson(),
files,
};
imagery.overviews = await ConfigJson.findImageryOverviews(imagery);
im.overviews = await ConfigJson.findImageryOverviews(im);

provider.put(imagery);
provider.put(im);

const aerialTileSet: ConfigTileSetRaster = {
id: 'ts_aerial',
Expand All @@ -116,30 +117,37 @@ export class CommandImageryConfig extends CommandLineAction {
category: 'Basemaps',
type: TileSetType.Raster,
format: ImageFormat.Webp,
layers: [{ 2193: imagery.id, name: imagery.name, title: imagery.title }],
layers: [{ 2193: im.id, name: im.name, title: im.title }],
};
provider.put(aerialTileSet);
const tileSet = provider.imageryToTileSetByName(imagery);
provider.imageryToTileSetByName(im);

// Prepare the center location
let location = '';
if (bounds && gsd) {
const center = { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 };
const proj = Projection.get(Nztm2000QuadTms);
const centerLatLon = proj.toWgs84([center.x, center.y]).map((c) => c.toFixed(6));
const targetZoom = Math.max(Nztm2000QuadTms.findBestZoom(gsd) - 12, 0);
location = `#@${centerLatLon[1]},${centerLatLon[0]},z${targetZoom}`;
}
const center = { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 };
const proj = Projection.get(Nztm2000QuadTms);
const [lon, lat] = proj.toWgs84([center.x, center.y]).map((c) => c.toFixed(6));
const targetZoom = Math.max(Nztm2000QuadTms.findBestZoom(gsd) - 12, 0);
const locationHash = `@${lat},${lon},z${targetZoom}`;

if (commit) {
logger.info({ path }, 'ImageryConfig:UploadConfig');
const configJson = provider.toJson();
const outputPath = fsa.join(path, `basemaps-config-${configJson.hash}.json.gz`);
await fsa.writeJson(outputPath, configJson);
const configPath = base58.encode(Buffer.from(outputPath));
const url = `https://basemaps.linz.govt.nz/?config=${configPath}&i=${tileSet.name}&tileMatrix=NZTM2000Quad&debug${location}`;

const url = `https://basemaps.linz.govt.nz/${locationHash}?i=${im.name}&tileMatrix=${im.tileMatrix}&debug&config=${configPath}`;
const urlPreview = `https://basemaps.linz.govt.nz/v1/preview/${im.name}/${im.tileMatrix}/${targetZoom}/${lon}/${lat}?config=${configPath}`;

logger.info(
{ imageryId: id, path: output, url, tileMatrix: Nztm2000QuadTms.identifier, config: configPath, title },
{
imageryId: id,
path: output,
url,
urlPreview,
tileMatrix: Nztm2000QuadTms.identifier,
config: configPath,
title,
},
'ImageryConfig:Done',
);
if (output != null) await fsa.write(output, url);
Expand Down
10 changes: 6 additions & 4 deletions packages/cogify/src/cogify/cli/cli.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ export const BasemapsCogifyConfigCommand = command({

const configPath = base58.encode(Buffer.from(outputPath));
const location = getImageryCenterZoom(im);
const targetZoom = location.zoom;
const lat = location.lat.toFixed(7);
const lon = location.lon.toFixed(7);
const locationHash = `#@${lat},${lon},z${location.zoom}`;
const url = `https://basemaps.linz.govt.nz/?config=${configPath}&i=${im.name}&tileMatrix=${im.tileMatrix}&debug${locationHash}`;
const preview = `https://basemaps.linz.govt.nz/v1/preview/${im.name}/${im.tileMatrix}/${location.zoom}/${lon}/${lat}.webp?config=${configPath}`;
const locationHash = `@${lat},${lon},z${location.zoom}`;

const url = `https://basemaps.linz.govt.nz/${locationHash}?i=${im.name}&tileMatrix=${im.tileMatrix}&debug&config=${configPath}`;
const urlPreview = `https://basemaps.linz.govt.nz/v1/preview/${im.name}/${im.tileMatrix}/${targetZoom}/${lon}/${lat}?config=${configPath}`;

logger.info(
{
imageryId: im.id,
path: outputPath,
url,
urlPreview: preview,
urlPreview,
config: configPath,
title: im.title,
tileMatrix: im.tileMatrix,
Expand Down
Loading