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'm using WFS protocol on Vector layer / GeoServer / PostGIS

Currently the map is refreshing and calling new requests whenever i do anything like searching or drawing and when i move back to a part of the map which previously had features already downloaded, it refreshes and call new request again. i need to reuse previous data for previous requests.

I've read that the OpenLayers does not have this functionality. but this was a long time ago. is there a way to cache wfs returns by check the boolean in top of the code or anything like that ?

also that will help me implement my BACK button so that i can store previous requests in a stack and pull requests when the user clicks the back button

would appreciate any help.

share|improve this question

3 Answers 3

HTTP POST requests are not normally cached - see this StackOverflow question: http://stackoverflow.com/questions/626057/is-it-possible-to-cache-post-methods-in-http

However if you switch your WFS layer to use GET requests rather than POST requests then these requests can be cached.

I had to apply a patch to my OpenLayers installation to get this to work correctly - http://trac.osgeo.org/openlayers/ticket/2718

Then you can set the WFS method to be GET when creating the layer (in the options parameter).

share|improve this answer

The HTML5 specs have a feature that does exactly what you need, for the details see the documentation on the Mozilla Developers Network:

https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history

Unfortunately this means you will have to code the integration between OpenLayers and the different browser history implementations yourself. There are plugins for jquery but since I don't have direct experience with any of them I can't give recommendations.

Basically what you need to do is:

  1. whenever a WFS query is issued push the results on the browser history
  2. setup a listener so that you are notified of back/forward events
  3. handle back/forward events by popping features from previous wfs requests

There are two new kids on the js block (Amber.js and Sproutcore) who have a complete framework for handling browser history or as they call it routes and I strongly suggest you take a look at them before rolling your own.

BTW: if you pull down lots of features with the wfs requests, the browser could run out of memory and be slower then if it just had to fetch the features from wfs every time. Apply the 3 rules of optimizations first.

share|improve this answer

What type of strategy are you using? If you are using the boundingBox strategy, at each pan/zoom OL will do a new request to get the features that are inside the map. Depending on how many features you have, to lower the number of ajax request you can try to use the OpenLayers.Strategy.Fixed instead.

About caching, OpenLayers has a caching controls, but I think they are oly for WMS protocol (I never try to use them on a vector layer).

Or, you could implement your own caching system, which should be quite simple, overriding the OpenLayers.Protocol.read() method

var layer = new OpenLayers.Layer.Vector(
    "layer",
    {
        strategies:[new OpenLayers.Strategy.Fixed()],
        projection: this.wgs84Projection,
        //filter: propertyFilter,
        protocol: new OpenLayers.Protocol.WFS.v1_1_0(
        {
            version: '1.1.0',
            url: Optima.Settings.getServiceUrl("wfs"),
            read: function(options)
            {
                /*
                 * Override of read() to avoid loading events using WFS. 
                 * Or, implement a cache: 
                 * {options} have all the necessary information to build
                 * a WFS request, and a callback to call after the data are loaded
                 * is also provided
                 */
                return null;
            }
            featureType: 'events',
            featureNS :  Optima.Settings.client.namespace,
            featurePrefix: Optima.Settings.client.typename,
            geometryName: 'shape',
            extractAttribute:   true,
            srsName: 'EPSG:4326'                
        }),
        displayInLayerSwitcher: false
    });
share|improve this answer

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.