maplibre/style/
source.rs

1//! Vector tile data utilities.
2
3use serde::{Deserialize, Serialize};
4
5/// String url to a tile.
6pub type TileUrl = String;
7
8/// String url to a JSON tile.
9pub type TileJSONUrl = String;
10
11/// Tiles can be positioned using either the xyz coordinates or the TMS (Tile Map Service) protocol.
12#[derive(Serialize, Deserialize, Debug, Clone)]
13pub enum TileAddressingScheme {
14    #[serde(rename = "xyz")]
15    XYZ,
16    #[serde(rename = "tms")]
17    TMS,
18}
19
20impl Default for TileAddressingScheme {
21    fn default() -> Self {
22        TileAddressingScheme::XYZ
23    }
24}
25
26/// GeoJSON data — either an inline JSON value or a URL pointing to a GeoJSON file.
27#[derive(Serialize, Deserialize, Debug, Clone)]
28#[serde(untagged)]
29pub enum GeoJsonData {
30    Url(String),
31    Inline(serde_json::Value),
32}
33
34/// Source properties for a GeoJSON source.
35#[derive(Serialize, Deserialize, Debug, Clone)]
36pub struct GeoJsonSource {
37    pub data: GeoJsonData,
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub maxzoom: Option<u8>,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub minzoom: Option<u8>,
42}
43
44/// Source properties for tiles or rasters.
45#[derive(Serialize, Deserialize, Debug, Clone)]
46pub struct VectorSource {
47    /// String which contains attribution information for the used tiles.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub attribution: Option<String>,
50    /// The bounds in which tiles are available.
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub bounds: Option<(f64, f64, f64, f64)>,
53    /// Max zoom level at which tiles are available.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub maxzoom: Option<u8>,
56    /// Min zoom level at which tiles are available.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub minzoom: Option<u8>,
59    // TODO: promoteId
60    #[serde(default)]
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub scheme: Option<TileAddressingScheme>,
63    /// Array of URLs which can contain place holders like {x}, {y}, {z}.
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub tiles: Option<Vec<TileUrl>>,
66    // url: Option<TileJSONUrl>,
67    // TODO volatile
68}
69
70#[derive(Serialize, Deserialize, Debug, Clone)]
71#[serde(tag = "type")]
72pub enum Source {
73    #[serde(rename = "vector")]
74    Vector(VectorSource),
75    #[serde(rename = "raster")]
76    Raster(VectorSource), // FIXME: Does it make sense that a raster have a VectorSource?
77    #[serde(rename = "geojson")]
78    GeoJson(GeoJsonSource),
79}