1
我想動態更改WMS層的SLD。我可以通過STYLES參數應用Geoserver保存SLD,但是當我想通過SLD_BODY應用SLD時,它發送請求但沒有任何事情發生。我認爲一切都很好,但SLD不適用於圖層。下面是代碼:OpenLayers將SLD應用於WMS層3
var SLD = '<?xml version="1.0" encoding="UTF-8"?>'+
'<StyledLayerDescriptor version="1.0.0" 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"'+
'xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">'+
'<NamedLayer>'+
'<Name>pmo:'+ layer.Name + '</Name>'+
'<UserStyle>'+
'<Name>pmo:' + layer.Name + '</Name>' +
'<Title>A small red flag</Title>'+
'<Abstract>A sample of how to use an SVG based symbolizer</Abstract>'+
'<FeatureTypeStyle>'+
'<Rule>'+
'<Title>Red flag</Title>'+
'<PointSymbolizer>'+
'<Graphic>'+
'<ExternalGraphic>'+
'<OnlineResource xlink:type="simple" xlink:href="burg02.svg" />'+
'<Format>image/svg+xml</Format>'+
'</ExternalGraphic>'+
'<Size>'+
'<ogc:Literal>20</ogc:Literal>'+
'</Size>'+
'</Graphic>'+
'</PointSymbolizer>'+
'</Rule>'+
'</FeatureTypeStyle>'+
'</UserStyle>'+
'</NamedLayer>'+
'</StyledLayerDescriptor>';
SLD = encodeURI(SLD);
var source = layer.WMSLayer.getSource();
source.updateParams({ 'STYLES': '' ,'SLD_BODY': SLD });
我改變風格來定義,我請求發送到利用Geoserver,我得到這個錯誤: 了java.lang.RuntimeException: org.xml.sax.SAXParseException; lineNumber 我調試字符串,這是因爲我發送的顏色爲#字符。我不知道我應該如何糾正它 – danialtehrani
而不是你的sld pls替換上面的代碼 – dev9