Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering from local .mbtiles file? #266

Open
aLemonFox opened this issue Feb 19, 2024 · 6 comments
Open

Rendering from local .mbtiles file? #266

aLemonFox opened this issue Feb 19, 2024 · 6 comments

Comments

@aLemonFox
Copy link

aLemonFox commented Feb 19, 2024

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:

const Overlay: FC<OverlayProps> = ({}) => {
   return (
      <VectorSource id={'overlay-layer'} url={'mbtiles://my-file.mbtiles'}>
         <FillLayer props-... />
      </VectorSource>
   );
}

If this is not supported, what are the options to do such a thing without using a remote server?

@gorbypark
Copy link

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.

@aLemonFox
Copy link
Author

@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
Copy link

@mohanedmoh
Copy link

it worked with me

@tyrauber
Copy link
Collaborator

@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
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants