I am trying to use dynamic styling by providing the sld& parameter in the WMS request. The parameter is pointing to a local file that is modified by a script. Like this: sld=file:///D:/testStyle.sld&.
The issue is that the layer is always displayed with the default style defined on GeoServer. Here is the content of the file:
<?xml version="1.0" encoding="UTF-8"?>
<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>ne:testLayer</Name>
<UserStyle>
<Name>testStyle</Name>
<Title>simple</Title>
<FeatureTypeStyle>
<Rule>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#FF0000</CssParameter>
</Fill>
</Mark>
<Size>6</Size>
</Graphic>
</PointSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
I have tried the following:
- Omit the layers& parameter in the WMS request so I do not go into Library Mode. This works fine, but unfortunately I am constrained to use the layers& parameter in the request so this is not an option.
- Using the layers& and sld& parameters in the WMS request. I am aware that this will trigger Library Mode. When I do this, the layer is displayed with the default style, not with the style defined in the SLD.
- Using the layers&, sld&, styles=testStyle& parameters in the WMS request. When I do this I get an error that tells me the testStyle could not be found. (even though there are no typos)
- Using the layers& and sld& parameters in the WMS and also adding the
<IsDefault>1</IsDefault>
tag in the UserStyle defined in the SLD. In this case, the layers is displayed again with the default style - defined in GeoServer.
The request I am using to preview the layer (only for point 3- since for the other points I just remove some of the parameters):
http://localhost:8080/geoserver/ne/wms?service=WMS&version=1.1.0&request=GetMap&layers=ne%3AtestLayer&bbox=51.230123%2C25.192783%2C51.619153%2C25.405197&width=768&height=419&srs=EPSG%3A404000&format=application/openlayers#toggle&sld=file:///D:/testStyle.sld&styles=testStyle&
What am I doing wrong?
&styles=testStyle
the style must be configured on the server side. It will then be included also in the GetCapabilities. One thing that you have not tried yet is to use&SLD_BODY=...
with GetMap.SLD_BODY=
, but this will not meet the requirements because I will not be able to dynamically modify the request from the client side)