Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support custom URL parameters in a GetLegendGraphic request for a layer without a style configured #7263

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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.7.9)

- support URL parameters in a GetLegendGraphic request for a layer without a style configured
- Properly initialize react ref in functional components
- Add NominatimSearchProvider.
- [The next improvement]
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 @@ -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);
Expand Down