You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importReact,{useEffect}from'react';importMapboxfrom'@rnmapbox/maps';import{StyleSheet,View,Alert}from'react-native';import*asFileSystemfrom'expo-file-system';conststyles=StyleSheet.create({map: {width: '100%',height: '100%',}});constCreateOfflineMaps=()=>{constTILE_FOLDER=`${FileSystem.documentDirectory}tiles`;constMAP_URL='http://c.tile.openstreetmap.org';useEffect(()=>{consttest=async()=>{// check if a test png exists, if not then download themconstfileInfo=awaitFileSystem.getInfoAsync(`${TILE_FOLDER}/1/0/0.png`)if(!fileInfo.exists){downloadTiles();}}test();},[]);constdownloadTiles=async()=>{// just a few top level tiles to testconsttiles=[{x: 0,y: 0,z: 1},{x: 1,y: 1,z: 1},{x: 0,y: 0,z: 0},{x: 1,y: 0,z: 1},{x: 0,y: 1,z: 1}];// Create directory for tilesfor(consttileoftiles){constfolder=`${TILE_FOLDER}/${tile.z}/${tile.x}`awaitFileSystem.makeDirectoryAsync(folder,{intermediates: true})}// Download tiles in batches to avoid excessive promises in flightconstBATCH_SIZE=100letbatch=[]for(consttileoftiles){constfetchUrl=`${MAP_URL}/${tile.z}/${tile.x}/${tile.y}.png`constlocalLocation=`${TILE_FOLDER}/${tile.z}/${tile.x}/${tile.y}.png`consttilePromise=FileSystem.downloadAsync(fetchUrl,localLocation)batch.push(tilePromise)if(batch.length>=BATCH_SIZE){awaitPromise.all(batch)batch=[]}}awaitPromise.all(batch)alert('Finished downloading tiles.')}// tile url here can be replace with "http://c.tile.openstreetmap.org/{z}/{x}/{y}.png" and it works fineconststyleJSON={"version": 8,"name": "Offline Test","sources": {"offline": {"type": "raster","tiles": [`${FileSystem.documentDirectory}tiles/{z}/{x}/{y}.png`]}},"layers": [{"id": "test","type": "raster","source": "offline",}]}return(<Viewstyle={styles.container}><Mapbox.MapViewstyle={styles.map}styleJSON={JSON.stringify(styleJSON)}></Mapbox.MapView></View>);}exportdefaultCreateOfflineMaps
Observed behavior and steps to reproduce
If you allow the tiles to be downloaded, and reload or leave and re-enter this component, the app will crash on android (development build for expo).
Here are my relevant package versions (I'm using expo):
I don't get any errors from my terminal or anything really, it simply crashes. The code works fine if you replace the tile url with an online one like "http://c.tile.openstreetmap.org/{z}/{x}/{y}.png" and it also works as expected with the downloaded tiles on iOS.
Additional links and references
I am trying to do something similar to what is done here and downloading tiles based on this tutorial (this part works great).
The text was updated successfully, but these errors were encountered:
I'm sure it could be reproduced without expo if you are able to just place some downloaded tiles in any file:// location and reference it in the tiles array like above.
Mapbox Implementation
Mapbox
Mapbox Version
default
Platform
Android
@rnmapbox/maps
version10.1.6
Standalone component to reproduce
Observed behavior and steps to reproduce
If you allow the tiles to be downloaded, and reload or leave and re-enter this component, the app will crash on android (development build for expo).
Here are my relevant package versions (I'm using expo):
Expected behavior
Should just show the map tiles
Notes / preliminary analysis
I don't get any errors from my terminal or anything really, it simply crashes. The code works fine if you replace the tile url with an online one like "http://c.tile.openstreetmap.org/{z}/{x}/{y}.png" and it also works as expected with the downloaded tiles on iOS.
Additional links and references
I am trying to do something similar to what is done here and downloading tiles based on this tutorial (this part works great).
The text was updated successfully, but these errors were encountered: