Expand description
§MapLibre-native-rs
Rust bindings to the MapLibre Native map rendering engine.
§Usage
We use maplibre-natives’ “core library”, a static, pre-compiled library.
We also allow you to compile this yourself.
Instructions for this are below.
§Backend Features
This crate supports multiple rendering backends:
vulkan(default on Linux/Windows):cargo build --features vulkanopengl(cross-platform):cargo build --features openglmetal(default on macOS/iOS):cargo build --features metal
If no feature is specified, the crate will automatically select the platform-appropriate default backend.
We also support the following other features:
poolA tile rendering pool for building tile servers. SeeSingeThreadedRenderingPoolfor further detailsloglogging via theloglibrary
At its core, we work as follows:
use maplibre_native::{ImageRendererBuilder, Image};
use std::num::NonZeroU32;
let mut renderer = ImageRendererBuilder::new()
.with_size(NonZeroU32::new(512).unwrap(),NonZeroU32::new(512).unwrap())
.build_static_renderer();
renderer.load_style_from_url(&"https://demotiles.maplibre.org/style.json".parse().unwrap());
let image: Image = renderer.render_static(0.0, 0.0, 0.0, 0.0, 0.0).unwrap();
// Access the underlying ImageBuffer for all operations
let img_buffer = image.as_image();
println!("Image dimensions: {}x{}", img_buffer.width(), img_buffer.height());
img_buffer.save("map.png").unwrap();TIP: Next to the static rendering map mode, we also have continous and a tile based one. Continous is desiged to be interactive, while the tile based one is primarily for tile servers
§Platform Support
The following platform and rendering-API combinations are supported and tested in CI:
| Platform | Metal | Vulkan | OpenGL |
|---|---|---|---|
| Linux x86 | ❌ | ✅ | ✅ |
| Linux ARM | ❌ | ✅ | ✅ |
| Windows x86 | ❌ | 🟨 | 🟨 |
| Windows ARM | ❌ | 🟨 | 🟨 |
| macOS ARM | ✅ | ✅1 | ❌ |
§Dependencies
This command will install the required dependencies on Linux or macOS for the vulkan backend.
You may also use it with opengl parameter on Linux.
It is OK to run this command multiple times for each backend.
just install-dependencies vulkan§Getting the core library
Since we wrap the Maplibre native library, we need this and its headers to be included.
By default the library will be downloaded and build locally during the build process of maplibre-native-rs.
We can get the library and headers from two places:
default: library will be downloaded and build locally during the build process of maplibre-native-rs
The specific version is controllable from the `build.rs` file.downloaded from the releases page
The specific version of MapLibre Native used is controlled by
package.metadata.mln.releaseinCargo.toml. This dependency is automatically updated via a GitHub workflow on the 1st of each month repository. A pull request is created if an update is available.if the env vars
MLN_PRECOMPILEMLN_CORE_LIBRARY_PATHandMLN_CORE_HEADERS_PATHare set: from local disk via the environment variablesIf you don’t want to allow network access during buildscript execution, we allow you to download the release and tell us where you have downloaded the contents. You can also build from source by following the steps that maplibre-native does in CI to produce the artefacts.
§Development
- This project is easier to develop with just, a modern alternative to
make. Install it withcargo install just. - To get a list of available commands, run
just. - To run tests, use
just test.
§Getting Involved
Join the #maplibre-martin slack channel at OSMUS – automatic invite is at https://slack.openstreetmap.us/
§License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT) at your option.
§Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.
§MapLibre Native Licence
This crate incorporates MapLibre Native assets during compilation by downloading and statically linking them. As a result, any project using this crate must comply with the MapLibre Native License (BSD 2-Clause) requirements for binary distribution. This includes providing proper attribution and including the license text with your distributed binaries or source code.
Vulkan support on macos is provided via
MoltenVK. There is a slight performance overhead for this with little upsides. Both Metal and Vulkan run through the same extensive test suite upstream. You can use Vulkan if you find a bug in the Metal implementation until we have fixed it upstream. ↩
Modules§
- callbacks
- Callback types used by the renderer event API.
- layers
- FFI bindings for map layer operations.
- style
- Style abstractions for sources, layers, and images.
- tile_
server_ options - Tile server options builder.
Structs§
- Continuous
- Internal state type to render continuously
- GeoJson
Source - A
GeoJSONsource for rendering geographic data. - Height
- A height value
- Image
- A rendered map image.
- Image
Renderer - Configuration options for a tile server.
- Image
Renderer Builder - Builder for configuring
ImageRendererinstances - Latitude
- Latitude coordinate value.
- Longitude
- Longitude coordinate value.
- MapDebug
Options - Debug visualization options for map rendering.
- MapLoad
Error - Map loading error types.
- MapMode
- Map rendering mode configuration.
- MapObserver
- Object to modify the map observer callbacks
- MapObserver
Camera Change Mode - Camera change mode for map observer callbacks.
- Resource
Options - Resource Options
- Screen
Coordinate - A position in screen coordinates
- Single
Threaded Render Pool - A thread-safe rendering pool that serializes MapLibre Native tile rendering operations through a single worker thread.
- Size
- A size
- Source
Id - Stable source ID handle that can be used after a source object is moved.
- Static
- Internal state type to render a static map image.
- Style
- The style of the map
- Symbol
Layer - A symbol layer for rendering labels and icons on the map.
- Tile
- Internal state type to render a map tile.
- Width
- A width value
- X
- An x value
- Y
- An y value
Enums§
- Rendering
Error - Errors that can occur during map rendering operations.
- Single
Threaded Render Pool Error - Errors that can occur in the single-threaded render pool.
- Style
Layer - A style layer for rendering.
- Style
Source - A style source for rendering data layers.
Traits§
- Style
Source Ref - Shared interface for style sources that expose a stable source ID.
Functions§
- set_
log_ thread_ enabled - Enable or disable the internal logging thread