<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Dear list,<br>I would like to be able to merge a rule created on the fly with an existing SLD to style a requested wms layer.<br>So far, I accept input from the user to filter a wms layer.<br>The filter works when added to a layer: only the object matching the query criteria are added to the map, however the layer is displayed using the default orange styling rather than the nice SLD i specified. I am having difficulty defining how the layer should be rendered.<br>I feel it should be:<br>1. Create a rule according to the user's filter input e.g. "show features where size >25"<br>2. Fetch the SLD corresponding to the layer from Geoserver.<br>3. Add the new filter rule temporarily to the Existing SLD by merging params, thus only showing features matching the filter criteria and rendered according to the specified SLD<br><br>Step 1, no problem. Step 2. Not sure
exactly what the url of the SLD should be, but if I define the SLD as a variable in the javascript then I temporarily bypass this problem.<br>Step 3. Im stuck - I cannot figure out how to merge a new rule with an EXISTING SLD. I can add the rule to a new SLD, but cannot figure out how to append it to an existing style.<br><br>I would be really grateful if anyone could help me with:<br>1. verifying the correct url to reference an existing sld on my geoserver installation<br>2. How to temporarily append/merge the user's filter-rule to the appropriate SLD for the layer in order to style the layer correctly.<br><br>My code is below.<br>Many thanks,<br><br>Eoin.<br><br><br>The code I am using is:<br><br> /*build a rule based on the user input to the query panel*/<br><br> var rule = new OpenLayers.Rule({<br> filter:
panel.getFilter()<br> });<br><br> rule.symbolizer[queryPanel.symbolizerType] = symbolizer;<br><br> /**Read the existing SLD: my_sld is an SLD defined as a variable in the javascript**/<br><br> var sld = new OpenLayers.Format.SLD().read(my_sld);<br> //or read the SLD from geoserver: ...read("http:.../geoserver/data/styles/mystyle.sld"); -not sure this is correct?<br><br> /**merge this rule to an existing style. At present I am merging the rule into a NEW sld with no problems, but the new sld does not have the color,line properties etc. that I require**/<br><br> var style = new OpenLayers.Style("", {rules: [rule]});<br> wms.mergeNewParams({<br> sld_body: new OpenLayers.Format.SLD().write({<br> namedLayers: [{<br> name:
panel.selectedLayer.get("name"),<br> userStyles: [style]<br> }]<br> })<br> });</td></tr></table><br>