[GIS] Pass sld env parameter with openlayers 3

geoserveropenlayerssld

Is there a way to pass sld env parameter with openlayers 3?
It works to pass the env parameter with a normal getmap-request. Doesn´t openlayers support the env parameter?
I used this example http://docs.geoserver.org/latest/en/user/styling/sld-extensions/substitution.html

The problem is that I have to style a wms based on features that occured within the last 24 hours and 4 days, so I have to pass the exact timestamps.

Best Answer

Try this...

var wmsSource = new ol.source.ImageWMS({
url: 'http://ip:port/geoserver/wms',
params: {'LAYERS': 'workspace:layername'/*,'ENV': 'key1:value1;key2:value2'*/},
serverType: 'geoserver',
crossOrigin: 'anonymous'});

var wmsLayer = new ol.layer.Image({
    source: wmsSource
});

wmsSource.updateParams({ENV:'key1:value1;key2:value2'});

//or another way is, you can specify it at the time 
// of source object creation in it's params.

You can get more information here:

https://docs.geoserver.org/latest/en/user/styling/sld/extensions/substitution.html