Select to view content in your preferred language

Is there a cross-browser way to store tiles in web storage?

2246
5
01-26-2016 01:31 PM
DaveSouthern
New Contributor II

I found the following page in the ArcGIS javascript samples that supposedly gives an example of how to store tiles locally:

https://developers.arcgis.com/javascript/jssamples/exp_webstorage.html

It says that it doesn't work with IE - and I tested it and they are right - it doesn't work with IE.

Does anybody know of an approach to storing tiles locally that does work with IE?  In other words, is this really a problem with IE or is the example just not robust enough?

0 Kudos
5 Replies
ReneRubalcava
Frequent Contributor II

There is a library that you may want to look into to assist with offline mapping.

Esri/offline-editor-js: ArcGIS JavaScript library for handling offline editing and tiling.

The offline editor does a good job of storing tiles locally (storage limits do apply).

To answer your question above, it's always IEs fault.

IE8+ should support localStorage http://caniuse.com/#search=storage

I have a sample that uses PouchDB to do offline work, not using tiles, but similar concept. PouchDB will handle browser support for you and wrap storage around it's own API.

odoe/esri-pouchdb: Sample App using PouchDB... - GitHub

Hope that helps.

DaveSouthern
New Contributor II

Thanks for taking the time to respond.  As you say, IE is the problem - offline-editor.js does not support IE.

I tried to look at the PouchDB example, but the only example they had gave a 404 error when I clicked on it.

I was hoping one of these would work out.

I did some experimenting yesterday and IE does appear to place a layer into local storage - at least, according to the f12 tools it does.  But I can't find it on disk to see what is actually there, and when I try to pull it out of storage later all that comes out is a string 'object [Object]' - or something like that.  So I don't know what's going on.

0 Kudos
ReneRubalcava
Frequent Contributor II

One tip I can give is that web storage data should be strings, so you can do JSON.stringify(data). PouchDB should handle this, but if you are getting the 'object [Object]' response, you may need to stringify the data yourself.

I updated the link in the README there but here it is.

Taking it offline - odoenet

Hope that helps.

DaveSouthern
New Contributor II

I wasn't able to get either localForage or Dexie to even be recognized in my app.  I added the scripts to my pages, but whenever I tried to reference them, they showed up as undefined.  I wonder if something is going on because I'm using VS2015 or because of dojo being used in the app.  It just seems so strange...

0 Kudos
DaveSouthern
New Contributor II

I think there's something screwy going on with my system.  I tried the following sample code to work with IndexedDb directly:

    window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.OIndexedDB || window.msIndexedDB,

     IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.OIDBTransaction || window.msIDBTransaction,

     dbVersion = 1;

var request = indexedDB.open("elephantFiles", dbVersion);

But when I ran it, I got an error saying that indexedDB was undefined. 

0 Kudos