3

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

  • 1
    Have you checked in Firebug/Fiddler what's going out to your server? Try to load the WFS request manually in another tab with the BBOX parms in the URL. Maybe the issue is in your GeoServer config – Vadim Feb 9 '12 at 18:39
1

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.

  • Thanks @unicoletti. Just new OpenLayers.Strategy.BBOX({ratio:2, resFactor: 3} works for me, i.e. I don't need a refresh strategy. – minisaurus Jun 10 '16 at 11:36
1

@unicoletti's answer is quite right. I try it with my OpenLayers.Protocol.HTTP. And my new added feature in my json file can be loaded after zooming or panning at some extent. Here is my code, hope you can get some ideas.

    var vector_layer = new OpenLayers.Layer.Vector('JSON Vector Layer',{
        protocol: new OpenLayers.Protocol.HTTP({
            url: 'http://localhost:8080/MyServlet/gml/write.json',
            format: new OpenLayers.Format.GeoJSON({})
        }),
        strategies: [new OpenLayers.Strategy.BBOX({ratio:2, resFactor: 2}), refreshStrategy] 
    });

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.