2

I wonder if I can add SLD style to WMS or WFS layer existing in GeoServer, using OpenLayers 3?

1

You can add SLD style to WMS request, while WFS requsts can be styled with ol.style.

Example of Openlayers WMS request below. You can use either existing SLD on a given url or add SLD string to sld body. With long styles you will probably need to use POST method.

new ol.layer.Tile({
    'z-index': 1,
    source: new ol.source.TileWMS({
        url: url,
        projection: wmsProjection,
        preload: Infinity,
        params: {
            "VERSION": wmsVersion,
            "LAYERS": layerName,
            "TILED": true,
            "SLD": sldUrl,
            /*"SLD_BODY": sldBody*/
        }
        }),
        crossOrigin: 'anonymous'
    });

If you are interested in saving SLD to Geoserver then you will have to get familiar with Geoserver REST API.

3

Well it is certainly possible to construct an SLD and send it directly or by reference as part of a WMS GetMap request to a GeoServer service, with OpenLayers as a client. This is something done by the OneGeology portal as part of their thematic analysis tools.

It isn't possible for WFS, because a WFS doesn't deal in styling, you just get the raw data from the server and have to render it in your client.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.