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 am a newbie and I am using OpenLayers, GeoServer 2.1.3. I have a function that works to filter the markers on the map with a CQL_FILTER function. But when I click on a marker it shows a popup with featureInfo information. If there are hidden markers on the same coordinate (from the CQL_FILTER function) every marker shows a popup, even if I have filtered them out (I thought until now that is!) .

So I expect after what I have researched that I also need to filter the getFeatureInfo click that sends the cql_filter with the WMS call. The markers are on the same layer but I only want a popup to fire on the filtered markers. Any advice to where I start would be be appreciated. Here is my function that redraws the layers with the params from a search box. So how do I use this also in my click event?

function CQLfilter(sok,cat){
var mLayers = map.layers;
switch (cat)
case 'SN':
 param = "scientificname LIKE '%"+ sok + "%' ";
case 'NNG':
 param = "norsknavngruppe LIKE '%"+ sok + "%' ";
case 'NNA':
 param = "norsknavnart LIKE '%"+ sok + "%' ";
case 'PROJ':
 param2 = new Array()
 param2.push("prosjektnummer LIKE '%" + sok + "%'")
 param2.push("prosjektnavn LIKE '%" + sok + "%'")
 param = param2.join(" OR ");
 param2 = new Array()
 param2.push("scientificname LIKE '%" + sok + "%'")
 param2.push("norsknavngruppe LIKE '%" + sok + "%'")
 param2.push("norsknavnart LIKE '%" + sok + "%'")
 param2.push("collector LIKE '%" + sok + "%'")
 param = param2.join(" OR ");
for(var a = 4; a < (mLayers.length); a++ ){
 mLayers[a].mergeNewParams({'CQL_FILTER': param});

Here is my code that generates the popup and the wmsGetFeatureInfo. I guess it is here I must also do some kind of filtering on the wms request but not sure how to do it. How and where do I use the code from the CQLfilter function?

         info = new OpenLayers.Control.WMSGetFeatureInfo({
         url: '',
         title: 'Identify features by clicking',
         queryVisible: true,
         eventListeners: {
             getfeatureinfo: function(event) {
                 if (popup) {
                 var contentHtml = '';
                 // Manage the features
                 if (event.features.length > 0) {
                     for (var i = 0; i < event.features.length; i++) {
                         var feature = event.features[i];
                         // Identify the type
                         if (feature.gml.featureType ==
'ikke_rodlistet' || feature.gml.featureType == 'kritisk_truet' ||
feature.gml.featureType == 'nar_truet' || feature.gml.featureType ==
'regionalt_utdodd' ||
                                 feature.gml.featureType == 'saarbar' ||
                                 feature.gml.featureType == 'sterkt_truet') {
                             // Create HTML content for this feature type
                             // Fetch the feature attributes and some
conditional output of the popup - could be useful to someone :-)
                             var locality = feature.attributes['locality'];
                             country = feature.attributes['country'];
                             scientificname =
                             kingdom = feature.attributes['kingdom'];
                             norsknavnart =
feature.attributes['norsknavnart']!= null ?
feature.attributes['norsknavnart'] + ' | ':'';
                             norsknavngruppe =
feature.attributes['norsknavngruppe']!= null?
feature.attributes['norsknavngruppe'] + ' | ':'';
                             collector =  feature.attributes['collector'];
                             kommentar =
feature.attributes['kommentar']!= null?
feature.attributes['kommentar'] + ' | ':'';
                             dateinterval = feature.attributes['dateinterval'];
                             status = feature.attributes['status'];
                             statusimg = '<img
src="/images/svg/bab_'+status+'.svg" width="10" />'; // Conditionally
show a (status) icon in the popup
                             contentHtml = contentHtml + '<h2>' +
scientificname +' '+ statusimg + '</h2>';
                             contentHtml = contentHtml +norsknavnart
+ norsknavngruppe + ' Reg.dato: ' + dateinterval + '<br/>';
                             contentHtml = contentHtml + kommentar +
' Reg. av: ' + collector + '<br />';
                             contentHtml = contentHtml + '<span
link</a> til dette artsfunn.</span><hr />';
                 } else {
                     // Don't show any popup if no features.
                     return; alert(map.getLonLatFromPixel(event.xy));
                 var popup = new Popup(
                 popup.autoSize = true;
                 map.addPopup(popup, true);

~asle benoni

share|improve this question
Not sure what you mean. Does this affect if people answer or not? – asle Jun 1 '12 at 8:14
see the FAQ ( - basically you have a zero accept rate which means that you ask questions but don't accept the answers, which means you haven't rewarded anyone for answering your previous questions. Given limited time people will tend to skip people who don't reward their work. – iant Jun 1 '12 at 8:23
Sorry, I was really not sure how to do that. I am learning this also. – asle Jun 1 '12 at 14:47
up vote 2 down vote accepted

did you pass the CQL filter to the WMS GetFeatureInfo request too? If not then any record in the whole dataset at that location will be returned.

share|improve this answer
Not sure what you mean. How would NOT the whole dataset be queried? See the CQL function above. – asle May 30 '12 at 15:11
I think I understand more now. Am I correct when I find that I must also edit my OpenLayers.Control.WMSGetFeatureInfo so that the click also sends a filter to GeoServer asking only for certain markers? Can you check my code above and give me some advice? – asle May 30 '12 at 18:48
Yes, that's the point. Changes to the CQL of a layer does not automagically reflect themselves to the WMSGetFeatureInfo control. So, you have to apply the new CQL filter to the GetFeatureControl as well – atlefren May 31 '12 at 6:19
Any suggestion as to how I add the CQL params to my code? I tried some stuff did not work. I tried it in the block: "info = new OpenLayers.Control.WMSGetFeatureInfo({... ,cql_filter:'navn like "%han%"..." This had no effect. Does not seem to be many examples as to how to do this or the correct syntax in my solution. Any help in right direction is appreciated! – asle May 31 '12 at 6:59
@iant - how do you pass the CQL filter to the WMS getFeatureInfo function? Any examples? Thanks! – asle Jun 1 '12 at 8:15

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.