Skip to content

Commit

Permalink
fix: Fixed #4191 to return normal metadata without algorithm. (#4198)
Browse files Browse the repository at this point in the history
* fix: Fixed #4191 to return normal metadata without algorithm.

* refactor: deleted console.log
  • Loading branch information
JinIgarashi authored Oct 3, 2024
1 parent 3dcc854 commit f1c5cad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-spoons-add.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions sites/geohub/src/components/util/stac/StacApiExplorer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,9 @@
width: 300px;
background-color: rgba(255, 255, 255, 1);
z-index: 999;
max-height: 90%;
overflow-y: auto;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions sites/geohub/src/lib/RasterTileData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions sites/geohub/src/lib/server/helpers/createDatasetLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand All @@ -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();
Expand Down

0 comments on commit f1c5cad

Please sign in to comment.