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 am using a Vector Layer with WFS protocol to show only a subset of the data. The filter which defines the subset, changes dynamically from the code. How do I refresh the layer, to show only the data that satisfies the new filter?

layer.refresh(); does not work.

share|improve this question
add comment

2 Answers

you could also do this:

var refresh = new OpenLayers.Strategy.Refresh({force: true, active: true});

and then as a strategy on the WMS layer :

strategies: [new OpenLayers.Strategy.Fixed(), refresh],

then call this where and when needed:

refresh.refresh();

edit:

If you want to test, try this from your init() (onload property content) or in a document.ready block:

  /* Now reload the vector data every 20 seconds */
  setInterval(function () {
        refresh.refresh();
  },20000);

It has to show the async requests in the firebug console and under the tab too, if not your not calling it for some reason.

share|improve this answer
    
I can't get this to work. refresh.refresh() does not cause the layer to refresh. I can't see any request being sent in firebug. –  Devdatta Tengshe Oct 17 '12 at 3:49
    
Where are you calling this from ? can you show some code in your question? This comes from a production page so it has to work. Update your question with the code you have so far and we'll get this to work. –  Glenn Plas Oct 17 '12 at 8:16
    
This worked for me. I needed to force the refresh on the Refresh Strategy itself to make my WFS layers trigger the refresh event and go get new data. Thanks. –  Chris Nov 16 '12 at 22:55
add comment
up vote 2 down vote accepted

If your vector layer is called wfslayer, use the the force option on the refresh method like this:

wfslayer.refresh({force: true}); 
share|improve this answer
add comment

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.