I have a request I send to get specific layers based on year, type and region. I receive the request for the layers and can display it on the map perfectly. The legend for this layer however, comes back as a broken image, because the geoservice was not able to produce it.
The URL for the petitioned legend graphic shows up like this upon the element´s inspection in the DOM:
If I replace the ? character BEFORE the CQL_FILTER options with & I get the original legend for the layer request sans filtering. I am not sure if it is fixing the problem and returning the correct graphic, or if the request is disregarding the petition for the CQL mods entirely because of the character change. This change is being done by hand to test the url, not programatically.
Actually, I see no place in the documentation that would suggest the customlayer parameter options from my request should be tacked on to the legendurl value with a ? and not a &, which is weird. I have not yet found the part of my code where this specific concatenation is happening, as I am using the ESRI loader library to preload the legend widget for me.
Here is a bit of the code where I tack on the CQL specifications:
this.esriLayer_lc.sublayers.items[0].name = this.addLegendName(
typeLegend,
);
this.esriLayer_lc.sublayers.items[0].legendUrl = this.addLegendNameToUrl(
typeLegend,
);
this.esriLayer_lc.customLayerParameters['CQL_FILTER'] =
'klc_code LIKE ' +
"'" +
this.dataKlc_code +
"'" +
" AND in_pa = 'not_defined' AND date = " +
selectBoxHighlightsLc;
Here is my function where I set everything in place for the request:
addLegendName(legend) {
let name = legend;
return name;
}
addLegendNameToUrl(legend) {
const legendLinkUrl =
'https://geospatial.jrc.ec.europa.eu/geoserver/hotspots/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=';
return legendLinkUrl + legend;
}
layerModelInit() {
const serviceUrl =
'https://geospatial.jrc.ec.europa.eu/geoserver/hotspots/wms';
this.esriLayer_lcc = new WMSLayer({
url: serviceUrl,
//featureInfoFormat: "application/json",
customLayerParameters: {},
sublayers: [
// LAND COVER CHANGE DATASET ________________________________________________________________________________________________________________
{
name: this.addLegendName('all_lcc_a_pol'),
legendUrl: this.addLegendNameToUrl('all_lcc_a_pol'),
},
],
});
It is set up this way so that I bring in the entire layer set by default, with a global legend that is recalled by way of the legend name, and then I have a filter I can apply to ask for the info from specific regions, filter type, and available year. Even though it works great for producing a layer, it does not work well for producing a legend graphic.