[OpenLayers-Users] save Filter

Andreas Hocevar ahocevar at opengeo.org
Thu Dec 17 09:20:22 EST 2009


On 2009-12-17 15:12, Jimmy Aumard wrote:
> Thanks for answer Andreas,
>
> My problem is little more complicated :s
> I propose to users to make own styles, I would like to save styles
> (with filters, rules, symbolizers...) in my database in sld format.
>
> I try this:
> var frmt = new OpenLayers.Format.SLD();
> var sld= frmt.write(my_layer.styleMap);
>
> But it's doesn't work
>
> After I have to load slds on layers (I try to follow this example
> http://www.openlayers.org/dev/examples/sld.html) but I have to
> transform StyleMap -> SLD first.

The StyleMap is no 1:1 representation of an SLD document. So you would
e.g. have to do the following:

var rule = new OpenLayers.Rule({
    filter: yourFilter
});
rule.symbolizer[yourGeometryType(point|line|polygon)] = yourSymbolizer;
var style = new OpenLayers.Style("", {rules: [rule]});
var sld = new OpenLayers.Format.SLD().write({
    namedLayers: [{
        name: yourLayer.name,
        userStyles: [style]
    }]
});


Regards,
Andreas.

-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.




More information about the Users mailing list