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
Is it possible to add a local .mbtiles file onto the map using a <VectorSource>?
I was thinking of doing something like this but I couldn't figure out a way to make it work:
I believe it should be possible, I have done it with the pre-forked version of Mapbox-gl-native. You will have to include the mbtiles file in the bundle somehow. I ended up doing it manually (dragging it into the project in Xcode and android studio) and then used something like react-native-filesystem to get the proper local uri for the file, then fed that into the url prop.
It's been a while so I don't remember some of the exact details, but the hardest part was getting the mbtiles file included in the bundle. I spent a number of hours trying to coax metro into including it with a require, but couldn't make that work, so had to resort to the manual method I mentioned above.
@mohanedmoh, please post the context of the slack conversation in question. Unfortunately, the slack history isn't publicly accessible, nor is it long lived. Some mock code with explanations of how you made it work, I am sure that would be appreciated by all. Thanks!
@tyrauber, @aLemonFox
Sure, so you will save the MBtiles locally and load it using <MapLibreGL.RasterSource id="testSource" tileUrlTemplates={["mbtiles:///" + path]} tileSize={512} minZoomLevel={10} maxZoomLevel={14}> <MapLibreGL.RasterLayer id="testLayer" sourceID="testSource" /> </MapLibreGL.RasterSource>
Which is normal RasterSource but with tileURLTemplate of (mbtiles:///path_to_your_mbtiles_file.mbtiles)
make sure to change the tileSize based on your MBtile configuration, mine was 512
if it's the wrong tileSize the map will start showing some tiles in dark mode and others in light mode
Activity
gorbypark commentedon Feb 24, 2024
I believe it should be possible, I have done it with the pre-forked version of Mapbox-gl-native. You will have to include the mbtiles file in the bundle somehow. I ended up doing it manually (dragging it into the project in Xcode and android studio) and then used something like react-native-filesystem to get the proper local uri for the file, then fed that into the url prop.
It's been a while so I don't remember some of the exact details, but the hardest part was getting the mbtiles file included in the bundle. I spent a number of hours trying to coax metro into including it with a require, but couldn't make that work, so had to resort to the manual method I mentioned above.
maarten-22 commentedon Feb 26, 2024
@gorbypark Hm, I don't seem to get it to work using filesystem either. Did you use the .mbtiles file or extract a pbf from it?
mohanedmoh commentedon May 20, 2024
Hi @aLemonFox check this out
https://osmus.slack.com/archives/C065DB4T2UB/p1711978657053129
mohanedmoh commentedon May 20, 2024
it worked with me
tyrauber commentedon May 20, 2024
@mohanedmoh, please post the context of the slack conversation in question. Unfortunately, the slack history isn't publicly accessible, nor is it long lived. Some mock code with explanations of how you made it work, I am sure that would be appreciated by all. Thanks!
mohanedmoh commentedon May 20, 2024
@tyrauber, @aLemonFox
Sure, so you will save the MBtiles locally and load it using
<MapLibreGL.RasterSource id="testSource" tileUrlTemplates={["mbtiles:///" + path]} tileSize={512} minZoomLevel={10} maxZoomLevel={14}> <MapLibreGL.RasterLayer id="testLayer" sourceID="testSource" /> </MapLibreGL.RasterSource>Which is normal RasterSource but with tileURLTemplate of (mbtiles:///path_to_your_mbtiles_file.mbtiles)
make sure to change the tileSize based on your MBtile configuration, mine was 512
if it's the wrong tileSize the map will start showing some tiles in dark mode and others in light mode
hope this was helpful
KiwiKilian commentedon Jan 4, 2025
Here is an example a put together the other day with
expo-asset:Will look, if we can add this to the examples. It's more difficult, because assets are different on Expo and React Native.
[-]Rendering from local .mbtiles file?[/-][+]How to use local `.mbtiles` file?[/+]