OpenLayers 2 is outdated. Go to the latest 3.x version:

WMS Layer

Three args to constructor:

  • name -- used for display purposes
  • url -- URL of WMS Service
  • params -- {param:'name'} style list of parameters. Via this setting, you can also override existing settings, such as the format. All params are forced to uppercase. Default parameters are:
    DEFAULT_PARAMS: { SERVICE: "WMS",                                              
     VERSION: "1.1.1",                                            
     REQUEST: "GetMap",                                           
     STYLES: "",                                                  
     EXCEPTIONS: "application/vnd.ogc.se_inimage",                
     FORMAT: "image/jpeg"                                         

Typically, the one people want to edit most is the 'format' attribute.

Full params example:

  layer = new OpenLayers.Layer.WMS( "My WMS", 
		                    {layers: 'layer1,layer2,layer3','VERSION': "1.1.1",'units': 'meters'},
                                    {'maxExtent': new OpenLayers.Bounds(minx,miny,maxx,maxy),'maxResolution': "auto"} 

Multiple URLs example:

  var urlArray = ["",

  layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
                                    {layers: 'basic'} );
Last modified 8 months ago Last modified on May 20, 2016 12:07:01 AM