Skip to content

Instantly share code, notes, and snippets.

@gr2m
Created November 15, 2013 19:44
Show Gist options
  • Save gr2m/7490418 to your computer and use it in GitHub Desktop.
Save gr2m/7490418 to your computer and use it in GitHub Desktop.
Imagine you could use your map-based web application offline, including the map tiles. How could the API look like? #nobackend #dreamcode
// Add a new map to the collection
var map = OfflineMap.add('Berlin')
// This will not yet download it, to do so, call download on it.
// It returns a promise, with done / fail / progress callbacks
var download = OfflineMap.find('Berlin').download();
download.progress( updateProgressBar );
// Before downloading, you can also calculate its size
var map = OfflineMap.find('Berlin');
map.calculate().then( showRequiredSize );
// Use the offline map as a proxy for Leaflet
// This will trigger the download if needed
var map = OfflineMap.find('Berlin');
map.addTo( leafletInstance );
map.removeFrom( leafletInstance );
// add more specific parameters on what to download
var map = OfflineMap.add('Berlin', {
levels: [7,8,9,10,11,12,13],
from: [x1, y1],
to: [x2, y2]
})
var map = OfflineMap.add('My Home Quarter', {
query: 'Mission District, San Francisco'
levels: [10]
})
// Remove a map
OfflineMap.remove('Berlin')
// List offline available maps
OfflineMap.forEach( function(map) {
// returns map name and other meta data
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment