Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I added 4 WMS layers (three polygons and one have point geometry) from GeoServer on my webpage

My requirement is:

  1. I have to select a single polygon of one wms layer using a mouse click. After the selection, the polygon color should be changed. If you select another polygon, the previous selected polygon color is to be changed to original color.

  2. If I select a polygon of one wms layer, I want to get the NAME of the selected polygon as an alert.

Any help is greatly appreciated..

Thank you..

layer = new OpenLayers.Layer.WMS(

 "Layer", "http://********:8080/geoserver/POC/wms",

                LAYERS: 'POC:CIRCLE_VIEW',
                STYLES: '', 
                wrapDateLine: true, 
                format: format,

               singleTile: true, 
               ratio: 1, 
               isBaseLayer: false,
               yx : {'EPSG:42106' : false}




I added four layers in this way..

var infoControls = {
         click: new OpenLayers.Control.WMSGetFeatureInfo({
             url: 'http://********:8080/geoserver/POC/wms', 
             title: 'Details',
             layers: [layer,layer2,layer3,layer4],
             queryVisible: true
         hover: new OpenLayers.Control.WMSGetFeatureInfo({
        url: 'http://********:8080/geoserver/POC/wms',
             title: 'Details',
           layers: [layer,layer2,layer3,layer4],
             hover: true,
             queryVisible: true
    for (var i in infoControls) 

        infoControls[i].events.register("getfeatureinfo", this, showInfo);
function showInfo(evt) {
            if (evt.features && evt.features.length) {

            } else {
                document.getElementById('responseText').innerHTML = evt.text;

In this I am showing attribute data of selected polygon.

share|improve this question
can you show us what you have tried so far? – iant Jun 27 '13 at 5:55
I edited the question , check it once – Arun Jun 27 '13 at 6:09
up vote 1 down vote accepted

The WMS specification does not provide a function to select features and/or colorize them by selection. It only provides pretty dumb map images. With GetFeatureInfo you only can query what is under a specific coordinate / pixel, to get the attributes of the feature which was used to render the map image.

For a select features function you also have to use a WFS Service in the background additionaly to the WMS which is used to render a nice looking map.

EDIT: Yes you are right, it IS possible to hack around with Styled Layer Descriptors and GetFeatureInfo Requests to emulate a Feature Highlight only with WMS. Actually I don't know what are the disadvantages of this hack, if there are any, but what I can say is, that the WMS protocol was not intended to perform this (mind that every selection triggers a new rendering of the map image on the server). Selecting and Querying of vector data is the main reason for the WFS specification. Check out this stable example on the OpenLayers page

share|improve this answer
Thank you ver much.. I will try to use WFS Service.. Could u please share the link of WFS service example – Arun Jun 27 '13 at 6:34 But, in this example he is using WMS service only.. Please check the example – Arun Jun 27 '13 at 6:35
modified my answer to cover SLD Select. Would be nice to know if this hack fits all your needs (do you get back a selection set for further actions on it for example?) – Jürgen Zornig Jun 27 '13 at 10:40
Jürgen Zornig-- I tried with the example u shown, it is working when I have one layer. But I have 4 layers. I want to switch the control from one layer to other at a time.. Please do some help.. Thank u – Arun Jun 27 '13 at 12:44
Now we get in the pitfalls of Openlayers, I have to say that I am also very often messing around with these ones. There is a MultiLayer Selection example in Openlayers which uses the SelectControl and just adds more layers to it, while the WFS Selection example does not make use of this control. I only can guess, that the solution is to just make Layers out of your WFS services and add them to a SelectionControl. Unfortunately I don't really know if that works. :( – Jürgen Zornig Jun 27 '13 at 12:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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