If you've ever self-hosted a map, you know the drill: import the data (OSM, for example) into PostGIS, run a tile server of your choice, repeat every time you need to update. This process is heavy, complex, and time-consuming.
PMTiles offers an alternative: one file, any static host, no required tile server.
Lately, my team and I have been playing around with PMTiles for our web project. We experimented with several approaches until we figured out the architecture that worked for our context. It is now up and running in production, serving a vector basemap along with a raster layer for hillshade.
The goal of this article is to sum up everything we have learned along the way about PMTiles: how to obtain them, how to host them, how to display them, the methods we ended up choosing but also those we set aside.
This article is the technical counterpart of a use case blog post that I wrote earlier this year. Don't hesitate to check it out!
What are PMTiles ?
PMTiles is a single-file archive format for tiled data, created by Protomaps. The principle is simple: instead of many z/x/y files, everything lives in just one .pmtiles file.
It supports both raster and vector data, in different formats (MVT, PNG, WebP...), as well as several compression methods (gzip, brotli...).
Protomaps also provides its own basemap (OSM based) with pre-generated styles (flavors), along with several useful tools to manipulate PMTiles, including a CLI.
How it works
All the data is available in the same file, but clients need to query only a small portion of it at a time.
To make that happen, the trick relies on the internal layout of the file:
- a header describing the archive.
- a directory with an index that maps tile IDs to byte offsets and lengths in the file. For large archives, this directory is itself split into a root directory and several leaf directories, so only a small fraction of the index ever needs to be fetched.
- the data itself, ordered along a Hilbert curve, so tiles that are close on the map are also close in the file.
In order to query a specific tile, the client must first query the header and the directory to know about the layout, find out at which bytes the tile is stored, and finally query just these bytes using an HTTP Range Request.
In practice, this means a tile can be reached with at most two or three requests (header + root directory, optionally a leaf directory, then the tile itself). PMTiles clients also cache the directory in memory, so once it's loaded, fetching further tiles only costs one request each.
No server-side logic is needed: any backend that can serve static file and honour Range headers will do!
Why (or why not) use them
The main advantage is a simplified hosting: it reduces the storage cost, while remaining scalable and efficient. It also makes updates much easier and faster: only one file to regenerate, no writing in a database. This argument sealed the deal for our project, which required long, tedious basemap updates, that often ended up deprioritized.
Additionally, for vector data, the advantages of PMTiles are the same as those for any vector tile layer: a modern visual rendering and customizable styling.
As a trade-off, keep in mind that PMTiles archives are immutable: any change means that you need to regenerate the whole file.
That makes PMTiles best suited for large datasets that do not change too often, such as basemaps.
Creating PMTiles
The first step to start using PMTiles is to get your first hello.pmtiles file.
Converting from other formats
If you already have some data in another format, you may want to convert it into PMTiles. To achieve that, the recommended tool is tippecanoe (optionally paired with GDAL to support a wider variety of input formats):
tippecanoe -zg -o hello.pmtiles -l mylayer hello.json If you have MBTiles, the pmtiles CLI comes with a "convert" tool to transform them directly into PMTiles:
pmtiles convert input.mbtiles output.pmtiles These are only a few possibilities: more converting tools are described in the Protomaps documentation.
Using existing data
Alternatively, several projects publish ready-to-use PMTiles archives.
- Protomaps produces daily builds of a global OSM-based basemap.
- Overture Maps also publishes its datasets in several formats, including PMTiles.
- Mapterhorn produces public terrain tiles, useful for hillshade maps.
If you don't need to download the whole extent, the pmtiles CLI provides an "extract" command to fetch only the tiles you need:
pmtiles extract https://build.protomaps.com/20260101.pmtiles \ paris.pmtiles \ --bbox=2.22,48.81,2.47,48.91 \ --maxzoom=15 The CLI also has commands to inspect the obtained archive and verify its layout:
pmtiles show hello.pmtiles pmtiles verify hello.pmtiles Hosting PMTiles
Now that we have our PMTiles archive, let's make it available for the world to see!
Serving PMTiles directly
The easiest way to serve PMTiles is simply to upload it onto a storage like S3 or Cloudflare, or just any web server. Just make sure that your server supports Range Requests, caches them correctly, and has CORS configured if the file is on a different origin, and you're good to go!
Note that this simplicity has a trade-off: the dataset is exposed to whoever knows its URL, which may not be what you want. In that case, you will have to use a tile server as a proxy.
If you go with this approach, you will need a client-side renderer to generate Range Requests. We will address this topic in the next section.
Using a tile server
Sometimes, you need a classic /{z}/{x}/{y} URL: when the client doesn't speak PMTiles, when you need to query a private storage bucket, to add custom logic or cache. In this case, we need a server-side solution that can translate the usual tile request into a PMTiles request with the correct Range header.
There are a few options to consider:
- The pmtiles CLI (once again) provides a command to create a lightweight server with a ZXY endpoint from a local directory or a bucket:
pmtiles serve . --port 8080 # → http://localhost:8080/paris/{z}/{x}/{y}.mvt pmtiles serve / --bucket=s3://BUCKET_NAME --port 8080 - Martin: a tile server from the MapLibre ecosystem, built in Rust, that supports PMTiles along with MBTiles and PostGIS sources.
martin paris.pmtiles GeoServer also supports PMTiles through a community module.
Protomaps also provides serverless functions (Cloudflare Workers / AWS Lambda) to expose PMTiles files as ZXY.
With this approach, you don't have to worry about Range Requests on the client side: just instantiate your layer, as you would for any vector tile source.
Display PMTiles in a frontend app
You now have your PMTiles file hosted somewhere: the last step is to use it as a layer in your application. If you have a tileserver that provides a ZXY endpoint, this should be nothing new, as vector tile sources are natively supported by most frontend mapping libraries. However, if you chose to expose your PMTiles directly, you need to set up a client that can handle Range Requests.
PMTiles in MapLibre
To add a PMTiles layer in MapLibre directly from storage, you can install the npm package pmtiles. This library is maintained by Protomaps and provides several tools for PMTiles in the browser, including a MapLibre plugin.
The logic relies on the addProtocol feature of MapLibre by providing a custom Protocol that translates the map extent into bytes range to generate the right Range Request. In the code below, we register this protocol and tell MapLibre to apply it whenever it comes across a URL that starts with pmtiles://.
import { addProtocol, Map } from 'maplibre-gl' import 'maplibre-gl/dist/maplibre-gl.css' import { Protocol } from 'pmtiles' const protocol = new Protocol() addProtocol('pmtiles', protocol.tile) const map = new Map({ container: 'map', center: [2.35, 48.86], zoom: 11, style: { version: 8, sources: { paris: { type: 'vector', url: 'pmtiles://https://my-bucket.example/paris.pmtiles', }, }, layers: [ { id: 'buildings', type: 'fill', source: 'paris', 'source-layer': 'my_layer', paint: { 'fill-color': '#4f46e5', 'fill-opacity': 0.6 }, }, ], }, }) If your PMTiles is behind a tile server, you don't need the pmtiles library at all or to use any protocol: simply add the ZXY URL in the source.
Note that if you want to display the complete Protomaps basemap, the @protomaps/basemaps package generates ready-to-use styles (light, dark, grayscale…).
PMTiles in OpenLayers
The OpenLayers ecosystem works a bit differently from the Protomaps / MapLibre philosophy, so integrating PMTiles is a little less straightforward. There are still several ways to achieve it, depending on your needs.
If you only need to query the data contained in your PMTiles, without a specific style associated to it, Protomaps provides yet another tool, called ol-pmtiles. This library provides two classes PMTilesRasterSource and PMTilesVectorSource. These classes will handle the Range Request. They can be instantiated as sources inside a native vector or raster layer:
import { Map, View } from 'ol' import VectorTile from 'ol/layer/VectorTile' import { PMTilesVectorSource } from 'ol-pmtiles' import { Style, Stroke } from 'ol/style' const vectorLayer = new VectorTile({ declutter: true, source: new PMTilesVectorSource({ url: 'https://my-bucket.example/paris.pmtiles' }), style: new Style({ stroke: new Stroke({ color: 'gray', width: 1 }) }) }) export const map = new Map({ view: new View({ center: [0, 0], zoom: 1 }), target: 'map', layers: [vectorLayer] }) In this example, we use the OpenLayers API to create our own style. However, vector PMTiles often come with a Mapbox Style, the standard style specification for vector tiles, which is not natively supported by OpenLayers.
To that end, the OL ecosystem provides a complementary library ol-mapbox-style to convert Mapbox Styles into OpenLayers Styles or Layers. Combining it with pmtiles-protocol lets you read a JSON style that references a pmtiles:// URL, like in the example below:
import { Map, View } from 'ol' import { apply } from 'ol-mapbox-style' import { register } from 'pmtiles-protocol' const style = await fetch('./protomaps-style.json').then(r => r.json()) export const map = new Map({ view: new View({ center: [0, 0], zoom: 1 }), target: 'map' }) register() apply(map, style) Alternatively, @geoblocks/ol-maplibre-layer is a tool we created at Camptocamp to render a MapLibre map as a layer in OpenLayers, which can make vector tiles and PMTiles integration smoother:
import { MapLibreLayer } from '@geoblocks/ol-maplibre-layer' import { addProtocol } from 'maplibre-gl' import { Map, View } from 'ol' import { Protocol } from 'pmtiles' let protocol = new Protocol() addProtocol('pmtiles', protocol.tile) const mapLibreLayer = new MapLibreLayer({ mapLibreOptions: { style: './protomaps-style.json' } }) export const map = new Map({ view: new View({ center: [0, 0], zoom: 1 }), target: 'map', layers: [mapLibreLayer] }) To generate the Range Requests, we can use addProtocol, just like in the MapLibre example.
Conclusion
There is not a single typical workflow to work with PMTiles. The simplest, more direct one would be:
Generate a PMTiles file with tippecanoe (or extract it from an external source).
Upload it on a static server.
Point MapLibre at it.
However, in a real-life project, many factors can influence your final stack: a frontend that historically relies on OpenLayers, the need for a proxy with authentication or custom logic, the need for cache, or a private storage bucket.
This article aims at describing the different alternatives we considered. It may not be exhaustive though, don't hesitate to get in touch to discuss!



