[OpenLayers-Users] CQL_FILTER works but click also gives popup of hidden/filtered markers

Asle Benoni asle.benoni at gmail.com
Wed May 30 11:54:59 PDT 2012


Not sure if this is correctly posted here or on the GeoServer list but
I will try!
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. Is it possible to only have the filtered markers give a popup?
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!

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

            info = new OpenLayers.Control.WMSGetFeatureInfo({
            url: 'http://kart.naturkart.no/geoserver/wms',
            title: 'Identify features by clicking',
            queryVisible: true,
            infoFormat:'application/vnd.ogc.gml',
            eventListeners: {
                getfeatureinfo: function(event) {
                    if (popup) {
                        map.removePopup(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
                                var locality = feature.attributes['locality'];
                                country = feature.attributes['country'];
                                scientificname =
feature.attributes['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" />';
                                contentHtml = contentHtml + '<h2>' +
scientificname +' '+ statusimg + '</h2>';
                                contentHtml = contentHtml +
norsknavnart + norsknavngruppe + ' Reg.dato: ' + dateinterval + '<br
/>';

                                contentHtml = contentHtml + kommentar
+ ' Reg. av: ' + collector + '<br />';
                                                          contentHtml
= contentHtml + '<span class="popItem"><a
href="http://babkart.no/?x='+feature.attributes['x']+'&y='+feature.attributes['y']+'">Direkte
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(
                            "chicken",
                            map.getLonLatFromPixel(event.xy),
                            null,
                            contentHtml,
                            null,
                            true
                            );
                    popup.autoSize = true;
                    map.addPopup(popup, true);
                    Ext.ux.Lightbox.register("a[rel^=lightbox]",true);
                }
            }
        });
        map.addControl(info);
        info.activate();


More information about the Users mailing list