0

I have two WMS layers Martello_Towers and Martello_Towers_Range. Rather than have two options in Layerswitcher I would like one option to control both layers. They are both in the same projection. I've tried obvious things like layers: "egm715:DLR_Martello_Towers" + "egm715:DLR_Martello_Towers_Range", or trying to combine them in a variable.

I've seen the solution at Working example to group layers in LayerSwitcher of OpenLayers 2? But grouping them isn't what I'm after.

// Martello Towers
    dlr_martello_towers_wms = new OpenLayers.Layer.WMS("DLR Martello Towers", "http://localhost:8080/geoserver/egm715/wms",
        {
        layers: "egm715:DLR_Martello_Towers",
        transparent: true
        }, {
        projection: "EPSG:3857",
        opacity: 0.7,
        visibility: false
        }
    );
    dlr_mtowers_range_wms = new OpenLayers.Layer.WMS("DLR Martello Towers Firing Range (WMS)", "http://localhost:8080/geoserver/egm715/wms",
        {
        layers: "egm715:DLR_Martello_Towers_Range",
        transparent: true
        }, {
        projection: "EPSG:3857",
        opacity: 0.4,
        visibility: false
        }
    );
  • Put it to send a comma separated list as "layers". – user30184 Apr 29 '17 at 17:05
  • Hi user30184, can you let me know what you mean? – Dakan_GIS Apr 29 '17 at 17:59
1

If you want to show those two layers always together then just ask the WMS server to send them together. Order of layers in the list matters. The first layer is rendered first the following one on top of that. About like this

   // Martello Range and Towers
        dlr_martello_range_and_towers_wms = new OpenLayers.Layer.WMS("DLR Martello Towers", "http://localhost:8080/geoserver/egm715/wms",
            {
            layers: "egm715:DLR_Martello_Towers_Range,egm715:DLR_Martello_Towers",
        transparent: true
        }, {
        projection: "EPSG:3857",
        opacity: 0.7,
        visibility: false
        }
    );
  • Thanks user30184. that worked great. I forgot to add the 'egm715' bit. Thanks. – Dakan_GIS Apr 30 '17 at 8:35

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.