Skip to content

Commit

Permalink
support custom URL parameters in a GetLegendGraphic request for a lay…
Browse files Browse the repository at this point in the history
…er without a style configured
  • Loading branch information
sidneygijzen committed Aug 28, 2024
1 parent 3af4e38 commit 36e6604
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
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.7.7)

- support URL parameters in a GetLegendGraphic request for a layer without a style configured
- [The next improvement]

#### 8.7.6 - 2024-08-22
Expand Down
2 changes: 1 addition & 1 deletion lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default class WebMapServiceCapabilitiesStratum extends LoadableStratum(
legendUri = URI(
proxyCatalogItemUrl(
this.catalogItem,
this.catalogItem.url.split("?")[0]
this.catalogItem.getLegendBaseUrl()
)
);
legendUri
Expand Down
14 changes: 14 additions & 0 deletions lib/Models/Catalog/Ows/WebMapServiceCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions test/Models/Catalog/Ows/WebMapServiceCatalogItemSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,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);
Expand Down

0 comments on commit 36e6604

Please sign in to comment.