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:

 EXTENT 300000.000 4374000.000 316000.000 4386000.000
  UNITS meters
  SIZE 900 580
  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?

  • With WMS you should be able to set the background color dynamically with &BGCOLOR parameter Hexadecimal red-green-blue color value for the background color (default=0xFFFFFF). See this answer gis.stackexchange.com/questions/20313/…. – user30184 Feb 6 '17 at 13:36

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.


  • Yup... !!! That's it..!!! I'ts working ^_^ Thank you – Stefanos Feb 6 '17 at 14:57
  • One more question, regarding the CRS of the WMS service: is there a default CRS (in OpenLayers case 3857) when you use your WMS service through OpenLayers? Cause I've set my mapfile with PROJECTION object to be "init=epsg:2100" and of course "wms_srs" to "EPSG:2100". However when I try to load it and examine the Network tab of the page, my WMS service is loaded with EPSG 3857. How's that possible ? – Stefanos Feb 6 '17 at 15:41
  • Indeed, it seems that OpenLayers set a default CRS of EPSG:3857. I tried to override this in the variable params by setting CRS : 'EPSG:2100' or even SRS: 'EPSG:2100' but it seems that OpenLayers ignored them. – juminet Feb 6 '17 at 16:41
  • So is there any solution to this? Because otherwise this means that if I have other data in another EPSG I cannot have them both in a View.., right? – Stefanos Feb 6 '17 at 17:46
  • Also is it just me or reprojecting a WMS service causes a bluring effect on the image ? – Stefanos Feb 7 '17 at 10:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.