[GIS] OpenLayers: how to style WFS layer with SLD file

geoserveropenlayers-2sldwfs

I'm experimenting with a simple web mapping service build on PostGIS/GeoServer/OpenLayers stack on Win 2008 Server.

I overlay vector layer from PostGIS using:

var Index1v = new OpenLayers.Layer.Vector("Index1 v", {
    strategies: [new OpenLayers.Strategy.BBOX()],
        protocol: new OpenLayers.Protocol.WFS({
            version: "1.1.0",
            url: "http://localhost:1979/geoserver/wfs",
            featureType: "bern_poly_s100",
            featureNS: "http://www.ispm.ch",
            srsName: "EPSG:900913"
        })
});

Layer displays correctly, but in plain, default[?] style from GeoServer.

I've got a SLD style file build with uDig and it seems to be correct since WMS service is using it without any problems. Can I use it to style WFS layer as well?

Best Answer

Take a look at OL's "Styled Layer Descriptor (SLD) Example" example. They use SLD to style GML, but should work for WFS (a vector layer) as well.

Credit: OL's Nabble.com forum