7

I am using geoserver to serve up an image pyramid basemap. I want to have all areas outside of the data extent be black (instead of white).

I have the map displayed inside of a div tag and changing the css on that tag or the container (another div) it resides in has no effect. I have checked both the geoserver and openlayers documentation, but have not seen any way to change the background color.

Any suggestions on where to continue searching? Do I need to generate a black tiles and serve them?

2 Answers 2

13

In the definition of the WMS layer in your OpenLayers JavaScript code, you can specify the parameter bgcolor. This will eventually add the BGCOLOR parameter to the URL to the WMS service as explained already. For example:

var osm = new OpenLayers.Layer.WMS(
    "OpenStreetMap",
    url,
    {
        width: '600',
        height: '400',
        srs: 'EPSG:3857',
        layers: 'OpenStreetMap',
        styles: '',
        format: 'image/png',
        bgcolor: '0x80BDE3'
     },
     {
        singleTile: true,
        ratio: 1,
        visibility: true,
        isBaseLayer: true
    }
);
1
  • Spot on and a slightly more complete answer as someone might not be totally sure where to add the parameter. Thanks!
    – Jay Laura
    Commented Feb 17, 2012 at 0:54
9

You can set the background color in the WMS request, using the BGCOLOR param, with a hex value. Example: &BGCOLOR=0x000000

2
  • Is there a configuration parameter in geoserver like "wms_bgcolor" (metadata) in mapserver?
    – fherdom
    Commented Jan 20, 2017 at 9:36
  • 1
    @fherdom, no there isn't, that would probably violate the WMS specification (it states the background color is white unless explicitly indicated by the client) Commented Jan 25, 2017 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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