pub struct TileId {
pub zoom: u8,
pub x: u32,
pub y: u32,
}Expand description
A tile identifier in a slippy-map tile grid (zoom / x / y).
Zoom level 0 has a single tile covering the world. At zoom z there
are 2^z tiles along each axis, giving 4^z tiles total.
TileId is Copy, Hash, and Ord, so it can be used directly as a
key in HashMap, BTreeMap, or sorted Vec.
Fields§
§zoom: u8Zoom level (0-22).
x: u32Column index (0 is the western-most column).
y: u32Row index (0 is the northern-most row).
Implementations§
Source§impl TileId
impl TileId
Sourcepub fn new(zoom: u8, x: u32, y: u32) -> Self
pub fn new(zoom: u8, x: u32, y: u32) -> Self
Create a new tile identifier.
§Panics (debug only)
Debug-asserts that zoom <= 22 and that x, y are within range
for the zoom level. In release builds the values are unchecked –
use new_checked when the inputs come from
untrusted sources.
Sourcepub fn new_checked(zoom: u8, x: u32, y: u32) -> Option<Self>
pub fn new_checked(zoom: u8, x: u32, y: u32) -> Option<Self>
Checked constructor that returns None if parameters are out of range.
Validates zoom <= 22 and x, y < 2^zoom.
Sourcepub fn axis_tiles(zoom: u8) -> u32
pub fn axis_tiles(zoom: u8) -> u32
Total number of tiles along one axis at this zoom level (2^zoom).
§Contract
Callers should pass zooms in 0..=MAX_ZOOM. Higher zooms are not
meaningful for this crate and may overflow shift semantics on some
targets/toolchains.
Sourcepub fn parent(&self) -> Option<TileId>
pub fn parent(&self) -> Option<TileId>
Return the parent tile (one zoom level up). Returns None at zoom 0.
The parent is the tile that fully contains this tile at the next
coarser zoom level. Used by TileManager for fallback rendering
while a tile is still loading.
Sourcepub fn children(&self) -> [TileId; 4]
pub fn children(&self) -> [TileId; 4]
Return the four children (one zoom level down).
The children are ordered: top-left, top-right, bottom-left, bottom-right.
§Note
Calling this at zoom == MAX_ZOOM produces tiles at zoom 23,
which is beyond the validated range. The engine never does this,
but callers at the boundary should be aware.
Sourcepub fn quadkey(&self) -> String
pub fn quadkey(&self) -> String
Encode this tile as a Bing Maps-style quadkey string.
Returns an empty string at zoom 0. Each character is '0'-'3',
encoding two bits per level: bit 0 from X, bit 1 from Y.
Sourcepub fn from_quadkey(key: &str) -> Option<Self>
pub fn from_quadkey(key: &str) -> Option<Self>
Decode a Bing Maps-style quadkey string into a tile ID.
Returns None if the string contains invalid characters or if the
resulting zoom exceeds MAX_ZOOM.
An empty quadkey decodes to the root tile 0/0/0.
Sourcepub fn neighbor(&self, dx: i32, dy: i32) -> Option<TileId>
pub fn neighbor(&self, dx: i32, dy: i32) -> Option<TileId>
Return the neighbouring tile in a cardinal direction at the same zoom level.
dx and dy are offsets: (-1, 0) = west, (1, 0) = east,
(0, -1) = north, (0, 1) = south. Diagonal offsets such as
(-1, -1) (north-west) are also supported.
The X axis wraps around (longitude wrap): moving west from column 0
yields column 2^zoom - 1, and vice versa. The Y axis does not
wrap: moving north from row 0 or south from the last row returns
None (there is no tile beyond the poles).
Returns None if the resulting tile would be out of the valid
Y range.