It looks like sideloading offline packs might get supported in react-native-mapbox-gl (https://github.com/react-native-mapbox-gl/maps/pull/588).
Building mbgl-offline
mbgl-offline is the CLI to assemble offline databases for side-loading.
https://github.com/mapbox/mapbox-gl-native/wiki/Sideloading-offline-maps
These worked for me:
- Clone the Maps SDK: git clone https://github.com/mapbox/mapbox-gl-native.git
- Change to the root folder: cd mapbox-gl-native
- Check out the release commit equivalent to the version of the Maps SDK that you are using: git checkout {commit hash} (view all release commits)
- Compile the binary: make offline
Once the build is complete, you'll see the message Build Succeeded in the terminal. The binary is available under the build folder (for example, on a Mac the file will be in build/macos/Debug/mbgl-offline).
Creating the offline pack
To create the offline pack:
./mbgl-offline \
--geojson buffer.geojson \
-o offline.db \
--style=https://raw.githubusercontent.com/nst-guide/osm-liberty-topo/gh-pages/style-png.json \
--minZoom=0 \
--maxZoom=14
A 2 mile buffer around Sec A is 19MB. This includes contours and terrain but not NAIP.
When I run with --style=https://raw.githubusercontent.com/nst-guide/osm-liberty-topo/gh-pages/style-hybrid-png.json, that gives a 48MB db. So here the NAIP imagery (up to zoom 14) is 30MB for the 2 mile buffer.
Note that --geojson must be a single geometry. If you pass a FeatureCollectino it won't work. In this case, buffer.geojson is a 2-mile buffer around Sec A as a top-level type=Polygon.
It looks like it correctly intersects the polygon with xyz boxes, instead of just taking the bounding box of the provided geometry.
To get the xyz tiles downloaded for a given pack:
sqlite3 offline.db 'SELECT x,y,z from TILES;'
(offline.db is just a Sqlite3 database)
Then if you want to turn those xyz coords into a GeoJSON describing the tiles' geometry:
- Use a text editor to convert
1|2|3 to [1, 2, 3] (surely possible with sed but haven't tried)
- run
cat db_tiles.txt | mercantile shapes | fio collect > db_tiles_Z14.geojson
where db_tiles.txt has
Here's a visualization of the tiles used for this:

It looks like sideloading offline packs might get supported in
react-native-mapbox-gl(https://github.com/react-native-mapbox-gl/maps/pull/588).Building
mbgl-offlinembgl-offlineis the CLI to assemble offline databases for side-loading.https://github.com/mapbox/mapbox-gl-native/wiki/Sideloading-offline-maps
These worked for me:
Once the build is complete, you'll see the message Build Succeeded in the terminal. The binary is available under the build folder (for example, on a Mac the file will be in build/macos/Debug/mbgl-offline).
Creating the offline pack
To create the offline pack:
./mbgl-offline \ --geojson buffer.geojson \ -o offline.db \ --style=https://raw.githubusercontent.com/nst-guide/osm-liberty-topo/gh-pages/style-png.json \ --minZoom=0 \ --maxZoom=14A 2 mile buffer around Sec A is 19MB. This includes contours and terrain but not NAIP.
When I run with
--style=https://raw.githubusercontent.com/nst-guide/osm-liberty-topo/gh-pages/style-hybrid-png.json, that gives a 48MB db. So here the NAIP imagery (up to zoom 14) is 30MB for the 2 mile buffer.Note that
--geojsonmust be a single geometry. If you pass a FeatureCollectino it won't work. In this case,buffer.geojsonis a 2-mile buffer around Sec A as a top-leveltype=Polygon.It looks like it correctly intersects the polygon with xyz boxes, instead of just taking the bounding box of the provided geometry.
To get the xyz tiles downloaded for a given pack:
(
offline.dbis just a Sqlite3 database)Then if you want to turn those xyz coords into a GeoJSON describing the tiles' geometry:
1|2|3to[1, 2, 3](surely possible withsedbut haven't tried)where
db_tiles.txthasHere's a visualization of the tiles used for this:
