Last active
December 30, 2019 23:01
-
-
Save mellet/630cc40df0765fb50b916002d5dd4107 to your computer and use it in GitHub Desktop.
Download tiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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