Vector tiles

From OpenStreetMap Wiki
(Redirected from Pg tileserv)
Jump to navigation Jump to search

Vector tiles are a way to deliver geographic data in small chunks to a browser or other client application. Vector tiles are similar to raster tiles, but instead of raster images, the data returned is a vector representation of the features in the tile. Clients must then render the data into a visual representation on the fly, typically with the help of a separate stylesheet that describes how the data should look when it is presented to the user.

Motivation

Vector tiles were developed to address some limitations of raster tiles. The key difference is that vector tiles contain map data, which is loaded by client applications and then rendered on the fly. This adds complexity to the application, but also enables features that are not practical with raster tiles:

  • Customization: since the client application renders the tile data, it can adapt what it shows to different use cases. For example, a map could show bicycle lanes more prominently if the user is looking up biking directions, or switch to a "dark mode" version of the map at night that uses the same data but with different styling.
  • Smooth zooming: the application can render the data at exactly the size and resolution appropriate for the device's screen and the current zoom level, meaning the map always looks crisp (never pixelated).
  • Rotation: the user can rotate the map and the labels can remain upright, since the application can redraw them at whatever angle is required.
  • Interactivity: the application can query data stored in the tiles and present it to the user, for example letting them tap on the map to see details about an object, or search for things nearby, without needing to talk to a separate web service.

Mapbox Vector Tiles

When people say "vector tiles", they almost always mean tiles in a data format called Mapbox Vector Tiles or MVT. The Mapbox Vector Tile Specification defines this file format. Mapbox also offers a guide with visuals explaining how the format works.

At a high level, MVT tiles provide an efficient binary encoding for map features. Features have geometries (which can be points, lines, or polygons, similar to GeoJSON) and may also have attributes (key-value pairs, where keys are strings and values are strings, ints, floats, or booleans). MVT provides a compact binary encoding of this data, based on the Protobuf binary serialization format. Note that although the OpenStreetMap planet file is distributed in a Protobuf-based .osm.pbf file format, the two formats are unrelated except for the fact that they are built on top of the same low-level serialization format.

Like raster tiles, vector tiles are usually served to clients over HTTP. The file extension is typically either .mvt or .pbf. The recommended MIME type is application/vnd.mapbox-vector-tile.

Rendering

Vector tiles are somewhat more complex to display in a client application than raster tiles, since the client must interpret the data in the tiles and produce a visual representation from it. This process is called rendering.

Rendering libraries

Rendering nice maps from vector tiles is complex. It involves problems like intersection, rasterization, and label placement. Most websites and apps that render maps using vector tiles do so with the help of a rendering library that handles these details. Some available options are:

Styling

In addition to the tiles themselves, the client needs instructions that define how various features should look (which icons to use for different POI types, how thick should lines for roads be drawn, etc). The most widely used styling language is the Mapbox Stylesheet Specification (sometimes known as "the style spec"). The Mapbox and MapLibre rendering engines both support this stylesheet format.

Tile schemas

When creating a set of vector tiles, the author must decide what data to include in them. Applications will only be able to display information that is present in the tiles, but including too much data in the tiles will make the map very slow to load. Tileset authors must also decide how to organize the data they include.

Any given stylesheet will generally only work when combined with tiles that the stylesheet was designed for, in much the same way that a CSS stylesheet will generally only have the expected effect when applied to the HTML page it was intended for, and not to a page on a different website.

Several companies and organizations have created standardized tile schemas with the goal of providing a common set of map data that will be sufficient to build maps for a variety of purposes. This allows website and app developers to customize the look of a map to their needs, without needing to create and host their own tilesets (instead they can use the tiles hosted by one of these companies or organizations). These include:

However, it's also common for applications that use vector tiles to have their own, bespoke tile schemas designed to suit their particular needs.

MBTiles and PMTiles

MBTiles and PMTiles are two file formats designed for storing large sets of tiles in a single file. Both are capable of storing either raster (image) or vector tiles, and both support fast random access so that a single tile can efficiently be retrieved by its Z, X and Y coordinates without needing to scan the entire file. Many tools that create vector tiles support outputting to MBTiles or PMTiles archives. This is often more convenient than producing millions of tiles as individual files (e.g. can be more efficient to upload the resulting tileset to a server).

Providers

The following companies or organizations host vector tiles in MVT format as a service. Some require an API key and/or payment to use.

Note that the Operations Working Group is also working on hosting vector tiles on OSMF servers. The current (2024) plan is to use Tilekiln.

Generators

The following programs can generate MVT tiles from OSM data:

  • Tilemaker - Command line tool to generate vector tiles (MBtiles) directly from .osm.pbf files
  • Planetiler - Flexible tool to build planet-scale vector tilesets from OpenStreetMap data in a few hours; output as MBTiles (sqlite) or PMTiles
  • Sequentially-generate-planet-mbtiles - Generate planet-scale vector tilesets on low memory / low cpu count devices
  • OpenMapTiles Tools - Generate vector tiles from OSM data
  • Martin (MapLibre) - Generate vector tiles from OSM data in a PostGIS database

History

  • 2016-01-19: Mapbox Vector Tile Specification 2.1 is released
  • 2014-04-13: Mapbox Vector Tile Specification 1.0.0 is released
  • 2010-11-29: TileStache can serve clipped GeoJSON tiles to Polymaps

Examples

Some examples of OSM-based maps using vector tiles are:

See also