Getting Started

Configuration

How to configure Tileserver RS

Tileserver RS uses a TOML configuration file to define tile sources, styles, and server settings.

Configuration File

Create a config.toml file. Note that root-level options (fonts, files) must come before any [section] headers due to TOML parsing rules:

# Root-level options (must come before [sections])
fonts = "/data/fonts"
files = "/data/files"

[server]
host = "0.0.0.0"
port = 8080
cors_origins = ["*"]

[telemetry]
enabled = false

[[sources]]
id = "openmaptiles"
type = "pmtiles"
path = "/data/tiles.pmtiles"
name = "OpenMapTiles"
attribution = "© OpenMapTiles © OpenStreetMap contributors"

[[sources]]
id = "terrain"
type = "mbtiles"
path = "/data/terrain.mbtiles"
name = "Terrain Data"

[[styles]]
id = "osm-bright"
path = "/data/styles/osm-bright/style.json"
Root-level keys like fonts and files must appear before any section headers ([server], [telemetry], etc.) in the TOML file. Otherwise they will be incorrectly parsed as part of the preceding section.

Server Configuration

OptionDescriptionDefault
hostIP address to bind to0.0.0.0
portPort number8080
cors_originsAllowed CORS origins["*"]

Source Configuration

File-based sources (PMTiles, MBTiles) are configured in [[sources]] arrays. PostgreSQL sources are configured separately in [postgres].

Each file source requires:

OptionDescriptionRequired
idUnique identifierYes
typepmtiles or mbtilesYes
pathPath to tile file (local or URL)Yes
nameDisplay nameNo
attributionMap attributionNo

PMTiles Sources

[[sources]]
id = "world"
type = "pmtiles"
path = "/data/world.pmtiles"
# Or from a URL (requires http feature)
# path = "https://example.com/tiles.pmtiles"

MBTiles Sources

[[sources]]
id = "local-data"
type = "mbtiles"
path = "/data/local.mbtiles"

PostgreSQL Configuration

PostgreSQL support requires the postgres feature flag when building from source.

Configure PostgreSQL connection and sources in the [postgres] section:

[postgres]
connection_string = "postgresql://user:pass@localhost:5432/tiles"
pool_size = 20

# Table sources (recommended - auto-generates optimized SQL)
[[postgres.tables]]
id = "points"
table = "my_points"
geometry_column = "geom"
minzoom = 0
maxzoom = 14

# Function sources (for custom SQL logic)
[[postgres.functions]]
id = "custom_tiles"
function = "get_tiles"
minzoom = 0
maxzoom = 14

Connection Options

OptionDescriptionDefault
connection_stringPostgreSQL connection URLRequired
pool_sizeMaximum connections20
ssl_certPath to SSL certificate-
ssl_keyPath to SSL key-
ssl_root_certPath to SSL root certificate-

Table Sources

Table sources auto-discover geometry columns and generate optimized tile queries with spatial index filtering.

[[postgres.tables]]
id = "buildings"
schema = "public"
table = "buildings"
geometry_column = "geom"      # Optional, auto-detected
id_column = "id"              # Optional, for feature IDs
properties = ["name", "type"] # Optional, defaults to all columns
minzoom = 0
maxzoom = 14
bounds = [-180, -85, 180, 85] # Optional, auto-detected
extent = 4096                 # MVT extent (default: 4096)
buffer = 64                   # Tile buffer in pixels (default: 64)
max_features = 10000          # Optional feature limit per tile
OptionDescriptionDefault
idUnique source identifierRequired
schemaPostgreSQL schemapublic
tableTable nameRequired
geometry_columnGeometry column nameAuto-detected
id_columnColumn for feature IDs-
propertiesColumns to includeAll non-geometry columns
minzoomMinimum zoom level0
maxzoomMaximum zoom level22
boundsBounds [west, south, east, north]Auto-detected
extentMVT tile extent4096
bufferTile buffer in pixels64
max_featuresMax features per tileUnlimited
Ensure your geometry column has a spatial index (GIST) for optimal performance. The server will warn if no index is found.

Function Sources

Function sources call PostgreSQL functions that return MVT tiles directly.

[[postgres.functions]]
id = "dynamic_tiles"
schema = "public"
function = "get_tiles"
minzoom = 0
maxzoom = 14
bounds = [-180, -85, 180, 85]

The function must have one of these signatures:

-- Simple (z, x, y)
CREATE FUNCTION get_tiles(z integer, x integer, y integer)
    RETURNS bytea AS $$ ... $$ LANGUAGE plpgsql;

-- With query parameters (z, x, y, query)
CREATE FUNCTION get_tiles(z integer, x integer, y integer, query json)
    RETURNS bytea AS $$ ... $$ LANGUAGE plpgsql;
OptionDescriptionDefault
idUnique source identifierRequired
schemaPostgreSQL schemapublic
functionFunction nameRequired
minzoomMinimum zoom level0
maxzoomMaximum zoom level22
boundsBounds [west, south, east, north]-

Table vs Function Sources

AspectTable SourceFunction Source
SetupMinimal configRequires SQL function
PerformanceOptimized (uses spatial index)Depends on function
FlexibilityFixed schemaCustom SQL logic
Use caseStandard tablesComplex queries, joins

Style Configuration

[[styles]]
id = "bright"
path = "/data/styles/bright/style.json"
name = "Bright Style"  # Optional display name

Styles should include sprites alongside the style.json:

styles/
└── bright/
    ├── style.json
    ├── sprite.json
    ├── sprite.png
    ├── sprite@2x.json
    └── sprite@2x.png

Font Configuration

Fonts are required for rendering text labels. Configure the fonts directory:

fonts = "/data/fonts"

The fonts directory should contain subdirectories for each font family with PBF glyph files:

fonts/
├── Noto Sans Regular/
│   ├── 0-255.pbf
│   ├── 256-511.pbf
│   └── ...
├── Noto Sans Medium/
│   ├── 0-255.pbf
│   └── ...
└── Open Sans Bold/
    └── ...
Font glyph PBF files can be generated using tools like node-fontnik or downloaded from OpenMapTiles fonts.

Static Files Configuration

Optionally serve static files from a directory:

files = "/data/files"

Files in this directory will be accessible at /files/{filepath}. This is useful for:

  • GeoJSON overlays
  • Custom marker icons
  • Other static assets

Environment Variables

VariableDescriptionDefault
RUST_LOGLog level (error, warn, info, debug, trace)info
CONFIG_PATHPath to config fileconfig.toml
HOSTOverride server host-
PORTOverride server port-

CLI Options

tileserver-rs --help

Options:
  -c, --config <FILE>  Path to configuration file [default: config.toml]
  -h, --host <HOST>    Override server host
  -p, --port <PORT>    Override server port
  -v, --verbose        Enable verbose logging
      --help           Print help
      --version        Print version