Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sixlighthouses committed May 10, 2024
1 parent c07fb88 commit e8fc7b6
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 47 deletions.
57 changes: 44 additions & 13 deletions lib/Models/Catalog/Ows/NcWMSGetMetadataStratum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { computed, makeObservable, runInAction } from "mobx";
import LoadableStratum from "../../Definition/LoadableStratum";
import { BaseModel } from "../../Definition/Model";
import WebMapServiceCatalogItemTraits, {
WebMapServiceAvailablePaletteTraits,
WebMapServiceAvailableStyleTraits
} from "../../../Traits/TraitsClasses/WebMapServiceCatalogItemTraits";
import proxyCatalogItemUrl from "../proxyCatalogItemUrl";
Expand All @@ -11,29 +12,58 @@ import StratumFromTraits from "../../Definition/StratumFromTraits";
import { SelectableDimensionEnum } from "../../SelectableDimensions/SelectableDimensions";
import WebMapServiceCatalogItem from "./WebMapServiceCatalogItem";
import isDefined from "../../../Core/isDefined";
import StratumOrder from "../../Definition/StratumOrder";

export default class NcWMSGetMetadataStratum extends LoadableStratum(
WebMapServiceCatalogItemTraits
) {
static stratumName = "ncWMSGetMetadata";
static availablePalettes: Complete<{
name?: string | undefined;
title?: string | undefined;
abstract?: string | undefined;
}>[];

static async load(
catalogItem: WebMapServiceCatalogItem,
availablePalettes: string[]
availablePalettes?: StratumFromTraits<WebMapServiceAvailablePaletteTraits>[]
): Promise<NcWMSGetMetadataStratum> {
if (!isDefined(availablePalettes)) {
const palettes = await new NcWMSGetMetadataStratum(
catalogItem,
[]
).fetchPalettes();
availablePalettes = palettes.map((palette) => palette.name || "");
const paletteResult: StratumFromTraits<WebMapServiceAvailablePaletteTraits>[] =
[];

const url = catalogItem
.uri!.clone()
.setSearch({
service: "WMS",
version: catalogItem.useWmsVersion130 ? "1.3.0" : "1.1.1",
request: "GetMetadata",
item: "layerDetails",
layerName: catalogItem.layersArray[0]
})
.toString();

if (url) {
const paletteUrl = proxyCatalogItemUrl(catalogItem, url);
const response = await fetch(paletteUrl);
const data = await response.json();
const palettes = data.palettes;
palettes.forEach((palette: any) => {
paletteResult.push({
name: palette,
title: palette,
abstract: palette
});
});
}
return new NcWMSGetMetadataStratum(catalogItem, availablePalettes);

const stratum = new NcWMSGetMetadataStratum(catalogItem, availablePalettes);
console.log(stratum);
return stratum;
}

constructor(
readonly catalogItem: WebMapServiceCatalogItem,
readonly availablePalettes: string[]
availablePalettes?: StratumFromTraits<WebMapServiceAvailablePaletteTraits>[]
) {
super();
makeObservable(this);
Expand All @@ -47,9 +77,9 @@ export default class NcWMSGetMetadataStratum extends LoadableStratum(
}

async fetchPalettes(): Promise<
StratumFromTraits<WebMapServiceAvailableStyleTraits>[]
StratumFromTraits<WebMapServiceAvailablePaletteTraits>[]
> {
const paletteResult: StratumFromTraits<WebMapServiceAvailableStyleTraits>[] =
const paletteResult: StratumFromTraits<WebMapServiceAvailablePaletteTraits>[] =
[];

const url = this.catalogItem
Expand All @@ -72,12 +102,13 @@ export default class NcWMSGetMetadataStratum extends LoadableStratum(
paletteResult.push({
name: palette,
title: palette,
abstract: palette,
legend: this.legends && this.legends[0] // Add null check and default value
abstract: palette
});
});
}

return paletteResult;
}
}

StratumOrder.addLoadStratum(NcWMSGetMetadataStratum.stratumName);
1 change: 0 additions & 1 deletion lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import WebMapServiceCapabilities, {
getRectangleFromLayer
} from "./WebMapServiceCapabilities";
import WebMapServiceCatalogItem from "./WebMapServiceCatalogItem";
import { Complete } from "../../../Core/TypeModifiers";

const dateFormat = require("dateformat");

Expand Down
124 changes: 96 additions & 28 deletions lib/Models/Catalog/Ows/WebMapServiceCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import {
} from "../../../Table/tableFeatureInfoContext";
import WebMapServiceCatalogItemTraits, {
SUPPORTED_CRS_3857,
SUPPORTED_CRS_4326,
WebMapServiceAvailableLayerStylesTraits
SUPPORTED_CRS_4326
} from "../../../Traits/TraitsClasses/WebMapServiceCatalogItemTraits";
import CommonStrata from "../../Definition/CommonStrata";
import CreateModel from "../../Definition/CreateModel";
Expand Down Expand Up @@ -227,22 +226,27 @@ class WebMapServiceCatalogItem
}

protected async forceLoadMetadata(): Promise<void> {
if (this.isNcWMS) {
const ncWMSGetMetadataStratum = await NcWMSGetMetadataStratum.load(this);

runInAction(() => {
this.strata.set(
NcWMSGetMetadataStratum.stratumName,
ncWMSGetMetadataStratum
);
});
}

if (
this.strata.get(GetCapabilitiesMixin.getCapabilitiesStratumName) !==
this.strata.get(GetCapabilitiesMixin.getCapabilitiesStratumName) ===
undefined
)
return;
const stratum = await WebMapServiceCapabilitiesStratum.load(this);

// const ncWMS = await NcWMSGetMetadataStratum.load(
// this,
// this.availablePalettes
// );
// console.log(ncWMS);
const stratum = await WebMapServiceCapabilitiesStratum.load(this);

runInAction(() => {
this.strata.set(GetCapabilitiesMixin.getCapabilitiesStratumName, stratum);
// this.strata.set(NcWMSGetMetadataStratum.stratumName, ncWMS);
});
}

Expand All @@ -254,15 +258,6 @@ class WebMapServiceCatalogItem
return "0d";
}

@computed
get availablePalettes(): string[] {
const ncWMSStrata = this.strata.get(
NcWMSGetMetadataStratum.stratumName
) as NcWMSGetMetadataStratum;

return ncWMSStrata?.availablePalettes ?? [];
}

@computed
get layersArray(): ReadonlyArray<string> {
if (Array.isArray(this.layers)) {
Expand Down Expand Up @@ -399,7 +394,6 @@ class WebMapServiceCatalogItem
if (time) {
uri.addQuery("time", time);
}

return uri.toString();
}

Expand Down Expand Up @@ -538,6 +532,8 @@ class WebMapServiceCatalogItem
return undefined;
}

console.log(`Creating new ImageryProvider for time ${time}`);

// Set dimensionParameters
const dimensionParameters = formatDimensionsForOws(this.dimensions);
if (time !== undefined) {
Expand Down Expand Up @@ -639,19 +635,24 @@ class WebMapServiceCatalogItem

@computed
get paletteDimensions(): SelectableDimensionEnum[] {
if (!this.isNcWMS || !this.showPalettes) {
return [];
}
// if (!this.isNcWMS || !this.showPalettes) {
// return [];
// }

const options: { name: string; id: string }[] = [];
// fetch ncWMS stratum
const ncWMSGetMetadataStratum = this.strata.get(
NcWMSGetMetadataStratum.stratumName
) as NcWMSGetMetadataStratum;

this;
console.log(ncWMSGetMetadataStratum);

const options: { name: string | undefined; id: string | undefined }[] = [];

if (this.availablePalettes) {
this.availablePalettes.map((palette) => {
options.push({
name: palette,
id: palette
name: palette.name,
id: palette.uniqueId
});
});
}
Expand Down Expand Up @@ -680,6 +681,73 @@ class WebMapServiceCatalogItem
];
}

// @computed
// get styleSelectableDimensions(): SelectableDimensionEnum[] {
// return this.availableStyles.map((layer, layerIndex) => {
// let name = "Styles";

// // If multiple layers -> prepend layer name to name
// if (this.availableStyles.length > 1) {
// // Attempt to get layer title from GetCapabilitiesStratum
// const layerTitle =
// layer.layerName &&
// (
// this.strata.get(
// GetCapabilitiesMixin.getCapabilitiesStratumName
// ) as WebMapServiceCapabilitiesStratum
// ).capabilitiesLayers.get(layer.layerName)?.Title;

// name = `${
// layerTitle || layer.layerName || `Layer ${layerIndex + 1}`
// } styles`;
// }

// const options = filterOutUndefined(
// layer.styles.map(function (s) {
// if (isDefined(s.name)) {
// return {
// name: s.title || s.name || "",
// id: s.name as string
// };
// }
// })
// );

// // Try to set selectedId to value stored in `styles` trait for this `layerIndex`
// // The `styles` parameter is CSV, a style for each layer
// const selectedId = this.styles?.split(",")?.[layerIndex];

// return {
// name,
// id: `${this.uniqueId}-${layer.layerName}-styles`,
// options,
// selectedId,
// setDimensionValue: (
// stratumId: string,
// newStyle: string | undefined
// ) => {
// if (!newStyle) return;
// runInAction(() => {
// const styles = this.styleSelectableDimensions.map(
// (style) => style.selectedId || ""
// );
// styles[layerIndex] = newStyle;
// this.setTrait(stratumId, "styles", styles.join(","));
// });
// },
// // There is no way of finding out default style if no style has been selected :(
// // To use the default style, we just send empty "styles" to WMS server
// // But if the server doesn't support GetLegendGraphic, then we can't request the default legend
// // Therefore - we only add the "Default style" / undefined option if supportsGetLegendGraphic is true
// allowUndefined: this.supportsGetLegendGraphic && options.length > 1,
// undefinedLabel: i18next.t(
// "models.webMapServiceCatalogItem.defaultStyleLabel"
// ),
// disable: this.isShowingDiff
// };
// });
// }

@computed
get styleSelectableDimensions(): SelectableDimensionEnum[] {
return this.availableStyles.map((layer, layerIndex) => {
Expand Down Expand Up @@ -830,7 +898,7 @@ class WebMapServiceCatalogItem
return super.selectableDimensions;
}

const paletteDimensions = this.showPalettes ? this.paletteDimensions : [];
const paletteDimensions = this.paletteDimensions;

return filterOutUndefined([
...super.selectableDimensions,
Expand Down
23 changes: 18 additions & 5 deletions lib/Traits/TraitsClasses/WebMapServiceCatalogItemTraits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,24 @@ export class WebMapServiceAvailableLayerStylesTraits extends ModelTraits {
export class WebMapServiceAvailablePaletteTraits extends ModelTraits {
@primitiveTrait({
type: "string",
name: "URL",
description:
"The URL of the GetMetadata request for the palette. This is used to get the palettes available for a layer."
name: "Style Name",
description: "The name of the style."
})
name?: string;

@primitiveTrait({
type: "string",
name: "Title",
description: "The title of the style."
})
url?: string;
title?: string;

@primitiveTrait({
type: "string",
name: "Abstract",
description: "The abstract describing the style."
})
abstract?: string;
}

export class WebMapServiceAvailableDimensionTraits extends ModelTraits {
Expand Down Expand Up @@ -349,7 +362,7 @@ export default class WebMapServiceCatalogItemTraits extends mixTraits(
description:
"Used to store the available palettes available for a layer. This is a non-standard property supported by THREDDS servers. This property is ignored unless WebMapServiceCatalogItem's isThredds is true. The default value is ['default']."
})
availablePalettes?: string[] = [];
availablePalettes?: WebMapServiceAvailablePaletteTraits[] = [];

@primitiveTrait({
type: "string",
Expand Down

0 comments on commit e8fc7b6

Please sign in to comment.