#tile #vector #mapbox #gis #cartography

bin+lib mvt

A library for encoding mapbox vector tiles

17 unstable releases

0.9.4 Oct 23, 2024
0.9.3 Jun 6, 2024
0.9.2 Jan 19, 2024
0.8.1 Mar 7, 2023
0.5.2 Feb 28, 2019

#326 in Encoding

Download history 85/week @ 2024-07-28 105/week @ 2024-08-04 51/week @ 2024-08-11 77/week @ 2024-08-18 107/week @ 2024-08-25 334/week @ 2024-09-01 163/week @ 2024-09-08 74/week @ 2024-09-15 199/week @ 2024-09-22 160/week @ 2024-09-29 248/week @ 2024-10-06 151/week @ 2024-10-13 327/week @ 2024-10-20 115/week @ 2024-10-27 276/week @ 2024-11-03 229/week @ 2024-11-10

953 downloads per month
Used in 2 crates

MIT/Apache

72KB
1.5K SLoC

mvt

A Rust library for encoding mapbox vector tiles. Version 2.1 of the standard is supported. See documentation for details.

earthwyrm-bin is a tile server using this crate.


lib.rs:

A library for encoding mapbox vector tiles.

A tile is composed of one or more layers. Each layer can have any number of features, which contain the geometry to be rendered. They can also have metadata tags, which are key/value pairs.

Example

use mvt::{Error, GeomEncoder, GeomType, Tile};
use pointy::Transform;

fn main() -> Result<(), Error> {
    let mut tile = Tile::new(4096);
    let layer = tile.create_layer("First Layer");
    // NOTE: normally, the Transform would come from MapGrid::tile_transform
    let b = GeomEncoder::new(GeomType::Linestring)
        .point(0.0, 0.0)?
        .point(1024.0, 0.0)?
        .point(1024.0, 2048.0)?
        .point(2048.0, 2048.0)?
        .point(2048.0, 4096.0)?
        .encode()?;
    let mut feature = layer.into_feature(b);
    feature.set_id(1);
    feature.add_tag_string("key", "value");
    let layer = feature.into_layer();
    tile.add_layer(layer)?;
    let data = tile.to_bytes()?;
    println!("encoded {} bytes: {:?}", data.len(), data);
    Ok(())
}

Dependencies

~2–11MB
~139K SLoC