Skip to main content

Module map

Module map 

Source
Expand description

A map, MapLibre GL style: named sources (vector tiles, GeoJSON) plus an ordered list of style layers that say how to draw them, with custom layers for anything else. The app changes the map with set_data, set_paint, set_filter and friends, draws it with Map::view, and asks what’s under the pointer with Map::query_rendered_features.

let mut map = Map::new();
map.add_source("basemap", MapSource::vector(Source::open(OPENFREEMAP).await?))?;
map.add_source("route", MapSource::geojson(&route_json)?)?;
map.add_layer(StyleLayer::background("bg").color("#101418"))?;
map.add_layer(StyleLayer::line("roads", "basemap").source_layer("transportation").color("#666"))?;
map.add_layer(StyleLayer::line("route", "route").color("#00e5ff"))?;
loop {
    let area = term.get_frame().area();
    map.load_tiles(&cam, area).await?;
    term.draw(|frame| frame.render_widget(map.view(&cam), area))?;
    // What's under a spot: braille dots in the map area (2 per column, 4 per row).
    for f in map.query_rendered_features(&cam, area, (40.0, 40.0), Some(&["route"])) {
        println!("{}", f.title());
    }
}

Structs§

GeoJsonSource
A GeoJSON source: features, a spatial index, and clusters when on.
KittyState
The images Map::kitty_commands has sent to the terminal: their decoded size and the last frame that used each.
Loaded
A fetched and decoded tile.
Map
A map: sources, style and custom layers, feature state, and how raster layers draw. See the module docs.
MapView
Draws a Map with a camera. Make one with Map::view.
RasterTiles
A raster source and its decoded tiles.
RetryPolicy
Retrying tiles that failed to load (timeouts, network or server errors). A tile that doesn’t exist (“no tile here”) is not a failure: it is stored empty at once.
TileRequest
A tile a view needs, to load in the background with TileRequest::load and hand back with Map::insert_loaded.
VectorSource
A vector tile source and its loaded tiles.

Enums§

MapSource
A source of features for style layers.
RasterMode
How raster layers are drawn.