Dioxus Leaflet
A general-purpose Leaflet map component for Dioxus applications. This crate provides an easy-to-use, reactive map component that integrates seamlessly with Dioxus applications.
Features
- Easy-to-use map component with customizable markers
- Interactive markers with popups and custom styling
- Extensible marker system with custom icons and data
- CDN-based Leaflet integration - no additional setup required
- Responsive design with customizable dimensions
- Customizable tile layers including OpenStreetMap and satellite imagery
- Configurable map options for zoom, dragging, and interaction controls
- Event handling for map clicks, marker clicks, and map movements
Screenshots


Installation
Add this to your Cargo.toml:
[]
= "0.1.4"
= "0.6.3"
Quick Start
Here's a simple example to get you started:
use *;
use ;
Core Components
Map Component
The main Map component provides a full-featured Leaflet map:
rsx!
Map Properties
| Property | Type | Default | Description |
|---|---|---|---|
initial_position |
MapPosition |
London coordinates | Initial map center and zoom |
markers |
Vec<MapMarker> |
Empty | Markers to display on the map |
height |
String |
"500px" |
Height of the map container |
width |
String |
"100%" |
Width of the map container |
options |
MapOptions |
Default | Map configuration options |
class |
String |
"" |
Additional CSS classes |
style |
String |
"" |
Additional CSS styles |
on_marker_click |
EventHandler<MapMarker> |
None | Callback when marker is clicked |
on_map_click |
EventHandler<MapPosition> |
None | Callback when map is clicked |
on_map_move |
EventHandler<MapPosition> |
None | Callback when map is moved |
Working with Markers
Basic Markers
let marker = new;
Advanced Markers
let marker = new
.with_description
.with_custom_data
.with_custom_data
.with_popup_options;
Custom Marker Icons
use MarkerIcon;
let custom_icon = new
.with_size
.with_anchor;
let marker = new
.with_icon;
Map Configuration
Map Options
Customize map behavior with MapOptions. Options will use sensible defaults if not specified:
use ;
// Full configuration with all options specified
let options = MapOptions ;
// Minimal configuration - specify only what you want to customize
let minimal_options = MapOptions ;
// Use default configuration
let default_options = default; // All options set to sensible defaults
rsx!
Available Map Options
| Option | Type | Default | Description |
|---|---|---|---|
zoom_control |
Option<bool> |
true |
Show/hide zoom control buttons |
scroll_wheel_zoom |
Option<bool> |
true |
Enable/disable scroll wheel zooming |
double_click_zoom |
Option<bool> |
true |
Enable/disable double-click zooming |
touch_zoom |
Option<bool> |
true |
Enable/disable touch/pinch zooming |
dragging |
Option<bool> |
true |
Enable/disable map dragging |
keyboard |
Option<bool> |
true |
Enable/disable keyboard navigation |
attribution_control |
Option<bool> |
true |
Show/hide attribution control |
tile_layer |
Option<TileLayer> |
OpenStreetMap | Tile layer configuration |
Tile Layers
Choose from different tile layer providers:
use TileLayer;
// OpenStreetMap (default)
let osm_tiles = openstreetmap;
// Satellite imagery
let satellite_tiles = satellite;
// Custom tile layer
let custom_tiles = TileLayer ;
Event Handling
Handle various map and marker events:
Styling
CSS Classes
The component uses these CSS classes that you can style:
.dioxus-leaflet-container- Main container.dioxus-leaflet-map- Map element
Custom Styling
}
}
Examples
Tourist Map
use *;
use ;
Real-time Location Tracking
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or Apache 2.0)
- MIT License (LICENSE-MIT or MIT)
at your option.
Acknowledgments
- Leaflet - The amazing mapping library this component wraps
- Dioxus - The reactive UI library for Rust
- OpenStreetMap - Free geographic data used in examples
Note: This crate requires an internet connection to load Leaflet CSS and JavaScript from CDN. If you need offline support, consider hosting the Leaflet files locally and modifying the component accordingly.