utiles/mbt/
tiles_row.rs

1use utiles_core::Tile;
2
3use crate::core::tile_type::tiletype_str;
4use crate::core::{TileLike, flipy};
5
6/// Mbtiles Tile Row struct
7#[derive(Debug, Clone)]
8pub struct MbtTileRow {
9    /// `zoom_level` INTEGER NOT NULL -- z
10    pub zoom_level: u8,
11    /// `tile_column` INTEGER NOT NULL -- x
12    pub tile_column: u32,
13    /// `tile_row` INTEGER NOT NULL -- y (flipped)
14    pub tile_row: u32,
15    /// `tile_data` BLOB NOT NULL -- tile data
16    pub tile_data: Vec<u8>,
17}
18
19impl MbtTileRow {
20    /// Create a new `MbtTileRow`
21    #[must_use]
22    pub fn new(
23        zoom_level: u8,
24        tile_column: u32,
25        tile_row: u32,
26        tile_data: Vec<u8>,
27    ) -> Self {
28        Self {
29            zoom_level,
30            tile_column,
31            tile_row,
32            tile_data,
33        }
34    }
35}
36
37impl TileLike for MbtTileRow {
38    fn x(&self) -> u32 {
39        self.tile_column
40    }
41
42    fn y(&self) -> u32 {
43        flipy(self.tile_row, self.zoom_level)
44    }
45
46    fn z(&self) -> u8 {
47        self.zoom_level
48    }
49}
50
51impl MbtTileRow {
52    /// Return the file extension of the tile based on the `tile_data`
53    #[must_use]
54    pub fn extension(&self) -> String {
55        tiletype_str(&self.tile_data)
56    }
57}
58
59impl From<MbtTileRow> for Tile {
60    fn from(row: MbtTileRow) -> Self {
61        row.tile()
62    }
63}