dioxus_leaflet/types/
tile_layer.rs

1use serde::{Deserialize, Serialize};
2
3/// Tile layer configuration
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct TileLayer {
6    pub url: String,
7    pub attribution: String,
8    pub max_zoom: u8,
9    pub subdomains: Vec<String>,
10}
11
12impl TileLayer {
13    /// OpenStreetMap tile layer (default)
14    pub fn openstreetmap() -> Self {
15        Self {
16            url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png".to_string(),
17            attribution: "&copy; <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors".to_string(),
18            max_zoom: 19,
19            subdomains: vec!["a".to_string(), "b".to_string(), "c".to_string()],
20        }
21    }
22
23    /// Satellite imagery tile layer
24    pub fn satellite() -> Self {
25        Self {
26            url: "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}".to_string(),
27            attribution: "Tiles &copy; Esri".to_string(),
28            max_zoom: 18,
29            subdomains: vec![],
30        }
31    }
32}
33
34impl Default for TileLayer {
35    fn default() -> Self {
36        Self::openstreetmap()
37    }
38}