0

I am loading a layer from Geoserver to OpenLayers using this code :

overlays = new ol.layer.Group({
    'title': 'Couches',
    layers: [
            new ol.layer.Image({
            title: 'refer_22',
            source: new ol.source.ImageWMS({
                url: 'http://localhost:8080/geoserver/wms',
                params: {'LAYERS': 'topp:refer_22'},
                ratio: 1,
                serverType: 'geoserver'})
            })
    ]
});

map.addLayer(overlays);

In Geoserver, I created a sld style "style.sld" and assigned it to the layer

Now, let s suppose I have 5 styles : "style_1.sld", ..., "style_5.sld"

Is there a way to add a line where I can specify whish style I want my layer to be displayed with.

obito M
  • 25
  • 5
  • 2
    If you have named styles available in the Capabilities you can change dynamically `layer.getSource().updateParams({'STYLES': 'style_1'});` You can also pass SLD and SLD_BODY as parameters. A long SLD_BODY might need a custom load function to load the image via XHR POST. – Mike Sep 07 '21 at 11:33
  • Yes ,that exactly what I needed, thank you – obito M Sep 07 '21 at 12:05

0 Answers0