Reputation:
I'm trying to refresh a single WMS layer source. Goal is to use a parameterized SLD with different thresholds. Points are drawn with different size and colour depending on these values.
var source = new ol.source.TileWMS({
url: 'http://localhost:8080/geoserver/Global/wms',
params: {
LAYERS: 'cities',
VERSION: '1.3.0',
CQL_FILTER: "ISO_A2 IN ('DE', 'FR', 'BE', 'PT', 'CZ', 'NL', 'ES', 'AT', 'CH', 'HU', 'PL', 'SE', 'NO', 'DK', 'IT', 'GB', 'IE')",
STYLES: 'ring_dynamic',
ENV: 'LOW_MAX:' + low_max + ';MED_MAX:' + med_max
}
})
After setting low_max and med_max parameters the layer should be reload to make the changes visible.
I've tried the following two statements but none of them worked.
source.changed();
source.dispatchEvent('change');
Using OpenLayers 3.6 and 3.6.
€dit: I use a jQueryUI-Slider to trigger the reload:
$(function() {
$( "#slider-range" ).slider({
range: true,
min: 0,
max: 5000000,
values: [ 500000, 2000000 ],
slide: function( event, ui ) {
$( "#grenzen" ).val( ui.values[ 0 ] + " - " + ui.values[ 1 ] );
low_max = ui.values[0];
med_max = ui.values[1];
source.changed();
source.dispatchEvent('change');
}
});
$( "#range_limits" ).val( $( "#slider-range" ).slider( "values", 0 ) +
" - " + $( "#slider-range" ).slider( "values", 1 ) );
});
This code is placed below the previously shown code.
Upvotes: 1
Views: 3904
Reputation: 144
I use openlayers v4.6.5 and I solved this problem like that
layerChanged(layer){
layer.getSource().clear();
layer.getSource().refresh();
}
Upvotes: 1
Reputation: 2126
Use updateParams on the source http://openlayers.org/en/v3.7.0/apidoc/ol.source.TileWMS.html#updateParams
Upvotes: 2