3

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(),
        myStrategy
    ]
});

And add it to the map:

map.addLayer(wfsLayer);

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?

1

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 */;
wfsLayer.refresh({force:true});
1
  • 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...). Jan 24 '13 at 17:21

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.