Search code examples
javascriptopenlayers-3

How to refresh a WMS layer in OpenLayers 3?


I have a wms layer, created like so:

layer = new ol.layer.Tile({
  visible: true,
  source: new ol.source.TileWMS({
      url: 'http://localhost:8085/geoserver/accent/wms',
      params: {
          'FORMAT': 'image/png', 
          'VERSION': '1.1.1',
           tiled: true,
           STYLES: '',
           LAYERS: 'accent:layer_' + layer_id + '_',
           tilesOrigin: 0 + "," + 0.0000000000014415
      }
   })
});

I have some buttons in my application, that enable to change the layer store (make a shift, increase number of levels for tiles etc.). So, to make these changes visible, I need a method to "refresh" the layer, so that it would make server requests and redraw itself. It seems, like in old OL2 there was a nice method:

myWMSLayer.redraw(true);

But I do not know how can I achieve the same effect in OL3. Thanks!


Solution

  • To achieve that, you can use the updateParams on the layer source

    var params = layer.getSource().getParams();
    layer.getSource().updateParams(params);