In our mobile application, we'd like to use the map offline.
Actually, we don't care about tiles, but we want the user to be able to see some Vector layers.
Here is a piece of code:
layer = new OpenLayers.Layer.Vector("Block", {
strategies: [new OpenLayers.Strategy.BBOX()],
filter: VMMS.GIS.GetBlockFilter(i),
protocol: new OpenLayers.Protocol.WFS({
url: self.urlProxyGeoserver,
version: "1.1.0",
featureType: "block",
featureNS: self.urlGeoserver + self.dataStore,
featurePrefix: self.dataStore,
srsName: "EPSG:900913",
geometryName: "block_geom",
schema: self.urlGeoserver + "wfs/DescribeFeatureType?version=1.1.0&typename=" + self.dataStore + ":block"
}),
projection: "EPSG:900913",
styleMap : self.StyleBlockWithOpacity
});
I would like to be able to load this layer before to be offline, then use it.
I tried to do it, and cache it with localstorage (HTML5), but some problems occurs because of javascript cyclic object.
I could make the request (with url parameter) with my own API, and then cache the response. But I have the feeling that we have to use OpenLayers API.
Otherwise, do you have any idea?
On google, I have only seen solution to cache tiles, but not about my problem.
I'm kind of newbie to Openlayers, so I might have miss something. In that case, I would be happy to know what 🙂
Thanks
Edit:
By the way, I tried the recommandation there: WFS Caching / Back button
But it's not working (or doesn't match with my needs for some)
Best Answer
One option is to store the features in the mobile local storage like a sqlite database, you can even store it in a html5 web sql database. When it's offline you can create the layer from stored feature.
Edit:
Following is the code to save the features (in geojson format) to local storage
Following is how you create feature from the geojson objects (when it's offline):
More edits: So in your map page, there will be some kind of connection check, and you get the features from different sources depend on whether it's online or offline.
The above code is quite primitive, you need to modify it according to your own application.