A MapLibre GL JS wrapper for Dioxus 0.7+.
cargo add dioxus-maplibreInclude MapLibre assets in your HTML:
<link href="https://unpkg.com/maplibre-gl/dist/maplibre-gl.css" rel="stylesheet" />
<script src="https://unpkg.com/maplibre-gl/dist/maplibre-gl.js"></script>use dioxus::prelude::*;
use dioxus_maplibre::{FlyToOptions, LatLng, Map, MapHandle};
fn App() -> Element {
let mut map = use_signal(|| None::<MapHandle>);
rsx! {
Map {
style: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json",
center: LatLng::new(60.17, 24.94),
zoom: 10.0,
on_ready: move |handle| map.set(Some(handle)),
}
button {
onclick: move |_| {
if let Some(handle) = map() {
handle.fly_to(FlyToOptions {
center: Some(LatLng::new(60.17, 24.94)),
zoom: Some(12.0),
..Default::default()
});
}
},
"Fly"
}
}
}use dioxus::prelude::*;
use dioxus_maplibre::{
LatLng, LayerOptions, Map, MapLayer, MapMarker, MapSource, MapSourceKind,
GeoJsonSourceOptions,
};
use serde_json::json;
fn App() -> Element {
rsx! {
Map {
MapSource {
id: "points",
source: MapSourceKind::GeoJson(GeoJsonSourceOptions {
data: json!({"type": "FeatureCollection", "features": []}),
..Default::default()
}),
MapLayer {
options: LayerOptions::circle("point-layer", "points")
.paint(json!({"circle-radius": 5, "circle-color": "#3b82f6"})),
}
}
MapMarker {
id: "helsinki",
position: LatLng::new(60.17, 24.94),
}
}
}
}Maproot component- Event callbacks including
on_readyandon_error MapHandleimperative APIuse_map_handle()context hook- Declarative helpers:
MapSource,MapLayer,MapMarker,MapPopup,MapControl - Options/types/events exported from crate root
cargo test
cargo checkRun showcase app:
cd examples/showcase
dx serve --port 8080See CONTRIBUTING.md for full setup and e2e workflow.
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.