16

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?

radek
  • 10,579
  • 12
  • 86
  • 121

4 Answers4

11

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

Auspex
  • 153
  • 1
  • 12
Vadim
  • 3,971
  • 2
  • 29
  • 42
  • 1
    That's cool - I didn't know you could do that. – Ian Turton Dec 08 '10 at 19:46
  • I've never used it but I thought I saw it somewhere before, so had to research the good old trusty Nabble.com forum. However lets keep filling out the SO GIS board as well. – Vadim Dec 08 '10 at 19:51
  • 2
    But in a way you're right that you're still responsible for styling it on the client, right? It's not on the server. But you can style with a pre-made SLD on the client. – Vadim Dec 08 '10 at 19:52
  • 5
    It appears that the link is broken. Could you explain how to do this, or provide a new link please? – Ravi Mehta Jan 24 '15 at 04:13
6

Short answer is no - WFS sends you the data and then you are responsible for styling it in the client. OpenLayers uses a stylemap to style a vector layer. See http://docs.openlayers.org/library/feature_styling.html for details of how to style a vector layer.

Ian Turton
  • 81,417
  • 6
  • 84
  • 185
2

Yes, you could load the wfs-layer into openlayers, then parse the sld-file into an openlayers-stylemap, and apply it to the wfs-layer.

Alternatively, you could attach the sld to the geoserver-wfs-layer as the default sld. Then load the wfs-layer into openlayers and specify an image-format (e.g. image/png or image/jpeg) in the request parameter. Once loaded, store it as an Openlayers.Layer.WMS-object. This will render the layer as a raster layer with the attached sld already applied by geoserver.

user9124
  • 161
  • 3
1

The OGC definition for sld say that is for WMS

The OpenGIS® Styled Layer Descriptor (SLD) Profile of the OpenGIS® Web Map Service (WMS) Encoding Standard

so !