2015-12-15 15:40:39 +00:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
title: Serve Raster Tiles with Docker
|
|
|
|
published: true
|
|
|
|
---
|
2015-12-15 14:18:31 +00:00
|
|
|
|
2015-12-17 14:24:26 +00:00
|
|
|
# Serve Raster Tiles with Docker
|
|
|
|
|
2015-12-17 14:40:30 +00:00
|
|
|
You can render raster tiles from a Mapbox Studio Classic **.tm2** style project and a vector tile MBTiles file
|
|
|
|
with the help of Docker and [tileserver-mapnik](https://github.com/klokantech/tileserver-mapnik).
|
|
|
|
|
2015-12-15 14:18:31 +00:00
|
|
|
For a single map you can serve up to 50 users concurrently with a standard 4GB VPS server with Docker installed.
|
|
|
|
|
|
|
|
## Preparation
|
|
|
|
|
2015-12-17 14:01:56 +00:00
|
|
|
1. Download MBTiles
|
2015-12-17 14:40:30 +00:00
|
|
|
2. Clone a **tm2** project (visual style)
|
2015-12-15 14:18:31 +00:00
|
|
|
3. Add both to the same directory
|
|
|
|
|
|
|
|
### Download MBTiles
|
|
|
|
|
|
|
|
On the server download your desired extract of a country or the
|
2015-12-17 14:21:36 +00:00
|
|
|
entire world MBTiles of the [Downloads page](/downloads).
|
2015-12-15 14:18:31 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
wget -c https://osm2vectortiles-downloads.os.zhdk.cloud.switch.ch/v1.0/world.mbtiles
|
|
|
|
```
|
|
|
|
|
2015-12-17 14:21:36 +00:00
|
|
|
You can also download a smaller extract like Zurich.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
wget -c https://osm2vectortiles-downloads.os.zhdk.cloud.switch.ch/v1.0/extracts/zurich.mbtiles
|
|
|
|
```
|
|
|
|
|
2015-12-15 14:18:31 +00:00
|
|
|
### Clone the Style Project
|
|
|
|
|
|
|
|
Clone your custom style project or in this example the official OSM Bright style.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
git clone https://github.com/mapbox/mapbox-studio-osm-bright.tm2.git
|
|
|
|
```
|
|
|
|
|
|
|
|
## Run the raster tile server
|
|
|
|
|
|
|
|
Make sure you have the style project and the MBTiles file in the same directory.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
├── mapbox-studio-osm-bright.tm2
|
|
|
|
└── world.mbtiles
|
|
|
|
```
|
|
|
|
|
|
|
|
Now run Docker via the command line to serve raster tiles.
|
2015-12-17 14:01:56 +00:00
|
|
|
The raster tiles will be exposed at port 8080 of your Docker host.
|
2015-12-15 14:18:31 +00:00
|
|
|
|
|
|
|
```bash
|
2015-12-17 13:56:56 +00:00
|
|
|
docker run -v $(pwd):/data -p 8080:80 klokantech/tileserver-mapnik
|
2015-12-15 14:18:31 +00:00
|
|
|
```
|
|
|
|
|
2015-12-17 14:40:30 +00:00
|
|
|
## Use the Raster Tiles
|
2015-12-17 14:21:36 +00:00
|
|
|
|
2015-12-17 14:40:30 +00:00
|
|
|
If you visit your Docker host on port 8080 you should see your map appearing
|
2015-12-17 14:21:36 +00:00
|
|
|
in the interface. If you click on the map thumbnail you will get the configuration
|
2015-12-17 14:40:30 +00:00
|
|
|
of the most common GIS clients and mapping libraries.
|
2015-12-17 14:21:36 +00:00
|
|
|
|
|
|
|

|
|
|
|
|
2015-12-17 14:40:30 +00:00
|
|
|
Choose `Source code` in `Leaflet` to get the source code for e.g. Leaflet.
|
2015-12-17 14:21:36 +00:00
|
|
|
|
|
|
|

|
|
|
|
|
2015-12-17 14:01:56 +00:00
|
|
|
The server will now provide a TileJSON endpoint at the service URL of the map.
|
2015-12-17 14:23:25 +00:00
|
|
|
For this example the TileJSON endpoint is `http://192.168.99.101:8080/mapbox-studio-osm-bright/index.json`.
|
2015-12-17 14:40:30 +00:00
|
|
|
You need to reference this TileJSON endpoint in the Leaflet configuration.
|