[Users] Merging a new rule(filter) with an existing SLD
Eoin Mac Aoidh
eoinyp at yahoo.com
Thu Sep 30 17:16:55 CEST 2010
Dear list,
I would like to be able to merge a rule created on the fly with an existing SLD to style a requested wms layer.
So far, I accept input from the user to filter a wms layer.
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.
I feel it should be:
1. Create a rule according to the user's filter input e.g. "show features where size >25"
2. Fetch the SLD corresponding to the layer from Geoserver.
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
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.
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.
I would be really grateful if anyone could help me with:
1. verifying the correct url to reference an existing sld on my geoserver installation
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.
My code is below.
Many thanks,
Eoin.
The code I am using is:
/*build a rule based on the user input to the query panel*/
var rule = new OpenLayers.Rule({
filter: panel.getFilter()
});
rule.symbolizer[queryPanel.symbolizerType] = symbolizer;
/**Read the existing SLD: my_sld is an SLD defined as a variable in the javascript**/
var sld = new OpenLayers.Format.SLD().read(my_sld);
//or read the SLD from geoserver: ...read("http:.../geoserver/data/styles/mystyle.sld"); -not sure this is correct?
/**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**/
var style = new OpenLayers.Style("", {rules: [rule]});
wms.mergeNewParams({
sld_body: new OpenLayers.Format.SLD().write({
namedLayers: [{
name: panel.selectedLayer.get("name"),
userStyles: [style]
}]
})
});
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20100930/13f7547c/attachment.htm
More information about the Users
mailing list