[OpenLayers-Users] WFS Filter Stragety?

Tim Schaub tschaub at opengeo.org
Wed Feb 18 18:59:22 EST 2009


Hey-

HKChad wrote:
> I need to append an &filter= param to my WFS queries. I've already been down
> the road of using OpenLayers.Layer.WFS and learning that it appends &BBOX=
> to each query even if you have an &filter, and we all know that violates the
> WFS spec even though some servers support it, so I learned of the new,
> 
> new OpenLayers.Layer.Vector('bla', {
>                     strategies: [new OpenLayers.Strategy.BBOX()],
>                     protocol:bla,
> 
> way of doing things, and that got me right back to where I was (although a
> little slower, but Strategy.Fixed was nice and fast). So now I'm back to the
> point of where I want to send a filter. I don't see how do accomplish this.
> I looked through the BBOX strategy code and it references a filter but it
> appears it does a Logical AND and adds a BBOX onto that (which in some
> cases, I don't want). So 2 questions.
> 
> How can I send a pre-built filter to my WFS WITH OUT a BBOX

Currently, if you don't want a bbox, you would use the Fixed strategy. 
So, something like:

var strategy = new OpenLayers.Strategy.Fixed();
var layer = new OpenLayers.Layer.Vector({
     strategies: [strategy],
     protocol: new OpenLayers.Protocol.WFS(args)
});

// then, some time later when you want to filter
layer.protocol.read({
     filter: new OpenLayers.Filter.Comparison(args),
     callback: strategy.merge,
     scope: strategy
});

So, the idea was (and is) to have something like 
layer.setFilter(filter).  This would set layer.filter and call 
layer.refresh().  Appropriate strategies (like fixed) would listen for 
the refresh event and pass the filter along to the protocol.  This would 
make a good patch.

> and how can I send one WITH a bbox.

In this case, you use a BBOX strategy.  Then you manually set 
layer.filter and call layer.refresh().  The bbox strategy listens for 
refresh and looks for the filter.

Tim

> 
> thanks!
> -chad


-- 
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.



More information about the Users mailing list