diff options
| author | Code WvS <code-wvs@quantentunnel.de> | 2015-03-22 18:04:25 +0100 |
|---|---|---|
| committer | Code WvS <code-wvs@quantentunnel.de> | 2015-03-22 18:04:25 +0100 |
| commit | ba5af162af694fc1d767816ed19cf180e2a0b943 (patch) | |
| tree | c00b63c8f53008bc20732833c53b18bc60327fb4 | |
| parent | 8cbb9efd39b0c21c1a7237cee39b52d3dba587f4 (diff) | |
| download | snap-yow-ba5af162af694fc1d767816ed19cf180e2a0b943.tar.gz snap-yow-ba5af162af694fc1d767816ed19cf180e2a0b943.zip | |
fix caching on mobile
| -rwxr-xr-x | snap.html | 52 |
1 files changed, 23 insertions, 29 deletions
@@ -95,44 +95,38 @@ }); }); + var state = "mobilewifi"; // TODO: check other states than listed below // TODO: too much repeated code, shorten the url part if ("connection" in navigator) { // mobile cordova app - console.log('DEBUG - detected mobile'); state = navigator.connection.type; - // download everything & in high resolution - if (state == Connection.ETHERNET || state == Connection.WIFI) { - layer = L.tileLayer('http://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}@2x.png?access_token=pk.eyJ1IjoiY29kZS13dnMiLCJhIjoielU1N2dQayJ9.miUjtJaW7Y_Xx46dC6m0LA', { - useCache: true, - cacheMaxAge: 604800000, // one week - attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' - }); - new OSMBuildings(map).load(); - // download low-res and cache as much as possible - // we do not need OSMBuildings here - } else if (state == Connection.CELL) { - layer = L.tileLayer('http://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.jpg70?access_token=pk.eyJ1IjoiY29kZS13dnMiLCJhIjoielU1N2dQayJ9.miUjtJaW7Y_Xx46dC6m0LA', { - useCache: true, - cacheMaxAge: 604800000, // one week - attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' - }); - // shit, we're offline - let's hope there is something cached - // OSMBuildings won't work, anyway - } else { - layer = L.tileLayer('http://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.jpg70?access_token=pk.eyJ1IjoiY29kZS13dnMiLCJhIjoielU1N2dQayJ9.miUjtJaW7Y_Xx46dC6m0LA', { - useCache: true, - useOnlyCache: true, - cacheMaxAge: 604800000, // one week - attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' - }); - } - } else { - // desktop + } + console.log('Using tile layer appropriate for ' + state); + // download everything and in high resolution + if (state == 'mobilewifi') { layer = L.tileLayer('http://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}@2x.png?access_token=pk.eyJ1IjoiY29kZS13dnMiLCJhIjoielU1N2dQayJ9.miUjtJaW7Y_Xx46dC6m0LA', { useCache: true, + cacheMaxAge: 604800000, // one week attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' }); new OSMBuildings(map).load(); + // download low-res and cache as much as possible + // we do not need OSMBuildings here + } else if (state == "mobilecellular") { + layer = L.tileLayer('http://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.jpg70?access_token=pk.eyJ1IjoiY29kZS13dnMiLCJhIjoielU1N2dQayJ9.miUjtJaW7Y_Xx46dC6m0LA', { + useCache: true, + cacheMaxAge: 604800000, // one week + attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' + }); + // shit, we're offline - let's hope there is something cached + // OSMBuildings won't work, anyway + } else { + layer = L.tileLayer('http://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.jpg70?access_token=pk.eyJ1IjoiY29kZS13dnMiLCJhIjoielU1N2dQayJ9.miUjtJaW7Y_Xx46dC6m0LA', { + useCache: true, + useOnlyCache: true, + cacheMaxAge: 604800000, // one week + attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' + }); } layer.addTo(map); L.control.coordinates({ |
