[OpenLayers-Users] How to use CQL filter in OpenLayers.Control.WMSGetFeatureInfo?

Asle Benoni asle.benoni at gmail.com
Sun Jun 10 04:11:00 PDT 2012


Just another question also. I still have not got this filtering to work
even if I see the cql_filter params in the WMS request. I wonder also since
I generate a variable every time a search is done. Will the newest search
params be used on the WMS.getFeatureInfo or do I in some way have to push
the new variable to the WMS.getFeatureInfo. I guess the javascript is read
once when the page is loaded. I.ex. I use  this function

var filter_param = param;
 info = new OpenLayers.Control.WMSGetFeatureInfo({....
...
vendorParams:{
                    CQL_FILTER:filter_param

                    }, ......

Will each click use the new updated "param" or just use the one defined
upon page load?

~asle

2012/6/9 Asle Benoni <asle.benoni at gmail.com>

> Thanks. I tried this code:
>
> vendorParams:{
>                     CQL_FILTER:filter_param
>                     },
>
> But then the popups do not fire and I get this error in Firebug:
>
> Layers and filters are mismatched, you need to provide one filter for each layer
>
> So I am still doing something wrong?
>
> ~asle
>
> 2012/6/9 Dominik Mikiewicz <dominikmikiewicz at o2.pl>
>
>> Geoserver uses cql_filter as far as I remember. Try replacing
>> filter_param with cql_filter and you should be ok****
>>
>> ** **
>>
>> *From:* openlayers-users-bounces at lists.osgeo.org [mailto:
>> openlayers-users-bounces at lists.osgeo.org] *On Behalf Of *Asle Benoni
>> *Sent:* Saturday, June 09, 2012 1:13 PM
>> *To:* Ignacio Talavera
>> *Cc:* openlayers-users at lists.osgeo.org
>> *Subject:* Re: [OpenLayers-Users] How to use CQL filter in
>> OpenLayers.Control.WMSGetFeatureInfo?****
>>
>> ** **
>>
>> Thank you for putting me in this direction.
>> I get an error with your suggested code. ****
>>
>> missing ; before statement****
>>
>> var filter_param["cql_filter"] = "norsknavngruppe LIKE '%Sopp%';****
>>
>> So I tried this:****
>>
>>
>>           *var filter_param = "norsknavngruppe LIKE '%Sopp%'";*
>>                    info = new OpenLayers.Control.WMSGetFeatureInfo({
>>                    url: 'http://kart.naturkart.no/geoserver/wms',
>>                    title: 'Identify features by clicking',
>>                    queryVisible: true,
>>                    infoFormat:'application/vnd.ogc.gml',
>>                    *vendorParams:{
>>                    filter_param:filter_param
>>                    },*
>>                    eventListeners: {
>>                        getfeatureinfo: function(event) {
>>                            if (popup) {
>>                                map.removePopup(popup);
>>                            } .........****
>>
>> ** **
>>
>> I get no error and I see (in Firebug) that this is added to the WMS
>> request:****
>>
>>
>> &info_format=application%2Fvnd.ogc.gml&filter_param=norsknavngruppe%20LIKE%20'%25Sopp%25'
>> ****
>>
>> Still I get no filtering of the popups and it shows any data that is in
>> the clicked location. I see that the response contains i.ex.****
>>
>> <gbif_ns:norsknavngruppe>Lav</gbif_ns:norsknavngruppe>****
>>
>> and it should not be included since I only want "norsknavngruppe LIKE
>> '%Sopp%". ****
>>
>> Is there something wrong with my code? Thanks for any suggestions!****
>>
>>
>>
>> 2012/6/8 Ignacio Talavera <ignacio.talavera at gmail.com>:
>> > Hi the WMSGetFeatureInfo manage additionals parameters of the url of the
>> > GetFeatureInfo Request in  vendorparams attribute.
>> > So try to add this to your code
>> >
>> > var filter_param["cql_filter"] = prosjektnummer LIKE '%2008-25%' OR
>> > prosjektnavn LIKE '%2008-25%
>> > info = new OpenLayers.Control.WMSGetFeatureInfo({
>> >                    url: 'http://kart.naturkart.no/geoserver/wms',
>> >                    title: 'Identify features by clicking',
>> >                    queryVisible: true,
>> >                    infoFormat:'application/vnd.ogc.gml',
>> >                    vendorParams:filter_param
>> > eventListeners: {
>> >                        getfeatureinfo: function(event) {
>> >                            if (popup) {
>> >                                map.removePopup(popup);
>> >                            } ........................
>> > I hope this is useful to you.
>> > Regards
>> > Nacho
>> > On Thu, Jun 7, 2012 at 11:48 AM, Asle Benoni <asle.benoni at gmail.com>
>> wrote:
>> >>
>> >> I have made this map: www.babkart.no
>> >>
>> >> I have a search box that on select of the results sends a refresh of
>> >> the layer with CQL parameters to GeoServer. This works.
>> >> But of course when I click I get popups of all the markers, even if
>> >> they are hidden because I understand that I send a WMS request without
>> >> any filter.
>> >>
>> >> So I need help how to use the generated CQL params in my WMS request
>> >> for GetFeautureInfo to GeoServer.
>> >>
>> >> My function CQLfilter in app.js on line 1027 produces this link:
>> >> prosjektnummer LIKE '%2008-25%' OR prosjektnavn LIKE '%2008-25%
>> >> which I use to filter the map.
>> >>
>> >> The question is how I can use this (or IF I can use it!) in my
>> >> function (line 907):
>> >>
>> >> 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);
>> >>                            } ........................
>> >>
>> >> Any ideas on how to use the CQL code here?
>> >>
>> >> ~asle
>> >> _______________________________________________
>> >> Users mailing list
>> >> Users at lists.osgeo.org
>> >> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>> >
>> >****
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120610/ae575bc3/attachment.html>


More information about the Users mailing list