diff options
Diffstat (limited to 'snap.html')
| -rwxr-xr-x | snap.html | 44 |
1 files changed, 41 insertions, 3 deletions
@@ -11,6 +11,8 @@ <script type="text/javascript" src="Leaflet.Coordinates-0.1.4.min.js"></script> <script type="text/javascript" src="leaflet-geodesy.js"></script> <script type="text/javascript" src="leaflet-pip.min.js"></script> + <script type="text/javascript" src="pouchdb-3.3.1.min.js"></script> + <script type="text/javascript" src="L.TileLayer.PouchDBCached.js"></script> <script type="text/javascript" src="peer.js"></script> <script type="text/javascript" src="morphic.js"></script> <script type="text/javascript" src="widgets.js"></script> @@ -93,9 +95,46 @@ }); }); - layer = L.tileLayer('http://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.jpg70?access_token=pk.eyJ1IjoiY29kZS13dnMiLCJhIjoielU1N2dQayJ9.miUjtJaW7Y_Xx46dC6m0LA', { + // 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' - }).addTo(map); + }); + 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 + layer = L.tileLayer('http://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}@2x.png?access_token=pk.eyJ1IjoiY29kZS13dnMiLCJhIjoielU1N2dQayJ9.miUjtJaW7Y_Xx46dC6m0LA', { + useCache: true, + attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' + }); + new OSMBuildings(map).load(); + } + layer.addTo(map); L.control.coordinates({ decimals: 7, enableUserInput: false, @@ -108,7 +147,6 @@ map.locate({watch: true, enableHighAccuracy: true}); // OSMBuildings provides fancy 3D buildings - new OSMBuildings(map).load(); // A Sprite's X position is mapped to longitude // A Sprite's Y position is mapped to latitude |
