Preparing offline map packages
Last updated
Last updated
This page may require some technical knowledge about geospatial data. If the content of this page feels unfamiliar to you, get someone acquainted with geographic information systems (GIS) to help you.
For offline or mesh network usage, Terrastories can load a background map using a locally hosted map tileset and style, instead of a map from Mapbox Studio. This requires you to provide your own locally hosted map tiles and style.
By default, Terrastories provides a set of open-license offline map tiles, generated through the . These tiles cover the entire world, but are only compiled up to zoom level 8 (roughly the extent of a small country like Rwanda, Costa Rica, Slovenia or Bhutan). Once you zoom in past zoom level 8, no further level of detail will show.
However, you can also provide your own map tiles, which have to be in a or a format , alongside any map fonts (glyphs), sprites, and a style.json
that defines how the map tiles will be visualized and styled on a map canvas.
Map tiles can be generated using existing utilities, or converted from standard geospatial data (Shapefile, GeoJSON), in several ways.
Generate tiles using QGIS: The open-source GIS software QGIS has several tools for generating MBTiles
in both raster and vector format. Generate XYZ tiles (MBTiles)
can be used to create raster tiles of all of the content on your map canvas; this may also include XYZ Tiles from services such as OpenStreetMap, Bing, and Google Satellite. Generate Vector Tiles (MBTiles)
can be used to create vector tiles from one or more vector layers. You can then further style these vector tiles in your style.json
file.
The page in the Mapeo support materials has a visual, step-by-step guide for using QGIS to generate raster tiles.
Generate tiles using mapgl-tile-renderer: The tool can be used to generate rasterMBTiles
from various sources including Bing Satellite, Esri World Imagery, Google Earth, and more, with an optional OpenStreetMap overlay.
Convert tiles using tippecanoe: There is also a command line tool called tippecanoe
which can be used to generate vector MBTiles
or PMTiles
from Esri Shapefiles and other formats: .
Convert tiles using mbutil: If you already have tiles in a different format (such as xyz
), you can use a Node command line tool called mbutil
to convert them to MBTiles
. Please see our or this page in the Mapeo support materials for more information.
Once generated, place the tiles in the map/data/
directory.
style.json
)Map styles (per the style.json
schema) defines the visual appearance of a map: what data to draw on the map canvas, the order in which layers are displayed, and how to style the data when drawing it. Mapbox provides a helpful with all of the possible style parameters, but it's generally useful to download an existing style.json
file and modify it to suit your needs.
When you are done designing your map in the Mapbox Studio environment, click "Share" and then download the Map style ZIP file.
Unzip the file, and extract the style.json
and place it in tileserver/data/styles
.
Next, you will need to make some changes. The style.json
from Mapbox will be referring to an online URL for the map sources. You need to change this to refer to the local MBTiles
. Change sources
> composite
> url
to the following format: "url": "mbtiles://mbtiles/name.mbtiles"
. (Here, name
is just an example; it can be called whatever you want, so long as the filename is the same.)
Importantly, the layer names referenced in styles
and MBTiles
have to match, in order for the tiles to receive a style property. It may be necessary to edit the layer names in style.json
to reflect the names of the spatial data in the MBTiles
file.
If you have raster tiles that you want to load in Terrastories, those will need to defined differently from the vector tiles above. In sources
, create a new source definition with url
pointing to the raster MBTiles
in the same format as above, and with type
set to raster
. Then, in layers
, create a map object with your id
of choice, type
set to raster
, and source
set to the name of your raster tiles as defined in sources
. Here is an example style.json
file which only loads a raster MBTiles
:
If you want, you can add additional tile sources (vector as well as raster), and place your raster tile layer underneath vector layers. This is a good way to have an offline satellite imagery basemap with vector data (points, lines, polygons, and labels) overlaid on top of it.
One of the easiest ways to build a style.json
file is by uploading and styling your data on and downloading the style.json
file from there, in the following way:
Design your map in Mapbox Studio. Mapbox provides extensive documentation and tutorials on using Studio .
Note: it is also possible to use , the open-source visual editor for the Mapbox style specification, to style your MBTiles
data.