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 want to select polygons in wms/wfs layers (openlayes). I used the code of this example . Then, when I select a polygon in my the layer, nothing is selected, I don't no why. Could you help me please. Thanks

Here is the code :

WFS: GetFeature Example (GeoServer) var map, layer, select, hover, control;

    function init(){
        //OpenLayers.ProxyHost= "";
        //OpenLayers.ProxyHost= "proxy.cgi?url=";
        map = new OpenLayers.Map('map', {
            controls: [
                new OpenLayers.Control.PanZoom(),
                new OpenLayers.Control.Permalink(),
                new OpenLayers.Control.Navigation()
        layer = new OpenLayers.Layer.WMS(
            "States WMS/WFS",
            {layers: 'usa:states', format: 'image/gif'}
        select = new OpenLayers.Layer.Vector("Selection", {styleMap: 
            new OpenLayers.Style(["select"])
        hover = new OpenLayers.Layer.Vector("Hover");
        map.addLayers([layer, hover, select]);

        control = new OpenLayers.Control.GetFeature({
            protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layer),
            box: true,
            hover: true,
            multipleKey: "shiftKey",
            toggleKey: "ctrlKey"
        });"featureselected", this, function(e) {
        });"featureunselected", this, function(e) {
        });"hoverfeature", this, function(e) {
        });"outfeature", this, function(e) {

        map.setCenter(new OpenLayers.Bounds(-140.444336,25.115234,-44.438477,50.580078).getCenterLonLat(), 3);

WFS GetFeature Example (GeoServer) WFS, GetFeature Shows how to use the GetFeature control to select features from a WMS layer.

Click or drag a box to select features, use the Shift key to add features to the selection, use the Ctrl key to toggle a feature's selected status. Note that this control also has a hover option, which is enabled in this example. This gives you a visual feedback by loading the feature underneath the mouse pointer from the WFS, but causes a lot of GetFeature requests to be issued.

share|improve this question

you should set up a ProxyHost for getting information from remote server...more information is here...

OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

i hope it helps you...

share|improve this answer
Thanks for your answer. All the data I'm using is in computer, so do I need to set up a ProxyHost? I'm afraid I don't understand what does proxyhost mean? – hnahoulder Jun 7 '12 at 10:08
i gave this answer to above code you shared. if you work remote server you have to set up a proxy for retrieving data.. – Aragon Jun 7 '12 at 10:27

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.