4

I have a mobile app that uses Phonegap with OpenLayers and Geoserver. Now, I need to make the app available completely offline. The amount of data points can get very large depending on what client is loaded into the app, and each point has related properties. So, I need to be able to pull the data down to the phone when it is online and then use the local data when it is offline. I like the speed of GeoJSON and would like to use it if possible. I have built a GeoJSON file that loads on the map like I want it to. Now, I have to save edits/moves to the GeoJSON file and I'm stuck. Using a save strategy isn't working and from what I read it looks like I have to have a server script to make that work.

How do I save the edits back to my GeoJSON file?

Or am I going about this all wrong and need to use something else for offline data with OpenLayers?

9
  • I believe the bigger issue is that PhoneGap will need some sort of server to talk to. The OpenLayers running in phonegap will be requesting tiles from a server over http. There may be some trick to get a small web server running along with phonegap on the device, but I'm not sure. That's the bigger issue. Once you have that server in place, your client javascript can talk to it to make those edits (and possibly to serve your points to the client in the first place). Once that structural issue is solved, different file formats (geojson, etc.) could work for storing the data.
    – M Katz
    Dec 7, 2013 at 4:18
  • Not to mention: even if you get that server running locally, where is it getting the tiles from? Do you have a store of all the basemap tiles you'll need?
    – M Katz
    Dec 7, 2013 at 4:18
  • I'm not goning to use tiles for the data points - I've put all the info for the points into a geojson file and am displaying it in a vector layer. I haven't gotten to the baseman layers yet but I'm hoping to use mrsid or geotiffs for that. Right now my hurdle is to save edits to my geojson file or use another method of storing and manipulating the data locally if there's a better one.
    – bl8rchk
    Dec 8, 2013 at 2:26
  • 1
    PhoneGap gives you an API to write files to the device file system, right? So you can do whatever you want with the GeoJSON (or any other text data) in your JavaScript and then just save the file, right? It doesn't need to be wrapped up with OpenLayers' save strategy, right?
    – M Katz
    Dec 8, 2013 at 9:09
  • I am planning to use the file api to make the edits but I'm wondering how to update a record in the GeoJSON file? Is there a javascript example to update one record and not rewrite the whole file?
    – bl8rchk
    Dec 9, 2013 at 13:12

3 Answers 3

1

I suggest taking a look at ArcGIS Javascript Offline Editing sample.

https://github.com/Esri/offline-editor-js

http://video.esri.com/watch/3371/offline-editing-with-javascript

Though it uses different data storing format and technologies, but some main ideas could be helpful or give you inspiration for your app.

So the main idea is - instead of changing the original data file, store changes as Inserts/Updates/Deletes in another location. This would ease the editing part, but somehow complicate the map rendering part, since you need to include changed parts into main data, when rendering.

0

Hum for edits you be in need of a server support to receive your clients requests. Unfortunelly I do not know how to do it with Geoserver.

If you would like to adventure with nodejs, you could make an easy javascript app that can update your file easily. It is a JavaScript based programming language so you could manipulate JSON files very quickly!

Also take a look at available controls for editing and on examples at openlayers site.

2
  • I would be interested in using node.js, but I thought it was only on a server?
    – bl8rchk
    Dec 9, 2013 at 13:13
  • You could use pouchdb (pouchdb.com) for the offline-app and couchdb (with or without geocouch) on the server.with that combination you have out off the box replication between the offline app and the server. For offline-tiles you can use mbtiles
    – Thomas B
    Jan 20, 2015 at 17:33
0

I recommend preprocessing all data for use offline. Generate vector tiles MBTILES which openlayers supports natively just add reading mbtiles directly via a plugin or MBTILES.js. Use holidays for preprocessing or geoserver with geowebcache or directly.from the latest postgis. The vector tiles will have whatever attributes your data has but only include what you need for a label or callput. To reduce size of the data. Tippecanoe allows you to scale your data to show up at different zoom levels you need to use the tippecanoe geojs on extension. https://github.com/mapbox/tippecanoe. Here is example using MBTILES sqlite with openlayers http://bl.ocks.org/tormi/raw/7699272/75ad7a225f4774fe6bbb864f4df892a9e1702d69/

Not the answer you're looking for? Browse other questions tagged or ask your own question.