Skip to main content

TileId

Struct TileId 

Source
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: u8

Zoom level (0-22).

§x: u32

Column index (0 is the western-most column).

§y: u32

Row index (0 is the northern-most row).

Implementations§

Source§

impl TileId

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for TileId

Source§

fn clone(&self) -> TileId

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TileId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for TileId

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for TileId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats as "zoom/x/y" (the standard OSM URL path component).

Source§

impl Hash for TileId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for TileId

Source§

fn cmp(&self, other: &TileId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for TileId

Source§

fn eq(&self, other: &TileId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for TileId

Source§

fn partial_cmp(&self, other: &TileId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for TileId

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for TileId

Source§

impl Eq for TileId

Source§

impl StructuralPartialEq for TileId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,