[GIS] MapServer WMS background color in OpenLayers 3

mapserveropenlayersstylewms

I am using MapServer to render a number of layers and then I'm setting it up as a WMS server in order to render it using OpenLayers 3. I want the background color of the image to be grey so I set it with the following snippet:

MAP
 EXTENT 300000.000 4374000.000 316000.000 4386000.000
  UNITS meters
  SIZE 900 580
  IMAGETYPE png
  IMAGECOLOR 240 237 229
  ...

So in CGI mode it behaves as expected rendering the background as grey. However the same does not happen with OpenLayers. I'm setting params to render it as 'image/png':

var params = {
            LAYERS : 'layer1, layer2,layer3...layerN',
            FORMAT : 'image/png'
     }

Setting FORMAT as 'image/png' makes the background color white instead of the grey I want. If I set FORMAT as 'image/jpeg' the the background color turns to total black. So how can I keep the same grey color using OpenLayers?

Which format do I need to use?

Best Answer

By default, areas outside of the layers of a WMS are set as transparent by OpenLayers.

So add this:

var params = {
   transparent : false   
 }

in your variable params. Works for me.

J.