Skip to content

Latest commit

 

History

History

README.md

maplibre-tile-spec/cpp

A C++ implementation of the MapLibre Tile (MLT) vector tile format.

Status

CMake and Bazel build support.

Build

git submodule update --init --recursive
cmake -GNinja -Bbuild -S.
cmake --build build --target mlt-cpp-test mlt-cpp-json

Test

build/test/mlt-cpp-test

Use

To decode a tile:

  • Deserialize the tileset metadata
  • Create a Decoder
  • Call decode with the metadata and a view on the raw tile data

To use the standard packing of metadata and data within a tile, use decodeTile.

#include <mlt/decoder.hpp>
#include <mlt/metadata/tileset.hpp>

...

auto metadata = mlt::metadata::tileset::read({metadataBuffer.data(), metadataBuffer.size()});

mlt::Decoder decoder;
const auto tile = decoder.decode({mltBuffer.data(), mltBuffer.size()}, metadata);

const auto tile2 = decoder.decodeTile({tileData.data(), tileData.size()});

Tools

A simple application which dumps a tile/metadata file pair to JSON format.

build/tool/mlt-cpp-json ../test/expected/tag0x01/bing/4-12-6.mlt

Implementation Notes

Encoder

  • The C++ encoder supports detecting nullable columns in cases where the Java implementation (as of 04/2026) always encodes nullable columns with trivial presence streams. The EncoderConfig.forceNullableColumns option must be set in some cases for parity.
  • Java uses closed rings in generateMixed because it is building JTS Polygon objects, and JTS polygon rings are expected to be closed. But when Java converts geometry to MLT streams, it deliberately strips the duplicated closing vertex, to be synthesized on decoding. The C++ encoder does not use JTS and encodes the geometry exactly as provided, so closing vertices should not be provided.