1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Vector tile data utilities.

use serde::{Deserialize, Serialize};

/// String url to a tile.
pub type TileUrl = String;

/// String url to a JSON tile.
pub type TileJSONUrl = String;

/// Tiles can be positioned using either the xyz coordinates or the TMS (Tile Map Service) protocol.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum TileAddressingScheme {
    #[serde(rename = "xyz")]
    XYZ,
    #[serde(rename = "tms")]
    TMS,
}

impl Default for TileAddressingScheme {
    fn default() -> Self {
        TileAddressingScheme::XYZ
    }
}

/// Source properties for tiles or rasters.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct VectorSource {
    /// String which contains attribution information for the used tiles.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attribution: Option<String>,
    /// The bounds in which tiles are available.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bounds: Option<(f64, f64, f64, f64)>,
    /// Max zoom level at which tiles are available.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub maxzoom: Option<u8>,
    /// Min zoom level at which tiles are available.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub minzoom: Option<u8>,
    // TODO: promoteId
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub scheme: Option<TileAddressingScheme>,
    /// Array of URLs which can contain place holders like {x}, {y}, {z}.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tiles: Option<TileUrl>,
    // url: Option<TileJSONUrl>,
    // TODO volatile
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type")]
pub enum Source {
    #[serde(rename = "vector")]
    Vector(VectorSource),
    #[serde(rename = "raster")]
    Raster(VectorSource), // FIXME: Does it make sense that a raster have a VectorSource?
}