[GIS] How to show/hide labels with mapserver and openlayers

ext-jsgeoextlabelingmapserveropenlayers-2

I'd like to have a check/uncheck option like this print checkbox to show/hide labels in my WMS layers served by mapserver 5.6.7 in openlayers 2.11. I have a toolbar where to put this using probably geoext1 or ext3.4, so the questions:

  1. Is this possible?
  2. If so, how can it be done?

Best Answer

Regarding the comment about two separate labels (one for the "rest of the map" and one for the labels): this is what I thought of as well, and it should be fairly easy to implement:

var url = "http://myserver.com/wms";

var background = new OpenLayers.Layer.WMS(
    "Base Map",
    url, 
    {layers: 'background'} 
);

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

map.addLayers([background, layer]);

function toggleLabels() {
    var was = labels.getVisibility();
    labels.setVisibility(!was);
}
Related Question