Skip to content

Tile System

The tile system provides the foundational infrastructure for managing tiled map data in OpenLayers. It handles tile grid definitions, coordinate system conversions between geographic and tile coordinates, URL generation for tile requests, and spatial indexing for efficient tile retrieval. This system forms the backbone for all tiled data sources including XYZ, WMTS, and other tile-based services.

For information about specific tile sources that use this system, see Source System. For details about how tiles are rendered, see Canvas Rendering Pipeline.

Core Architecture

The tile system consists of three primary components that work together to manage the tile-based data flow:

Tile System Component Architecture

SVG
100%

Tile Coordinate System

The tile coordinate system represents tiles using a three-element array [z, x, y] where z is the zoom level, x is the column, and y is the row. This system provides the foundation for indexing and addressing individual tiles within a tile grid.

Tile Coordinate Operations

OperationFunctionPurpose
CreatecreateOrUpdate(z, x, y)Creates or updates tile coordinate
Key GenerationgetKey(tileCoord)Creates string key "z/x/y"
ParsingfromKey(key)Parses string key to coordinate
Hashinghash(tileCoord)Creates numeric hash for indexing
ValidationwithinExtentAndZ(tileCoord, tileGrid)Checks bounds and zoom validity

Tile Coordinate Conversion Flow

SVG
100%

Tile Grid Management

The TileGrid class manages the mathematical relationship between geographic coordinates and tile coordinates. It defines resolution levels, tile sizes, origins, and spatial extents that determine how the continuous geographic space is discretized into tiles.

TileGrid Configuration

SVG
100%

Key TileGrid Operations

MethodLine RangePurpose
forEachTileCoord()235-242Iterates tiles in extent
getTileRangeForExtentAndZ()426-434Gets tile range for extent/zoom
getTileCoordForCoordAndZ()571-579Map coordinate to tile coordinate
getTileCoordExtent()458-467Tile coordinate to geographic extent
getZForResolution()634-641Resolution to zoom level
getFullTileRange()608-615Complete tile range for zoom level

URL Generation System

The URL generation system creates tile request URLs from templates and tile coordinates. It supports template-based URL construction with placeholder substitution and load balancing across multiple server endpoints.

URL Template Processing

SVG
100%

URL Template Features

The URL generation system supports several template placeholder types:

PlaceholderPurposeExample
{z}Zoom level{z} → 10
{x}Tile column{x} → 512
{y}Tile row{y} → 256
{-y}Inverted Y coordinate{-y} → 767 (when maxY=1023)
{1-3}Server selection{1-3} → 1, 2, or 3

The {-y} placeholder requires a TileGrid instance to calculate the inverted Y coordinate using getFullTileRange() to determine the maximum Y value for the zoom level.

Integration with Data Sources

The tile system integrates with various tile sources through a standardized interface that combines tile grids, URL functions, and coordinate management:

Tile Source Integration Pattern

SVG
100%

The tile system provides the mathematical and URL generation foundation that enables tile sources to efficiently load, cache, and display tiled geographic data across different coordinate systems and server configurations.