Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I use Geoserver to get my WMS data. Everything works great for showing data in openlayers.

Geoserver has the ability to create sql views and use parameters to return certain geometry. These parameters are called viewparams. This could be an example of a sql view:

select *
from myTable
where age = %ageParam%

When using viewparams you are able to pass the value for the 'ageParam' parameter. If a parameter is not set, a predefined default value will be used. More information about this topic can be found here.

In openlayers however, "getFeature" control does not take the 'viewparams' parameter into account. This means it always returns features with the default parameter values.

Is this a bug, a missing feature or something I just missed.

Edit1

Here is a screencast I made to visualise the problem.

http://screencast.com/t/RgrQvaoyoqz

As you can see, the layer is redrawn with new points but the selectFeature control still returns the old features.

Edit2

<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:Query typeName="test:point_query" xmlns:test="http://test.boedy.p:8080/wms">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:BBOX>
<ogc:PropertyName>geometry</ogc:PropertyName>
<gml:Envelope xmlns:gml="http://www.opengis.net/gml">
<gml:lowerCorner>490488.82657346 6800062.1058854</gml:lowerCorner>
<gml:upperCorner>491071.65891403 6800556.5579121</gml:upperCorner>
</gml:Envelope>
</ogc:BBOX>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>

edit3

This is the javascipt code for the layer and controller

test = new OpenLayers.Layer.WMS("test",
    "http://test.boedy.p:8080/wms", 
    {
        'layers': 'test:test_query',
        viewparams: 'x:'+myX+';y:'+myY,
        maxfeatures: 2000,
        ratio: 1,
        transparent: true,
        isBaseLayer: false}
    );

selectCtrl = new OpenLayers.Control.GetFeature(
        {
            protocol: OpenLayers.Protocol.WFS.fromWMSLayer(test),
            clickout: true, toggle: false,
            multiple: false, hover: false,
            box: true,
            toggleKey: "shiftKey", // ctrl key removes from selection
            multipleKey: "shiftKey",
            eventListeners: {
                featureselected: onFeatureSelect,
                featureunselected: onFeatureUnselect
            }
        }
    );
share|improve this question
    
can you post an example url? –  iant Oct 26 '11 at 15:29
    
Please don't put tags in the title. –  underdark Oct 26 '11 at 21:46
    
@iant I can't give you an example url, because It's still in development and only locally accessible. I've added a short video displaying the problem instead. I hope that's of some use. –  Boedy Oct 27 '11 at 7:16
    
@underdark Thanks, I'll keep that in mind –  Boedy Oct 27 '11 at 7:17
    
I meant could you post an example of the URL that is being sent by the client (preferably to a default layer) so we can try to reproduce the problem locally. –  iant Oct 27 '11 at 7:34
show 5 more comments

1 Answer

Looking at the source of the WFS.fromWMSLayer function, it looks like you should pass in your viewparams as an additional option:

        protocol: OpenLayers.Protocol.WFS.fromWMSLayer(test, 
                                                       {viewparams: 'x:'+myX+';y:'+myY}),

Check the URL that is called when you select a feature - and hopefully the viewparams will be added to the URL.

If you wanted to apply a filter to a WFS layer you can play around with the filter code and the XML it generates on this demo.

Once you have the filter code correct then set the WFS layer's filter filter property.

        wfsLayer.filter = my_filter;

As you don't have a WFS layer you could try the following - the parameters may be copied across - you'd have to test.

        protocol: OpenLayers.Protocol.WFS.fromWMSLayer(test, 
                                                       {filter: my_filter}),
share|improve this answer
    
This doesn't seem to have any effect. I'm doubting if this is possible in openlayers or with the WFS protocol at all. I was able to get viewparams working with WMS, but not with WFS. –  Boedy Oct 28 '11 at 10:22
    
To clarify - the viewparams need to be sent as part of the URL or as part of the OGC Filter XML for it to work correctly? –  geographika Oct 28 '11 at 10:24
    
I'm not sure. I'm guessing it should be a part of the payload/OGC Filter. Geoserver suggests it's possible with WFS, but doesn't give an example on it's usage. –  Boedy Oct 28 '11 at 11:06
    
Are you suggesting I should switch to filters? So instead of filtering via sql use an openlayers filter? –  Boedy Oct 28 '11 at 13:52
    
An OL filter is simply XML that is sent to the server where the actual filtering occurs. OL itself doesn't filter the features. –  geographika Oct 28 '11 at 14:11
show 2 more comments

Your Answer

 
discard

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.