From f1c5cadf4c2f3f0b0b576a75246423ee2292a1bf Mon Sep 17 00:00:00 2001 From: Jin Igarashi Date: Thu, 3 Oct 2024 11:36:30 +0100 Subject: [PATCH] fix: Fixed #4191 to return normal metadata without algorithm. (#4198) * fix: Fixed #4191 to return normal metadata without algorithm. * refactor: deleted console.log --- .changeset/green-spoons-add.md | 5 +++++ .../src/components/util/stac/StacApiExplorer.svelte | 3 +++ sites/geohub/src/lib/RasterTileData.ts | 3 +++ .../src/lib/server/helpers/createDatasetLinks.ts | 10 ++++++++-- .../api/datasets/style/[layer]/[type]/+server.ts | 10 ++++++++++ 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 .changeset/green-spoons-add.md diff --git a/.changeset/green-spoons-add.md b/.changeset/green-spoons-add.md new file mode 100644 index 000000000..f4ba109b0 --- /dev/null +++ b/.changeset/green-spoons-add.md @@ -0,0 +1,5 @@ +--- +"geohub": patch +--- + +fix: when there are multiple algorithms are linked to raster dataset such as Rwanda DEM, geohub fetched metadata for the first algorithm even if user does not select an algorithm to add. Fixed the bug for this to return normal metadata without algorithm. diff --git a/sites/geohub/src/components/util/stac/StacApiExplorer.svelte b/sites/geohub/src/components/util/stac/StacApiExplorer.svelte index 4af7c317c..f8b9cc871 100644 --- a/sites/geohub/src/components/util/stac/StacApiExplorer.svelte +++ b/sites/geohub/src/components/util/stac/StacApiExplorer.svelte @@ -1101,6 +1101,9 @@ width: 300px; background-color: rgba(255, 255, 255, 1); z-index: 999; + + max-height: 90%; + overflow-y: auto; } } } diff --git a/sites/geohub/src/lib/RasterTileData.ts b/sites/geohub/src/lib/RasterTileData.ts index 338b5f2db..90d33a9ed 100644 --- a/sites/geohub/src/lib/RasterTileData.ts +++ b/sites/geohub/src/lib/RasterTileData.ts @@ -13,6 +13,8 @@ export class RasterTileData { private feature: DatasetFeature; constructor(feature: DatasetFeature) { + // delete all algorithm tags. set algorithm Id at getMetadata or add functions instead. + feature.properties.tags = feature.properties.tags?.filter((t) => t.key !== 'algorithm'); this.feature = feature; } @@ -130,6 +132,7 @@ export class RasterTileData { if (!savedLayerStyle?.style) { const data = new FormData(); + console.log(this.feature); data.append('feature', JSON.stringify(this.feature)); const params: { [key: string]: string } = {}; if (colormap_name) { diff --git a/sites/geohub/src/lib/server/helpers/createDatasetLinks.ts b/sites/geohub/src/lib/server/helpers/createDatasetLinks.ts index b5630e2cc..f8c8a6d68 100644 --- a/sites/geohub/src/lib/server/helpers/createDatasetLinks.ts +++ b/sites/geohub/src/lib/server/helpers/createDatasetLinks.ts @@ -7,10 +7,9 @@ export const createDatasetLinks = async ( origin: string, titilerUrl: string ) => { - const tags: Tag[] = feature.properties.tags; + const tags: Tag[] | undefined = feature.properties.tags; const type = tags?.find((tag) => tag.key === 'type'); - const algorithmId = tags?.find((tag) => tag.key === 'algorithm')?.value; feature.properties.links = [ { rel: 'self', @@ -60,10 +59,13 @@ export const createDatasetLinks = async ( } else if (type?.value === 'stac') { const stacType = tags?.find((tag) => tag.key === 'stacType')?.value; const product = tags?.find((t) => t.key === 'product')?.value; + if (stacType === 'cog') { // remove dataset link from stac items feature.properties.links = feature.properties.links.filter((l) => l.rel !== 'dataset'); + const algorithmId = tags?.find((tag) => tag.key === 'algorithm')?.value; + const b64EncodedUrl = getBase64EncodedUrl(feature.properties.url); if (product) { const expression = tags.find((t) => t.key === 'product_expression').value; @@ -210,6 +212,10 @@ export const createDatasetLinks = async ( }); if (is_raster) { + const algorithmTags = tags?.filter((tag) => tag.key === 'algorithm'); + const algorithmId = + algorithmTags && algorithmTags.length === 1 ? algorithmTags[0].value : undefined; + const b64EncodedUrl = getBase64EncodedUrl(feature.properties.url); feature.properties.links.push({ rel: 'cog', diff --git a/sites/geohub/src/routes/api/datasets/style/[layer]/[type]/+server.ts b/sites/geohub/src/routes/api/datasets/style/[layer]/[type]/+server.ts index ce56ff735..42bae9502 100644 --- a/sites/geohub/src/routes/api/datasets/style/[layer]/[type]/+server.ts +++ b/sites/geohub/src/routes/api/datasets/style/[layer]/[type]/+server.ts @@ -6,6 +6,7 @@ import RasterDefaultStyle from '$lib/server/defaultStyle/RasterDefaultStyle'; import type { UserConfig } from '$lib/config/DefaultUserConfig'; import { env } from '$env/dynamic/private'; import VectorDefaultStyle from '$lib/server/defaultStyle/VectorDefaultStyle'; +import { ALGORITHM_TAG_KEY } from '$components/maplibre/raster/RasterAlgorithmExplorer.svelte'; const LAYER_TYPES = ['raster', 'fill', 'symbol', 'line', 'circle', 'heatmap']; @@ -25,6 +26,15 @@ export const POST: RequestHandler = async ({ request, params, url, fetch }) => { const featureString = body.get('feature') as string; const dataset: DatasetFeature = JSON.parse(featureString); + // set also algorithm to tags, and remove all default algorithm tags associated. + if (algorithm) { + if (!dataset.properties.tags) { + dataset.properties.tags = []; + } + dataset.properties.tags = dataset.properties.tags.filter((t) => t.key !== ALGORITHM_TAG_KEY); + dataset.properties.tags.push({ key: ALGORITHM_TAG_KEY, value: algorithm }); + } + dataset.properties = await createDatasetLinks(dataset, url.origin, env.TITILER_ENDPOINT); const response = await fetch('/api/settings'); const config: UserConfig = await response.json();