Select to view content in your preferred language

WMS GetLegendGraphic in 4.x JavaScript API with custom SLD not working

1638
3
02-12-2021 02:47 PM
GeoNicole
Emerging Contributor

Hi,

I've been working on a fire weather monitoring web app using the 4.x (.17 and now .18) JS API and there seems to be an issue with how it's creating the GetLegendGraphics request URL with the custom parameters.

The custom SLD works and applies properly for the GetMap requests, but when it's appending the &SLD=thesource.sld parameter it's using a ? instead of &, and occasionally, converting the = sign doesn't seem to work either.

Here's the little function I'm using to initialize a whole array of layers

function wmsSLDInit(src, attribution, title, name, subtitle, legendsrc, sld) {
        return new WMSLayer({
            url: src,
            copyright: attribution,
            title: title,
            featureInfoUrl: src,
            featureInfoFormat: "application/json",
            sublayers: [{
                    name: name,
                    title: subtitle,
                    legendUrl: legendsrc,
                    popupEnabled: true,
                    queryable: true
                }],
            listMode: "hide-children",
            customLayerParameters: {SLD: sld}
        });
    }

One test case used the following parameters:

legendsrc: "https://cwfis.cfs.nrcan.gc.ca/geoserver/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=public%3Atemp_current"

sld: "https://maps.forsite.ca/AtcoMonitoring/styles/CWFIS_TT.sld"

Which resulted in the GetLegendGraphics request of:

https://cwfis.cfs.nrcan.gc.ca/geoserver/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=public:temp_current?SLD=https%3A%2F%2Fmaps.forsite.ca%2FAtcoMonitoring%2Fstyles%2FCWFIS_TT.sld

which as you can see, does not work. Change the ? and we have

https://cwfis.cfs.nrcan.gc.ca/geoserver/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=public%3Atemp_current&SLD=https%3A%2F%2Fmaps.forsite.ca%2FAtcoMonitoring%2Fstyles%2FCWFIS_TT.sld

which works. 

Similar kind of thing on the Environment Canada DataMart server (https://geo.weather.gc.ca/geomet?) so it's not a quirk of the server, it's how that custom parameter is being appended.

I mean, obviously I can just use the layerlist panels or legend source stuff and generate the URLs and put the resulting images somewhere, but the point is that it's supposed to work, and it does for the GetMap requests.

Anyone else run into this? Known issue?

0 Kudos
3 Replies
NilsBabel1
Regular Contributor

Hello, did you ever find a solution to this?  I'm having the exact same problem.  I have a WMS with a sublayer.  If I don't add any customParameters the legendUrl works fine.  But when I add a TIME parameter it appends that parameter to the legendUrl with a ? instead of & and the url does not work.  

0 Kudos
GeoNicole
Emerging Contributor

Hi! Sorry for the long delay on the response, I switched projects for a while. I did bring it up at the Dev Summit when I was talking to folks, but no response from them on the issue. 

I wound up just either hard-coding or generating the URLs using strings and arrays where I needed, which was and continues to be a pain. So, for each sublayer of the WMS I pass in the legendUrl parameter directly, which overrides the built-in construction of the legend URL from the other info passed in.

So I wind up with gross stuff like this, looping through arrays to pass things to that wmsSLDInit function you see in my first post.

 

window[dBoardCWFISKey[i]] = wmsSLDInit("https://cwfis.cfs.nrcan.gc.ca/geoserver/wms?", "Canadian Wildland Fire Information System (CWFIS)", dBoardCWFIS[i][0], dBoardCWFIS[i][1] + "_current", dBoardCWFIS[i][2], "https://cwfis.cfs.nrcan.gc.ca/geoserver/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=" + dBoardCWFIS[i][1] + "_current", dBoardCWFIS[i][3]);

 

 Hope this might still help a bit!

0 Kudos
NilsBabel1
Regular Contributor

I reported this issue to Esri and they created a bug for it.  BUG-000141284. Hopefully it gets resolved in the next release.

0 Kudos