Problem when using external SLD in WebMapServiceProvider

Hi !

I’m having trouble when trying to specify a custom SLD style to Cesium WebmapService provider.

For a bit of context, here is the code for the provider I’m currently using :

const provider = new Cesium.WebMapServiceImageryProvider({
    url: wms_ncdf,
    layers: wms_variable,
    parameters: {
        styles: wms_style + "/" + wms_palette,
        format: 'image/png',
        transparent: 'true',
        colorscalerange: wms_min+","+wms_max,
        numcolorbands: wms_numcolorbands,
        opacity: wms_opacity,
        sld_body: sld_custom

The “sld_body: sld_custom” line is a new addition. Without that, the provider work and return the requested tiles after sending this type of requests to our Thredds server where are stored our NCDF files :


When adding the “sld_body” line to the provider, the requests sent to the Thredds server now look like :


The SLD used is a simple one, only for test purpose. I tested it on GeoServer and the SLD worked. For better readability, here is the “sld_custom” variable used in the provider (the line breaks are removed in my code to avoid encoding problems) :

<?xml version="1.0" encoding="ISO-8859-1"?>
  <StyledLayerDescriptor version="1.0.0" 
    xsi:schemaLocation=" StyledLayerDescriptor.xsd" 
    <Name>Simple Line</Name>
      <Title>SLD Cook Book: Simple Line</Title>
              <CssParameter name="stroke">#000000</CssParameter>
              <CssParameter name="stroke-width">3</CssParameter>    

But the request don’t work, returning this error :

<ServiceExceptionReport version="1.1.1" xsi:schemaLocation="">
    Problem with SLD document Cause: A named layer must be named.

I don’t understand where this error come from (The “NamedLayer” tag in my SLD already have a “Name” tag and work in the GeoServer preview) anddI can’t find any occurrence of it in forums. Our Thredds server is in 5.4 version (since it seems that the external SLD functionality was added in 5.0 : Update TDS WMS configuration to support SLD parameter by ethanrd · Pull Request #73 · Unidata/tds · GitHub).

Hi there,

I tested it on GeoServer and the SLD worked.

Do you mind providing more info on how you tested this? Did you pass sld_body as a query parameter as you are doing in the example above?

My first guess here would be a url encoding or decoding issue.


Hi Gabby !

When I tested it, it was on my local Geoserver (I just downloaded it to run some tests so it’s the default configuration). I tried to create a new Style named “contours” with this SLD, and I checked the “Layer Preview” tab to check if my SLD was correct. It seems to work for this simple SLD.

Geoserver Preview

After that, I tried to insert this SLD in the “SLD_BODY” parameter of the GetMap url, but even after formatting the SLD (removing brackets, slashes…), I couldn’t make it work.

I tried searching for a working example and found this post : GeoServer WMS inline SLD_BODY syntax problem - Geographic Information Systems Stack Exchange

Error with contours' SLD_BODY

I tried to adapt it to apply it on Geoserver’s “topp:states” layer and it kinda worked. I got a result but it seems to be the default display of this layer. But at least, this wasn’t an error

Result with new SLD_BODY

But when I tried to include this SLD_BODY in my Thredds request (after changing “NamedLayer > Name” by “SSS” since it’s my layer’s name), I got the same error again.

Error after requesting my Thredds' layer with SLD_BODY

And once again, the base URL was generated by Cesium and return a correct layer if I remove the SLD_BODY parameter, so I don’t thing I’m doing a mistake while naming my NamedLayer.

Result after requesting my Thredds' layer without SLD_BODY

Now, I don’t really have any clues left to solve this problem so I hope someone will be able to help.