[GIS] WFS Layer does not refresh or give new data when map moved in openlayers

geoserveropenlayers-2wfs

I am trying to add a WFS Layer with a BBOX strategy. When I change the extent I want GeoServer to return only the features in that extent. Here is the code I am using to add layer.

wfs = new OpenLayers.Layer.Vector("Fields_WFS", {
    strategies : [new OpenLayers.Strategy.BBOX()],
    protocol : new OpenLayers.Protocol.WFS({
    version : "1.1.0",
    url : GEOSERVER_HOST + ":" + GEOSERVER_PORT + "/geoserver/wfs",
    featurePrefix : "rpid",
    featureType : "FIELDS_SUBSET_BNG_OSGB36_1", 
    featureNS : "<URI>",
    srsName : "EPSG:27700" //default
    }),
});

The map is set to a maxextent initially. And I have restricted WFS features to max 100 in geoserver settings.

My problem here is it only shows the same features every time I load and when I move or zoom +- it does not refresh WFS features.

Thanks,
JP

Best Answer

Try this in the layer definition:

 strategies: [new OpenLayers.Strategy.Refresh({force:true}), new OpenLayers.Strategy.BBOX({ratio:2, resFactor: 3})],

works for me.

Also note that by default the BBOX strategy requires that you zoom/pan quite a lot before a new request is issued. Try changing the ratio and resFactor params to lower the threshold.

The explanation for their meaning is in the code.