Skip to content

About

slippy map (openstreetmap) widget for egui

Resources

Stars

2 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Walkers, a map widget for Rust

made in Europe crates.io docs.rs

Walkers is a slippy maps widget for egui, similar to very popular Leaflet, but written in Rust. It compiles to native applications as well as WASM. See the book, with demos running right in the browser.

Screenshot

It supports OpenStreetMap, mapbox, and compatible tile servers as well as off-line tiles using the PMTiles format.

Before deploying your application, please get yourself familiar with the OpenStreetMap usage policy, and consider donating to the OpenStreetMap Foundation.

Cargo features

Raster tiles fetched over HTTP work out of the box. Everything else is behind a feature:

  • vector - drawing vector geometry, styled similarly to MapLibre style. Needs egui to be rendered with wgpu, and walkers::install_renderer to be called on startup.
  • mvt - decoding vector tiles (MVT). Enables vector.
  • pmtiles - reading tiles from .pmtiles files.
  • serde - serializing MapMemory, TileId and Position.
  • rustls-aws-lc-rs - enabled by default, uses aws-lc-rs as the rustls crypto provider. Disable default features to set up your own.

Quick start

Walkers has three main objects. Tiles downloads images from a tile map provider such as OpenStreetMap and stores them in a cache, MapMemory keeps track of the widget's state and Map is the widget itself.

use walkers::{HttpTiles, Map, MapMemory, Position, sources::OpenStreetMap, lon_lat};
use egui::{Context, CentralPanel};
use eframe::{App, Frame};

struct MyApp {
    tiles: HttpTiles,
    map_memory: MapMemory,
}

impl MyApp {
    fn new(egui_ctx: Context) -> Self {
        Self {
            tiles: HttpTiles::new(OpenStreetMap, egui_ctx),
            map_memory: MapMemory::default(),
        }
    }
}

impl App for MyApp {
    fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut Frame) {
        ui.add(Map::new(
            Some(&mut self.tiles),
            &mut self.map_memory,
            lon_lat(17.03664, 51.09916)
        ));
    }
}

The book

The book goes through Walkers one feature at a time, each with a small demo running in the page, followed by its code. To build and serve it locally, with Trunk and mdBook installed:

just book-serve

Each demo runs natively too:

cargo run -p demos -- raster

Running the demo

Native

To run demo application locally, use a default cargo run target.

cargo run

Web / WASM

cd demo_web
trunk serve --release

Android

You need to have Android SDK and cargo-ndk installed.

cd demo_android
make run-on-device

Offline maps

To obtain offline maps in .pmtiles format, you can fetch Dolnośląskie region extract from OpenFreeMap, which Walkers' own styles are made for, using:

just openfreemap-dolnoslaskie

Extracts from Protomaps, drawn with Protomaps' own styles, work as well:

just protomaps-dolnoslaskie

You can also use Overpass API to fetch hiking trails in GeoJSON format:

just overpass-trails-dolnoslaskie

Mapbox support

To enable mapbox layers, you need to define MAPBOX_ACCESS_TOKEN environment variable before building. You can get one by creating a mapbox account.

About

slippy map (openstreetmap) widget for egui

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages