Qt image plugin for displaying Mapbox vector tiles
Go to file
2019-04-28 09:10:19 +02:00
pkg Use the official IANA MIME-type and extension 2019-02-26 22:20:12 +01:00
protobuf Initial version 2018-10-29 00:11:23 +01:00
src Proper path-text halo drawing 2019-04-28 09:10:19 +02:00
style Added support for HiDPI sprites 2018-12-04 00:09:23 +01:00
.travis.yml Added support for QT < 5.6 (and >= 5.4) 2018-12-17 18:31:26 +01:00
LICENSE Create LICENSE 2018-10-29 01:17:35 +01:00
pbfplugin.json Use the official IANA MIME-type and extension 2019-02-26 22:20:12 +01:00
pbfplugin.pro Added support for QT < 5.6 (and >= 5.4) 2018-12-17 18:31:26 +01:00
pbfplugin.qrc Added support for HiDPI sprites 2018-12-04 00:09:23 +01:00
README.md Refer to PBF also as MVT 2019-01-03 01:44:57 +01:00

QtPBFImagePlugin

Qt image plugin for displaying Mapbox vector tiles

Description

QtPBFImagePlugin is a Qt image plugin that enables applications capable of displaying raster MBTiles maps or raster XYZ online maps to also display PBF(MVT) vector tiles without (almost, see usage) any application modifications.

Standard Mapbox GL Styles are used for styling the maps. Most relevant style features used by Maputnik are supported. The style is loaded from the $AppDataLocation/style/style.json file on plugin load. If the style uses a sprite, the sprite JSON file must be named sprite.json and the sprite image sprite.png and both files must be placed in the same directory as the style itself. A default fallback style (OSM-Liberty) for OpenMapTiles is part of the plugin.

"Plain" PBF files as well as gzip compressed files (as used in MBTiles) are supported by the plugin.

Usage

Due to a major design flaw in the Mapbox vector tiles specification - the zoom is not part of the PBF data - the plugin can not be used "as is", but passing the zoom level is necessary. This is done by exploiting the optional format parameter of the QImage constructor or the QImage::fromData() or QPixmap::loadFromData() functions. The zoom number is passed as ASCII string to the functions:

QPixmap pm;
pm.loadFromData(tileData, QString::number(zoom).toLatin1());

The plugin supports vector scaling using QImageReader's setScaledSize() method, so when used like in the following example:

QImageReader reader(file, QString::number(zoom).toLatin1());
reader.setScaledSize(QSize(512, 512));
reader.read(&image);

you will get 512x512px tiles with a pixel ratio of 2 (= HiDPI tiles).

Build

Requirements

  • Qt >= 5.4 (5.6 for HiDPI support)
  • Google Protocol Buffers (protobuf-lite)
  • Zlib

Build steps

Linux

qmake pbfplugin.pro
make

Windows

qmake PROTOBUF=path/to/protobuf ZLIB=path/to/zlib pbfplugin.pro
nmake

OS X

qmake PROTOBUF=path/to/protobuf pbfplugin.pro
make

Install

Copy the plugin to the system Qt image plugins path to make it work. You may also set the QT_PLUGIN_PATH system variable before starting the application. For Linux, there are RPM and DEB packages for most common distros available on OBS.

Limitations

  • Only data that is part of the PBF file is displayed. External layers defined in the style are ignored.
  • Text PBF features must have a unique id (OpenMapTiles >= v3.7) for the text layout algorithm to work properly.

Status

A picture is worth a thousand words. Data and styles from https://openmaptiles.org.

OSM-liberty

osm-liberty 2 osm-liberty 5 osm-liberty 8 osm-liberty 11 osm-liberty 14

Klokantech-basic

klokantech-basic 2 klokantech-basic 4 klokantech-basic 8 klokantech-basic 13 klokantech-basic 14

Applications using QtPBFImagePlugin