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
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
| Operation | Function | Purpose |
|---|---|---|
| Create | createOrUpdate(z, x, y) | Creates or updates tile coordinate |
| Key Generation | getKey(tileCoord) | Creates string key "z/x/y" |
| Parsing | fromKey(key) | Parses string key to coordinate |
| Hashing | hash(tileCoord) | Creates numeric hash for indexing |
| Validation | withinExtentAndZ(tileCoord, tileGrid) | Checks bounds and zoom validity |
Tile Coordinate Conversion Flow
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
Key TileGrid Operations
| Method | Line Range | Purpose |
|---|---|---|
| forEachTileCoord() | 235-242 | Iterates tiles in extent |
| getTileRangeForExtentAndZ() | 426-434 | Gets tile range for extent/zoom |
| getTileCoordForCoordAndZ() | 571-579 | Map coordinate to tile coordinate |
| getTileCoordExtent() | 458-467 | Tile coordinate to geographic extent |
| getZForResolution() | 634-641 | Resolution to zoom level |
| getFullTileRange() | 608-615 | Complete 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
URL Template Features
The URL generation system supports several template placeholder types:
| Placeholder | Purpose | Example |
|---|---|---|
{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
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.