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 :
https://[URL]/[FILE].nc?styles=default-scalar%2Fdefault&format=image%2Fpng&transparent=true&colorscalerange=6.656%2C43.22&numcolorbands=250&opacity=100&service=WMS&version=1.1.1&request=GetMap&layers=SSS&bbox=-90%2C-90%2C0%2C0&width=256&height=256&srs=EPSG%3A4326
When adding the “sld_body” line to the provider, the requests sent to the Thredds server now look like :
https://[URL]/[FILE].nc?styles=default-scalar%2Fdefault&format=image%2Fpng&transparent=true&colorscalerange=6.656%2C43.22&numcolorbands=250&opacity=100&sld_body=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22ISO-8859-1%22%3F%3E%3CStyledLayerDescriptor%20version%3D%221.0.0%22%20xsi%3AschemaLocation%3D%22http%3A%2F%2Fwww.opengis.net%2Fsld%20StyledLayerDescriptor.xsd%22%20xmlns%3D%22http%3A%2F%2Fwww.opengis.net%2Fsld%22%20xmlns%3Aogc%3D%22http%3A%2F%2Fwww.opengis.net%2Fogc%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%3E%3CNamedLayer%3E%3CName%3Econtours%3C%2FName%3E%3CUserStyle%3E%3CTitle%3Econtours%3C%2FTitle%3E%3CFeatureTypeStyle%3E%3CRule%3E%3CLineSymbolizer%3E%3CStroke%3E%3CCssParameter%20name%3D%22stroke%22%3E%23000000%3C%2FCssParameter%3E%3CCssParameter%20name%3D%22stroke-width%22%3E3%3C%2FCssParameter%3E%3C%2FStroke%3E%3C%2FLineSymbolizer%3E%3C%2FRule%3E%3C%2FFeatureTypeStyle%3E%3C%2FUserStyle%3E%3C%2FNamedLayer%3E%3C%2FStyledLayerDescriptor%3E&service=WMS&version=1.1.1&request=GetMap&layers=SSS&bbox=-22.5%2C-67.5%2C0%2C-45&width=256&height=256&srs=EPSG%3A4326
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="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>Simple Line</Name>
<UserStyle>
<Title>SLD Cook Book: Simple Line</Title>
<FeatureTypeStyle>
<Rule>
<LineSymbolizer>
<Stroke>
<CssParameter name="stroke">#000000</CssParameter>
<CssParameter name="stroke-width">3</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
But the request don’t work, returning this error :
<ServiceExceptionReport version="1.1.1" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.1.1/exceptions_1_1_1.xsd">
<ServiceException>
Problem with SLD document Cause: A named layer must be named.
</ServiceException>
</ServiceExceptionReport>
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).