I have a OpenLayers map that displays a few WMS layers on top of an Open Street Map base layer. I'm would like the county boundary WMS layer to display automatically along with the base layer when the map loads.

var map;
function initMap() {
    var osmlayer;
    var point;
    var dlr_county_boundaries_wms;
    var dlr_libraries_wms;
    var info;

    //create new map object
    map = new OpenLayers.Map("mymap");

    //create new OSM base layer
    osmlayer = new OpenLayers.Layer.OSM("Open Street Map");

    //create WMS layers
    dlr_county_boundaries_wms = new OpenLayers.Layer.WMS("DLR County Boundary (WMS)", "http://localhost:8080/geoserver/egm715/wms",
        layers: "egm715:DLR_County_Boundary",
        transparent: true
        }, {
        projection: "EPSG:3857",
        opacity: 0.5,
        visibility: false

    // DLR Libraries Layer
    dlr_libraries_wms = new OpenLayers.Layer.WMS("DLR Libraries (WMS)", "http://localhost:8080/geoserver/egm715/wms",
        layers: "egm715:DLR_Libraries",
        transparent: true
        }, {
        projection: "EPSG:3857",
        opacity: 0.5,
        visibility: false

//add layers to the map
map.addLayers([osmlayer, dlr_county_boundaries_wms, dlr_libraries_wms]);

//add LayerSwitcher control object
var custom_layerswitcher= new OpenLayers.Control.LayerSwitcher();

// change Labels of Base- and Overlay-Section
custom_layerswitcher.dataLbl.innerHTML="DLR Layers";
    // define point as a new LonLat object and transfom
    point = new OpenLayers.LonLat(-6.1832, 53.2560); 
    point.transform("EPSG:4326", "EPSG:900913");
    //centre the map and set zoom level
    map.setCenter(point, 11.7);

  • What is the problem with your code? What is not working?
    – chrki
    Apr 16, 2017 at 6:09
  • Hi chrki the code works, I'm looking for some help on how to make the dlr_county_boundary_wms layer display automatically along with the base layer rather than in the layerswitcher.
    – Dakan_GIS
    Apr 16, 2017 at 9:34

1 Answer 1


I have no experiences with openlayers 2 but the example and documents provided pointed out what you might want to do.

First, to display your boundary layer dlr_county_boundary_wms by default, you have to set the visibility of this layer to be true.

Then, refering to the source of the layer switcher example at line 21:

    var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
        {layers: 'basic'}, {'displayInLayerSwitcher':false} );

you may want to set the displayInLayerSwitcher property to be false to hide it from the layer switcher.


Your Answer

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

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