Skip to content

Instantly share code, notes, and snippets.

@mellet
Last active December 30, 2019 23:01
Show Gist options
  • Save mellet/630cc40df0765fb50b916002d5dd4107 to your computer and use it in GitHub Desktop.
Save mellet/630cc40df0765fb50b916002d5dd4107 to your computer and use it in GitHub Desktop.
Download tiles
function async fetchTiles(tileGrid, rootFolder, tileServerUrl) {
/*
* For Expo to be able to download the tiles,
* the directories have to be created first.
*/
const create_directories = tileGrid.map((tile) => {
const folder = `${rootFolder}/${tile.z}/${tile.x}`
return FileSystem.makeDirectoryAsync(folder, {
intermediates: true,
})
})
await Promise.all(create_directories)
const tile_downloads = tiles.map(tile => {
const fetchUrl = `${tileServerUrl}/${tile.z}/${tile.x}/${tile.y}.png`
const fsLocation = `${rootFolder}/${tile.z}/${tile.x}/${tile.y}.png`
return FileSystem.downloadAsync(fetchUrl, fsLocation)
})
const fileStatuses = await Promise.all(tile_downloads)
/*
// Debug downloaded files
fileStatuses.forEach(file => {
console.log('Downloaded, file.uri)
})
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment