Skip to content

Sideload offline packs #42

@kylebarron

Description

@kylebarron

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions