Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Vector tiles

OpenFreeMap’s vector tiles, drawn with Waymark, Walkers’ own style.

Vector tiles carry the map’s geometry and names rather than a picture of them, so it is the style that decides how they look. A StyledSources draws a Style from sources it names, here OpenFreeMap’s tiles fetched by an HttpSource. Waymark draws from a source called openmaptiles, after the OpenMapTiles schema those tiles follow, and comes in the colors of a Palette, here the dark one.

impl WaymarkMap {
    pub fn new(cc: &CreationContext<'_>) -> Self {
        let ctx = &cc.egui_ctx;
        let style = Waymark::new(Palette::dark()).build();
        let tiles = HttpSource::new(OpenFreeMap, HttpOptions::default(), ctx.clone());

        Self {
            map: StyledSources::new(style, ctx.clone()).with_tiled_source("openmaptiles", tiles),
            map_memory: MapMemory::default(),
        }
    }
}

StyledSources keeps the tiles it has fetched, so, as HttpTiles for raster tiles, it is created once and added to the map as a layer in every frame. A map can have more than one source, so there is a link to each one’s attribution.

impl App for WaymarkMap {
    fn ui(&mut self, ui: &mut Ui, _frame: &mut Frame) {
        let attributions = self.map.attributions();
        let wroclaw = lon_lat(17.03664, 51.09916);

        Map::new(None, &mut self.map_memory, wroclaw)
            .with_layer(&mut self.map, 1.0)
            .show(ui, |ui, _, _, _| {
                for attribution in attributions {
                    ui.hyperlink_to(attribution.text, attribution.url);
                }
            });
    }
}

Vector tiles are drawn with wgpu, so walkers::install_renderer has to be called once on startup, with eframe’s wgpu_render_state:

    eframe::run_native(
        &format!("Walkers: {name}"),
        Default::default(),
        Box::new(move |cc| {
            walkers::install_renderer(cc.wgpu_render_state.as_ref());
            Ok(app(&name, cc).unwrap_or_else(|| Box::new(Unknown(name))))
        }),
    )

Full source