Skip to content
Draft
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### next release (8.8.1)

- enforce the WMS layer limit
- [The next improvement]

#### 8.8.0 - 2025-02-18
Expand Down
2 changes: 2 additions & 0 deletions lib/Models/Catalog/Ows/WebMapServiceCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export interface CapabilitiesService {
readonly AccessConstraints?: string;
/** List of keywords or keyword phrases to help catalog searching. */
readonly KeywordList?: OwsKeywordList;
/** The maximum amount of layers that can be requested. */
readonly LayerLimit?: string;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ export default class WebMapServiceCapabilitiesStratum extends LoadableStratum(
);
}

@computed
get layerLimit() {
if (isDefined(this.capabilities?.Service?.LayerLimit)) {
return parseInt(this.capabilities.Service.LayerLimit, 10);
}
}

@computed
get layers(): string | undefined {
let layers: string | undefined;
Expand Down
24 changes: 20 additions & 4 deletions lib/Models/Catalog/Ows/WebMapServiceCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,31 @@ class WebMapServiceCatalogItem
return "0d";
}

@computed
get layerLimit() {
const gcStratum: WebMapServiceCapabilitiesStratum | undefined =
this.strata.get(
GetCapabilitiesMixin.getCapabilitiesStratumName
) as WebMapServiceCapabilitiesStratum;

return gcStratum?.layerLimit;
}

Comment on lines +248 to +257
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of pulling layerLimit out of the WebMapServiceCapabilitiesStratum, it would be better to create a layerLimit trait in WebMapServiceCatalogItemTraits.

This would allow the user to configure it (in a JSON catalog), and then you can remove this get layerLimit in WebMapServiceCatalogItem.

While there are a few instances of using the WebMapServiceCapabilitiesStratum directly in WebMapServiceCatalogItem, this is not ideal, and should be considered an anti-pattern, at some point we'll refactor it 🙂

@computed
get layersArray(): ReadonlyArray<string> {
if (!this.layers) return [];

let layers: string[];

if (Array.isArray(this.layers)) {
return this.layers;
} else if (this.layers) {
return this.layers.split(",");
layers = this.layers;
} else {
return [];
layers = this.layers.split(",");
}

if (this.layerLimit) layers = layers.slice(0, this.layerLimit);

return layers;
}

/** LAYERS which are valid (i.e. exist in GetCapabilities).
Expand Down
16 changes: 16 additions & 0 deletions test/Models/Catalog/Ows/WebMapServiceCatalogItemSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,22 @@ describe("WebMapServiceCatalogItem", function () {
expect(wms.validLayers).toEqual(["single_period"]);
});

it("enforces the layer limit", async function () {
const terria = new Terria();
const wms = new WebMapServiceCatalogItem("test", terria);
runInAction(() => {
wms.setTrait(
"definition",
"url",
"test/WMS/wms_nested_groups_layer_limited.xml"
);
});

await wms.loadMetadata();

expect(wms.validLayers).toEqual(["ls8_nbart_geomedian_annual"]);
});

it("uses GetFeatureInfo from GetCapabilities", async function () {
expect().nothing();
const terria = new Terria();
Expand Down
1 change: 0 additions & 1 deletion wwwroot/test/WMS/colorscalerange.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
</ContactInformation>
<Fees>none</Fees>
<AccessConstraints>none</AccessConstraints>
<LayerLimit>1</LayerLimit>
<MaxWidth>1024</MaxWidth>
<MaxHeight>1024</MaxHeight>
</Service>
Expand Down
1 change: 0 additions & 1 deletion wwwroot/test/WMS/ncwms2_service.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
</ContactInformation>
<Fees>none</Fees>
<AccessConstraints>none</AccessConstraints>
<LayerLimit>1</LayerLimit>
<MaxWidth>1024</MaxWidth>
<MaxHeight>1024</MaxHeight>
</Service>
Expand Down
1 change: 0 additions & 1 deletion wwwroot/test/WMS/styles_and_dimensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
</ContactInformation>
<Fees>none</Fees>
<AccessConstraints>none</AccessConstraints>
<LayerLimit>1</LayerLimit>
<MaxWidth>2048</MaxWidth>
<MaxHeight>2048</MaxHeight>
</Service>
Expand Down
1 change: 0 additions & 1 deletion wwwroot/test/WMS/wms_crs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd">
</ContactInformation>
<Fees>none</Fees>
<AccessConstraints>© Commonwealth of Australia (Geoscience Australia) 2018. This product is released under the Creative Commons Attribution 4.0 International Licence. http://creativecommons.org/licenses/by/4.0/legalcode</AccessConstraints>
<LayerLimit>1</LayerLimit>
<MaxWidth>512</MaxWidth>
<MaxHeight>512</MaxHeight>
</Service>
Expand Down
1 change: 0 additions & 1 deletion wwwroot/test/WMS/wms_nested_groups.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd">
</ContactInformation>
<Fees>none</Fees>
<AccessConstraints>© Commonwealth of Australia (Geoscience Australia) 2018. This product is released under the Creative Commons Attribution 4.0 International Licence. http://creativecommons.org/licenses/by/4.0/legalcode</AccessConstraints>
<LayerLimit>1</LayerLimit>
<MaxWidth>512</MaxWidth>
<MaxHeight>512</MaxHeight>
</Service>
Expand Down
Loading