0

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:

https://geospatial.jrc.ec.europa.eu/geoserver/hotspots/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=all_lcc_a_pol?CQL_FILTER=klc_code%20LIKE%20'CAF_16'%20AND%20in_pa%20%3D%20'not_defined'%20AND%20date%20%3D%202000

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.

https://geospatial.jrc.ec.europa.eu/geoserver/hotspots/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=all_lcc_a_pol&CQL_FILTER=klc_code%20LIKE%20'CAF_16'%20AND%20in_pa%20%3D%20'not_defined'%20AND%20date%20%3D%202000

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.

2
  • You shouldn't have two ? in the URL. The ? is the separator between the 'scheme + authority + path of a URI and the query, see the Uniform Resource Identifier (URI): Generic Syntax specification
    – nmtoken
    Apr 13, 2023 at 14:13
  • I get it. I am not doing it myself. It is what is required to get a new legend graphic. When the request is sent, it is tacking on the CQL filter value from the custom layer parameters onto the legend request. What I am trying to retrieve is a new legend graphic that holds that values included in the filtered hotspot only.
    – u_arcgis
    Apr 14, 2023 at 13:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.