Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm developing an ExtJS3.4-GeoExt1-OpenLayers2.12 GIS application.

For basic functionality I need to filter layers to get specific data from a Geoserver WFS layer.

Filter is done through the variable myVar as a filter value as it follows:

First Filter:

customFilter = new OpenLayers.Filter.Logical({
   filters: [
       new OpenLayers.Filter.Comparison({
           type: OpenLayers.Filter.Comparison.EQUAL_TO,
              property: 'myCode',
              value: myVar

Then the WFS Layer:

wfsLayer = new OpenLayers.Layer.Vector("LayerName", {
      protocol: new OpenLayers.Protocol.WFS({
           url: "http://localhost:8080/geoserver/wfs",
       featureType: "LayerName",
       featureNS: "http://localhost:8080/project",
       featurePrefix: "schema",
       geometryName: "the_geom",
       outputFormat: "json",
       readFormat: new OpenLayers.Format.GeoJSON(),
       srsName: 'EPSG:25831',
       defaultFilter: customFilter
    strategies: [new OpenLayers.Strategy.Fixed(),

And add it to the map:


This works with a pre-set myVar variable before running the app. My idea is that when myVar is changed dinamicaly in my app (this is done), wfs layer updates its filter value too so map data is updated.

I've tried refreshing layer as myLayer.refresh() when myVar has been changed on my app but it still takes the initial myVar value so data in the map does not change.

Anyone knows?

share|improve this question
up vote 1 down vote accepted

I'm not sure about defaultFilter on protocol level. But common use case is to define filter property on layer level and change it dynamically following way:

wfsLayer.filter = /* your new filter here */;
share|improve this answer
Thank you. I didn't supose that the problem could be the "default"Filter. I've got to change filter instance place too and then refresh. Thank you very much again. (I've got no reputation yet so I can't vote your answer...). – Calypo Gunn Jan 24 '13 at 17:21

Your Answer


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.