0

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();
map.addControl(custom_layerswitcher);

// change Labels of Base- and Overlay-Section
custom_layerswitcher.dataLbl.innerHTML="DLR Layers";
custom_layerswitcher.baseLbl.innerHTML="Basiskarten";
    // 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 '17 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 '17 at 9:34
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",
        "http://vmap0.tiles.osgeo.org/wms/vmap0",
        {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, privacy policy and cookie policy

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