diff --git a/CHANGES.md b/CHANGES.md index f881d02b37..1074579188 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ #### next release (8.7.8) +- support URL parameters in a GetLegendGraphic request for a layer without a style configured - [The next improvement] #### 8.7.7 - 2024-10-01 diff --git a/lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts b/lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts index 3c9069a2e6..9bffe7f89c 100644 --- a/lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts +++ b/lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts @@ -203,7 +203,7 @@ export default class WebMapServiceCapabilitiesStratum extends LoadableStratum( legendUri = URI( proxyCatalogItemUrl( this.catalogItem, - this.catalogItem.url.split("?")[0] + this.catalogItem.getLegendBaseUrl() ) ); legendUri diff --git a/lib/Models/Catalog/Ows/WebMapServiceCatalogItem.ts b/lib/Models/Catalog/Ows/WebMapServiceCatalogItem.ts index a9c28efbb7..629aa0f494 100644 --- a/lib/Models/Catalog/Ows/WebMapServiceCatalogItem.ts +++ b/lib/Models/Catalog/Ows/WebMapServiceCatalogItem.ts @@ -364,6 +364,20 @@ class WebMapServiceCatalogItem this.setTrait(CommonStrata.user, "isShowingDiff", false); } + getLegendBaseUrl(): string { + // Remove problematic query parameters from URL + const baseUrl = QUERY_PARAMETERS_TO_REMOVE.reduce( + (url, parameter) => + url + .removeQuery(parameter) + .removeQuery(parameter.toUpperCase()) + .removeQuery(parameter.toLowerCase()), + new URI(this.url) + ); + + return baseUrl.toString(); + } + getLegendUrlForStyle( styleId: string, firstDate?: JulianDate, diff --git a/test/Models/Catalog/Ows/WebMapServiceCatalogItemSpec.ts b/test/Models/Catalog/Ows/WebMapServiceCatalogItemSpec.ts index e748448a35..982eadbf03 100644 --- a/test/Models/Catalog/Ows/WebMapServiceCatalogItemSpec.ts +++ b/test/Models/Catalog/Ows/WebMapServiceCatalogItemSpec.ts @@ -972,6 +972,40 @@ describe("WebMapServiceCatalogItem", function () { .catch(done.fail); }); + it("supports parameters in a GetLegendGraphic request for a layer without a style configured", function (done) { + const terria = new Terria(); + const wmsItem = new WebMapServiceCatalogItem("some-layer", terria); + runInAction(() => { + wmsItem.setTrait( + CommonStrata.definition, + "url", + "http://example.com/mapserv?map=%2Fmap%2Fexample.map" + ); + wmsItem.setTrait( + CommonStrata.definition, + "getCapabilitiesUrl", + "test/WMS/styles_and_dimensions.xml" + ); + wmsItem.setTrait(CommonStrata.definition, "layers", "A"); + wmsItem.setTrait( + CommonStrata.definition, + "supportsGetLegendGraphic", + true + ); + }); + + wmsItem + .loadMetadata() + .then(function () { + expect(wmsItem.legends.length).toBe(1); + expect(wmsItem.legends[0].url).toBe( + "http://example.com/mapserv?map=%2Fmap%2Fexample.map&service=WMS&version=1.3.0&request=GetLegendGraphic&format=image%2Fpng&sld_version=1.1.0&layer=A" + ); + }) + .then(done) + .catch(done.fail); + }); + it("fetches legend with colourScaleRange", function (done) { const terria = new Terria(); const wmsItem = new WebMapServiceCatalogItem("some-layer", terria);