Martin Tile Server

repository·main·Indexed 25 days ago

https://github.com/maplibre/martin

A high-performance Rust-based tile server that generates vector tiles on the fly from PostGIS, PMTiles, MBTiles, and GeoJSON sources. Martin supports advanced features like tile compositing, passthrough proxying, and serving map styles, sprites, and fonts. It includes a Web UI for tile catalog browsing, style editing via Maputnik, and performance analytics.

Tokens
57.9K
Snippets
140
Records
339
Agent score
87%

What's inside Martin

  1. Overview of martin-core features

    main
    The martin-core library provides the fundamental building blocks for the Martin tile server. It supports a wide variety of tile sources and map resources, including various file formats, database tables/functions, and web resources.
  2. Overview of Martin tile server features

    main

    Martin is a high-performance tile server written in Rust designed to generate vector tiles on the fly and serve them from various sources.

    Supported Tile Sources:

    • PostGIS: Automatically discovers compatible tables and functions in PostgreSQL databases.
    • PMTiles: Serves from local files or over HTTP.
    • MBTiles: Serves from MBTiles files.
    • GeoJSON: Converts GeoJSON files to vector tiles on the fly.

    Advanced Capabilities:

    • Passthrough: Proxy tiles from an upstream HTTP tile server.
    • Composite Sources: Combine multiple tile sources into a single endpoint.
    • Style & Asset Support: Serve map styles and generate sprites or font glyphs on the fly.
    • Bulk Generation: Use the martin-cp tool to generate tiles in bulk from supported sources into an MBTiles file.
    • MBTiles Management: Use the mbtiles tool to examine, copy, validate, compare, and apply diffs between MBTiles files.
  3. Overview of Martin tile server capabilities

    main

    Martin is a high-performance tile server written in Rust designed to serve vector tiles on the fly. It supports combining multiple tile sources into a single endpoint and can serve styles, sprites, and font glyphs.

    Supported tile sources include:

    • PostGIS: Automatic discovery of compatible tables and functions.
    • PMTiles: Local files or remote files via HTTP.
    • MBTiles: Local files.
    • GeoJSON: Local files.

    Additional capabilities:

    • Bulk Generation: Use martin-cp to generate tiles in bulk into an MBTiles archive.
    • MBTiles Management: Use the mbtiles tool to examine, copy, validate, compare, and apply diffs between MBTiles files.
  4. Martin Web UI Features

    main

    The Martin Web UI provides several tools for interacting with tiles served by Martin:

    • Tile Catalog: Browse and preview all available tile sources.
    • Style Editor: Visual style editing with an integrated Maputnik editor.
    • Font Catalog: View and manage font collections.
    • Sprite Catalog: Browse and download sprite collections.
    • Analytics: Real-time performance metrics and usage statistics.
  5. Understand MBTiles Schemas in the mbtiles tool

    main

    The mbtiles tool extends the original MBTiles specification by supporting several different schema types for storing tile data. It can convert between these schemas, generate diffs between files of any schema, and merge multiple schema files.

    All schemas include a metadata table containing key/value pairs like tileset name, format, and bounds.

  6. Understand Martin's integration patterns

    main

    Martin supports several data integration patterns depending on your source type:

    PostgreSQL Integration

    Martin connects via a connection string and uses a deadpool-postgres connection pool. It automatically discovers tables with geometry columns and functions that return MVT data by querying geometry_columns and pg_proc.

    File Source Integration

    Martin can serve tiles from local or remote files:

    • MBTiles: SQLite-based format.
    • PMTiles: Binary format (uses HTTP range requests for remote files).
    • COG (Cloud Optimized GeoTIFF): Uses a TIFF parser and HTTP range requests for remote access.
    • Cloud Storage: Supports S3, Azure, and GCP via the object_store crate.

    GeoJSON Integration

    GeoJSON files are loaded into memory, reprojected to Web Mercator, and indexed using a packed Hilbert R-tree for real-time MVT encoding on demand.

  7. Understand Martin's Core Components and Crates

    main

    Martin is organized into four primary Rust crates, each serving a specific role in the tile serving ecosystem:

    • martin: The main tile server binary. It provides the HTTP service layer (using Actix-Web), handles request routing, configuration parsing (CLI, env vars, config files), and manages runtime source reloading. It also serves the Web UI.
    • martin-core: The library containing core abstractions. It implements tile source traits for PostgreSQL, MBTiles, PMTiles, and Cloud Optimized GeoTIFF (COG), and handles resource generation for sprites, fonts, and styles.
    • mbtiles: A library and CLI tool dedicated to MBTiles. It supports SQLite-based reading/writing, metadata management, tile compression (gzip, brotli), and schema management.
    • martin-tile-utils: Low-level utilities for tile coordinate conversions, encoding/decoding, and bounding box calculations.
  8. Choose a tile source type for Martin

    main

    Martin supports several types of tile sources depending on your data requirements for performance, flexibility, and scale:

    • Tile Archives (MBTiles, PMTiles): Best for high performance and memory efficiency. Use these when you have pre-generated vector or raster tiles.
    • GeoJSON Sources: Best for semi-static, relatively small datasets that do not justify the overhead of a tile archive.
    • PostgreSQL Connections (Tables or Functions): Best for flexible data that may need to be updated in real-time.

    Comparison Summary:

    FeatureDatabase (PG)Tile ArchivesGeoJSON
    FlexibilityHigh (Real-time updates)Low (Pre-generated)Medium
    PerformanceVariableHigh (Compact/Efficient)Variable
    Best Use CaseDynamic dataHigh-scale servingSmall, static data
  9. Use PostgreSQL tables as vector tile sources

    main

    Martin can automatically publish PostgreSQL tables or views as vector tile sources. When a PostgreSQL connection string is provided, Martin identifies all tables with at least one geometry column and publishes them.

    Key behaviors:

    • Geometry Columns: If a geometry column has an SRID of 0, you must set a default SRID in the configuration, otherwise the table will be ignored.
    • Properties: All non-geometry columns in the table are automatically published as vector tile feature tags (properties).
    • Automatic Discovery: Martin uses database identifiers for the default name and description in the generated TileJSON.
  10. Provide SSL certificates for PostgreSQL

    main

    SSL certificates can be provided to Martin in two ways:

    1. Configuration file: Specify certificate paths within your Martin configuration.
    2. Environment variables: Use environment variables (following standard psql conventions) to provide certificates. Environment variables apply to all PostgreSQL connections managed by Martin.
  11. Use Composite Sources to combine multiple sources

    main

    Composite Sources allow you to combine multiple data sources into a single endpoint. A composite source is defined by listing multiple source names separated by commas: {source1},{source2},...,{sourceN}.

    When using a composite source:

    • The TileJSON endpoint is available at /{source1},{source2},...,{sourceN}.
    • Tiles are available at /{source1},{source2},...,{sourceN}/{z}/{x}/{y}.
    • Individual sources within the composite can be accessed via their specific {source_name} using the source-layer property in your map client.