I have a filter control which works nicely. However, when I try to reset/remove the filter, I don't get the original features back. The debugger shows my features array as still only being the reduced number of features, yet shows the filter strategy as being inactive.

I set up the strategy on layer instantiation like this:

this.strategies = { 
    bbox: new OpenLayers.Strategy.BBOX(),
    filter: new OpenLayers.Strategy.Filter(),

// initialisation stuff here ...

layer = new OpenLayers.Layer.Vector(
    this.layerName, {
        projection: this.projection,
        strategies: [            
        protocol: protocol,
        styleMap: styleMap,

I set the filter like this:

filter: function () {

    var olLayer = this.olLayer;
    var attribute = document.getElementById
        ( "layer-search-attribute" ).value;
    var value = document.getElementById( "layer-search-value" ).value;
    var type = OpenLayers.Filter.Comparison.LIKE;
    var filter = new OpenLayers.Filter.Comparison({
        type: type,
        property: attribute,
        value: value,

    this.strategies.filter.setFilter( filter );

    // back to the map page
    $.mobile.changePage( "#mappage" );
}, // end filter ()

And I remove it like this:

resetFilter: function () {
    console.log("Removing filter on:", this.layerName );
    var olLayer = this.olLayer;


    // back to the map page
    $.mobile.changePage( "#mappage" );
}, // end resetFilter ()

I've also tried olLayer.refresh({ force: true }) without success.


should work

I use a WFS-Layer for filtering:

var filterStrategy = new OpenLayers.Strategy.Filter();

var layer = new OpenLayers.Layer.Vector("WFS", {
        strategies: [filterStrategy]

To reset the filter I just use


and this works well. You could of course also set a filter that will give you back all your features and pass this filter to filterStrategy.setFilter().

For further information see http://dev.openlayers.org/apidocs/files/OpenLayers/Strategy/Filter-js.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.