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

Sideload offline packs #42

Open
kylebarron opened this issue Dec 28, 2019 · 1 comment
Open

Sideload offline packs #42

kylebarron opened this issue Dec 28, 2019 · 1 comment

Comments

@kylebarron
Copy link
Member

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:

  1. Clone the Maps SDK: git clone https://github.com/mapbox/mapbox-gl-native.git
  2. Change to the root folder: cd mapbox-gl-native
  3. 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)
  4. 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:

  1. Use a text editor to convert 1|2|3 to [1, 2, 3] (surely possible with sed but haven't tried)
  2. 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:
image

@kylebarron
Copy link
Member Author

kylebarron commented Feb 6, 2020

surely possible with sed but haven't tried)

I think I did this recently with awk. Specifically here:

https://github.com/nst-guide/data in the tiles docs

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

1 participant