My app takes several seconds to return all features of a WFS layer from server, I am wondering whether there is a way to check whether all features are returned in coding, so that we can add a loading-mask...

In other words, how do you check whether a WFS request is successful or not?

Please provide more information, a bit of code would be nice and are you using OpenLayers.Format.WFS or OpenLayers.Protocol.WFS?
–
CaptDragonMar 13 '12 at 13:45

What should happen is the server will return some sort of response depending on the success or failure of the request, so you should wait for that. of course, the server could stop responding for some reason, in which case you should have some sort of reasonable timeout in your client that displays a "server not responding" type message.
–
MerseyVikingMar 13 '12 at 13:48

@MerseyViking I understand server will return some info no matter success or failure. but i don't know how to 'monitor' this response with the use of OpenLayers.Protocol.WFS...
–
SimonMar 13 '12 at 13:57

Update

The problem with supplying the protocol in the layer constructor is that you don't get the chance to call .read() yourself and the opportunity to provide your own callback to monitor the response because the layer does it for you.

So if you want to monitor the results you're going to have to create the layer and protocol separate so you can call the .read() whenever you click the "search" button for example. Then when you get the results you add those features to the layer newEventLayer.addFeatures(resp.features);

Update 2

Filter Strategy

You are right, i have removed the strategy from the layer constructor. You are going to have to specify your filter separately or in the protocol constructor as I have it above. But you're going to have build a search filter anyway if you want to search your WFS service by attributes, date/time, etc. Or did you only want to rely on the BBox Strategy (give me EVERYTHING in the BBOX)? If so then just set up a filter for that and call the protocol.read() on the map extentchange event. After all, that's all the strategy does. But that's seperate question which I, or others can help you with.

thanks very much! one further question, as you see, in the code sample, this layer request has strategy & protocol parameters, and I assume internally it will call protocol.read in order to get features; in your answer, I need to explicitly call protocol.read() again in order to get the response. Does this mean this function is called twice? if this is the case, how can I avoid one of them, which means, we only need call it once and we want to have its callBack function enabled with it. thanks again!
–
SimonMar 13 '12 at 14:16

It will not be called twice because you will not pass the protocol object you create to the layer's constructor. You will call protocol.read(), get results, then add the results.features to your layer.
–
CaptDragonMar 13 '12 at 14:41

hmmm.. not quite work yet... callBack func is not called; and, I am not sure whether the protocol uses layer strategy or not, because initially they don't have any relationship..
–
SimonMar 13 '12 at 15:12