2

I have made a WMS layer using Openlayers2 and Geoserver and I display the layeer using a specific CQL filter.

Now I want to use a WMSGetFeatureInfo request in order to get specific data on click. Although I use the CQL parameters in my WMSGetFeatureInfo request nothing seems to change and I get back all the results.

This is my code:

First I create the layer and added to the map:

        cql = "ftth_pop='"+ area+"' AND simul_desc='"+simulation+"'";
        layerName2 = 'ngn_marco:out_ducts';
        wms =  new OpenLayers.Layer.WMS("wms","http://ngn-marco.enomix.gr/geo_wms/",
                {
                    layers: layerName2,
                    format:  "image/png",
                    transparent: true,
                    version: "1.1.1",
                    CQL_FILTER: cql,
                    tiled: true 
                },
                {
                    format: "image/png",
                    displayOutsideMaxExtent: false,
                    projection: new OpenLayers.Projection("EPSG:900913"),
                    visibility: true
                }
        );  

       map.addLayer(wms);

Then I make the WMSGetFeatureInfo request:

      infoControls = {
        click: new OpenLayers.Control.WMSGetFeatureInfo({
            url: 'http://ngn-marco.enomix.gr/geo_wms/', 
            title: 'Identify features by clicking',
            layer: wms,
            CQL_FILTER: cql,
            queryVisible: true
            })
        };

I add the control and activate it as:

    for (var i in infoControls) { 
        infoControls[i].events.register("getfeatureinfo", this, showInfo);
        map.addControl(infoControls[i]); 
    }

    infoControls.click.activate();

The showInfo() function is:

function showInfo(evt) {
        if (evt.features && evt.features.length) {
            highlightLayer.destroyFeatures();
            highlightLayer.addFeatures(evt.features);
            highlightLayer.redraw();
        } else {
            //console.log(evt.txt);
            document.getElementById('responseText').innerHTML = evt.text;
    }
    }

The problem is that the CQL filter for the WMSGetFeatureInfo request doesnt work.

EDIT

These are the parameters sent to Geoserver:

BBOX    2637105.178295,4616485.137413,2638971.913845,4617560.033123
FEATURE_COUNT   10
FORMAT  image/png
HEIGHT  900
INFO_FORMAT text/html
LAYERS  ngn_marco:out_ducts
QUERY_LAYERS    ngn_marco:out_ducts
REQUEST GetFeatureInfo
SERVICE WMS
SRS EPSG:900913
STYLES  
VERSION 1.1.1
WIDTH   1563
X   715
Y   325

And this is part of the response I get back:

  <html>
    <head>
     <title>Geoserver GetFeatureInfo output</title>
   </head>
   <style type="text/css">
table.featureInfo, table.featureInfo td, table.featureInfo th {
    border:1px solid #ddd;
    border-collapse:collapse;
    margin:0;
    padding:0;
    font-size: 90%;
    padding:.2em .1em;
}
table.featureInfo th {
    padding:.2em .2em;
    font-weight:bold;
    background:#eee;
}
table.featureInfo td{
    background:#fff;
}
table.featureInfo tr.odd td{
    background:#eee;
}
table.featureInfo caption{
    text-align:left;
    font-size:100%;
    font-weight:bold;
    padding:.2em .2em;
}

out_ducts fid ftth_pop simul_desc coverage id crossing ducts ductsdrop ductsdist ductsfeed

<tr>

 <td>out_ducts.1627932</td>    
  <td>ATH_69</td>
  <td>PtP_test_1</td>
  <td>100</td>
  <td>2657</td>
  <td>false</td>
  <td>3</td>
  <td>0</td>
  <td>3</td>
  <td>0</td>

  • does the getFeatureInfo request contain the CQL filter? if yes then we need to see the GeoServer log, if not then it is just an OpenLayers issue and you need to add some logging to your script – Ian Turton Feb 8 '16 at 13:01
  • Yes the getFeatureInfo contains the CQL filter (its in the code above). And the geoserver log doesn't have an error. I was wondering perhaps my showInfo function might has some issue. – user1919 Feb 8 '16 at 13:08
  • 1
    please use the edit button to modify your question with examples of the url requested and the response sent back – Ian Turton Feb 8 '16 at 13:21
  • 1
    Please edit the title into something like "How to add CQL filter into GetFeatureInfo request in OpenLayers" because CQL filter does work if it is applied. – user30184 Feb 8 '16 at 13:36
  • 1
    I remember that it was a naming issue with the cql vendor parameter. Try to write it with lower case or test it also with one cql filter. Its something simply but I don't have the code right now to check how I fixed it! – user1919 Oct 11 '16 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.