Mapbox Vector Tiles from PostGIS
What is the best tool to generate vector mbtile tiles?
In 2021 there are several lightweight options to serve vector tiles from PostGIS:
I have done some research on these as part of my work. The latter two (martin and pg_tileserv
) are my favourites, but pg_tileserv
really is the winner. It has the same features as martin, but is written in Golang (rather than Rust) and actively developed. Main contributor is Paul Ramsey , who is also a core contributor to PostGIS.
Using pg_tileserver
is as simple as spinning up the Docker container, providing it with the access credentials to your database. It will auto-detect all layers with geometries that it has access to and will serve Mapbox Vector Tiles in pbf
format and Web Mercator (EPSG:3857) projection---ready to be consumed by Leaflet or OpenLayers. Addtionally, you can extend the SQL functions provided in the docs and serve vector tiles in custom projections or with multiple layers, etc.
GUI Tool to define Map Layers
What would be awesome it a tool where we can (ideally with a GUI) define what kind of data is embedded into the tiles at which zoom level.
The standard is to represent your map configuration in a Mapbox Style JSON document. Maputnik is an online GUI tool that generates Mapbox Style JSON documents for you. It lets you set your data sources (e.g. your.vectortiles.com/{z}/{x}/{y}.pbf
) and define styles and max-zoom
/min-zoom
for your map.

For example, if you have state boundaries and districts: The simplest setup would be to have two PostGIS tables and two vector tiles endpoints served by pg_tileserv
. You would add these as data sources to Maputnik and set zoom levels and styling:
/states/{z}/{x}/{y}.pbf
-> e.g. min-zoom 0
, max-zoom 12
/districts/{z}/{x}/{y}.pbf
-> e.g. min-zoom 13
, max-zoom 20