### Setup Database for Tilefeed Source: https://github.com/muimsd/tilefeed/blob/main/examples/serve-with-simplification/README.md Initializes the PostgreSQL database required for the tilefeed example. It creates a new database and imports the schema from the provided SQL file. ```bash createdb tilefeed_example psql -d tilefeed_example < examples/serve-with-simplification/setup.sql ``` -------------------------------- ### Webhook Receiver Example (Node.js/Express) Source: https://context7.com/muimsd/tilefeed/llms.txt An example Node.js Express application demonstrating how to receive and process webhook notifications from the tilefeed service. It includes middleware for parsing JSON bodies and logic for verifying the HMAC signature to ensure the request's authenticity. The example logs details about tile updates or generation completion. ```javascript const express = require('express'); const crypto = require('crypto'); const app = express(); app.use(express.json()); const WEBHOOK_SECRET = 'my-signing-secret'; app.post('/hooks/tilefeed', (req, res) => { // Verify HMAC signature const signature = req.headers['x-tilefeed-signature']; if (signature && WEBHOOK_SECRET) { const expectedSig = 'sha256=' + crypto .createHmac('sha256', WEBHOOK_SECRET) .update(JSON.stringify(req.body)) .digest('hex'); if (signature !== expectedSig) { return res.status(401).send('Invalid signature'); } } const { event, source, tiles_updated, affected_zooms, max_zoom } = req.body; if (event === 'update_complete') { console.log(`Tiles updated: ${tiles_updated} in ${source}`); console.log(`Affected zooms: ${affected_zooms.join(', ')}`); console.log(`Max zoom: ${max_zoom}`); // Invalidate CDN cache, notify clients, etc. } else if (event === 'generate_complete') { console.log(`Full generation complete for ${source}`); } res.status(200).send('OK'); }); app.listen(9000); ``` -------------------------------- ### Start tilefeed Built-in Server Source: https://github.com/muimsd/tilefeed/blob/main/docs/serving.md Starts the tilefeed HTTP server. It generates tiles, begins serving them, and monitors for changes to re-generate tiles incrementally. Configuration can be provided via a TOML file. ```bash tilefeed serve tilefeed -c myconfig.toml serve ``` -------------------------------- ### Setup and Verify Foreign Table Source: https://github.com/muimsd/tilefeed/blob/main/examples/ogr-fdw/README.md Steps to set up the foreign data source by editing the setup SQL file and then creating and verifying the foreign table within the PostgreSQL database. ```bash createdb tilefeed_ogr_example psql -d tilefeed_ogr_example < examples/ogr-fdw/setup.sql psql -d tilefeed_ogr_example -c "\dt+ buildings" ``` -------------------------------- ### Install ogr_fdw Extension Source: https://github.com/muimsd/tilefeed/blob/main/examples/ogr-fdw/README.md Instructions for installing the ogr_fdw PostgreSQL extension on Debian/Ubuntu, macOS using Homebrew, or by compiling from source. ```bash # Debian/Ubuntu sudo apt install postgresql-17-ogr-fdw # macOS (Homebrew) brew install pgsql-ogr-fdw # From source git clone https://github.com/pramsey/pgsql-ogr-fdw.git cd pgsql-ogr-fdw make && sudo make install ``` -------------------------------- ### Setup and Configure Database Environment Source: https://github.com/muimsd/tilefeed/blob/main/examples/local-parks/README.md Commands to initialize the PostgreSQL database with sample spatial data and configure environment variables for the tilefeed application. ```bash createdb tilefeed_example psql -d tilefeed_example < examples/local-parks/setup.sql export TILES_DATABASE__USER=myuser export TILES_DATABASE__PASSWORD=mypassword ``` -------------------------------- ### Run Tilefeed Server Source: https://github.com/muimsd/tilefeed/blob/main/examples/serve-with-simplification/README.md Starts the tilefeed HTTP server using a specific configuration file. This command enables the generation, watching, and serving of tiles. ```bash cargo run --release -- -c examples/serve-with-simplification/config.toml serve ``` -------------------------------- ### Configure and Interact with Tile Server Source: https://context7.com/muimsd/tilefeed/llms.txt Configuration settings for the tile server and command-line examples for fetching tiles, metadata, and performing health checks. It demonstrates ETag usage for efficient caching. ```toml [serve] host = "0.0.0.0" port = 3000 cors_origins = ["http://localhost:8080"] ``` ```bash tilefeed serve curl http://localhost:3000/basemap/12/655/1583.pbf -o tile.pbf curl http://localhost:3000/basemap.json curl http://localhost:3000/health curl -H "If-None-Match: \"abc123...\"" http://localhost:3000/basemap/12/655/1583.pbf ``` -------------------------------- ### Multi-Source Configuration (TOML) Source: https://context7.com/muimsd/tilefeed/llms.txt Demonstrates how to configure multiple independent tile sources within the same project. This allows for different data sources, backends, and zoom level configurations to be managed separately. The example includes settings for database connections and server host/port. ```toml [database] host = "localhost" port = 5432 user = "postgres" password = "postgres" dbname = "geodata" [serve] host = "0.0.0.0" port = 3000 ``` -------------------------------- ### Docker Deployment Configuration Source: https://context7.com/muimsd/tilefeed/llms.txt Configuration details for deploying Tilefeed using Docker Compose, including database setup and environment variables. ```APIDOC ## Docker Deployment ### Description Instructions and configuration for deploying Tilefeed with Docker Compose, including PostGIS integration. ### docker-compose.yml ```yaml version: '3.8' services: db: image: postgis/postgis:16-3.4 environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: geodata volumes: - pgdata:/var/lib/postgresql/data - ./sql/setup_notify.sql:/docker-entrypoint-initdb.d/01-notify.sql ports: - "5432:5432" tilefeed: build: . depends_on: - db environment: TILES_DATABASE__HOST: db TILES_DATABASE__PORT: 5432 TILES_DATABASE__USER: postgres TILES_DATABASE__PASSWORD: postgres TILES_DATABASE__DBNAME: geodata volumes: - ./config.toml:/data/config.toml - ./tiles:/data/tiles ports: - "3000:3000" command: serve volumes: pgdata: ``` ### Docker Commands - **Start services**: `docker compose up -d` - **Rebuild after code changes**: `docker compose up --build` - **View logs**: `docker compose logs -f tilefeed` ``` -------------------------------- ### GET / {z}/{x}/{y}.pbf Source: https://context7.com/muimsd/tilefeed/llms.txt Fetches a vector tile in MVT protobuf format for a specific zoom level and coordinate. ```APIDOC ## GET /{layer}/{z}/{x}/{y}.pbf ### Description Retrieves a Mapbox Vector Tile (MVT) for the specified layer and tile coordinates. ### Method GET ### Endpoint /{layer}/{z}/{x}/{y}.pbf ### Parameters #### Path Parameters - **layer** (string) - Required - The name of the map layer. - **z** (integer) - Required - Zoom level. - **x** (integer) - Required - X coordinate. - **y** (integer) - Required - Y coordinate. ### Request Example curl http://localhost:3000/basemap/12/655/1583.pbf ### Response #### Success Response (200) - **Content-Type** (application/x-protobuf) - Binary MVT data. #### Success Response (304) - **Status** (304) - Not Modified (returned if ETag matches If-None-Match header). ``` -------------------------------- ### GET /events Source: https://context7.com/muimsd/tilefeed/llms.txt Subscribes to Server-Sent Events (SSE) to receive real-time notifications about tile updates. ```APIDOC ## GET /events ### Description Establishes an SSE connection to stream real-time updates regarding tile generation and modifications. ### Method GET ### Endpoint /events ### Response #### Success Response (200) - **Content-Type** (text/event-stream) - Stream of update events. ### Response Example event: update_complete data: {"event":"update_complete","source":"basemap","tiles_updated":42} ``` -------------------------------- ### GET /events (SSE) Source: https://github.com/muimsd/tilefeed/blob/main/docs/serving.md Subscribes to a stream of Server-Sent Events for live tile updates. ```APIDOC ## GET /events ### Description Provides a live stream of tile update events using Server-Sent Events (SSE) for frontend synchronization. ### Method GET ### Endpoint /events ### Response #### Success Response (200) - **Content-Type** (text/event-stream) - Stream of JSON events. #### Response Example { "event": "update_complete", "source": "basemap", "tiles_updated": 42, "affected_zooms": [10, 11, 12, 13, 14], "max_zoom": 14, "layers_affected": ["buildings", "roads"] } ``` -------------------------------- ### Bash Commands for Docker Compose Management Source: https://context7.com/muimsd/tilefeed/llms.txt Provides essential bash commands for managing the Tilefeed Docker Compose services, including starting, rebuilding, and viewing logs. ```bash # Start services docker compose up -d # Rebuild after code changes docker compose up --build # View logs docker compose logs -f tilefeed ``` -------------------------------- ### Generate and Watch MBTiles Source: https://github.com/muimsd/tilefeed/blob/main/examples/local-parks/README.md Commands to generate initial MBTiles from PostGIS data and start the background watcher process for incremental updates. ```bash cargo run --release -- -c examples/local-parks/config.toml generate cargo run --release -- -c examples/local-parks/config.toml watch cargo run --release -- -c examples/local-parks/config.toml run ``` -------------------------------- ### GET /health Source: https://github.com/muimsd/tilefeed/blob/main/docs/serving.md Performs a health check on the tile server. ```APIDOC ## GET /health ### Description Simple health check endpoint to verify server status. ### Method GET ### Endpoint /health ### Response #### Success Response (200) - **body** (string) - Returns "ok". ``` -------------------------------- ### GET / TileJSON Metadata Source: https://github.com/muimsd/tilefeed/blob/main/docs/serving.md Retrieves the TileJSON 3.0.0 metadata for a specific source. ```APIDOC ## GET /{source}.json ### Description Returns the TileJSON 3.0.0 metadata configuration for the requested source. ### Method GET ### Endpoint /{source}.json ### Parameters #### Path Parameters - **source** (string) - Required - The name of the data source. ### Response #### Success Response (200) - **body** (JSON) - TileJSON 3.0.0 compliant object. #### Response Example { "tilejson": "3.0.0", "tiles": ["http://localhost:3000/source/{z}/{x}/{y}.pbf"], "minzoom": 0, "maxzoom": 14 } ``` -------------------------------- ### GET / Vector Tile Serving Source: https://github.com/muimsd/tilefeed/blob/main/docs/serving.md Retrieves a vector tile in MVT protobuf format for a specific source and coordinate. ```APIDOC ## GET /{source}/{z}/{x}/{y}.pbf ### Description Serves a vector tile (MVT protobuf) for the specified source at the given zoom and coordinate. ### Method GET ### Endpoint /{source}/{z}/{x}/{y}.pbf ### Parameters #### Path Parameters - **source** (string) - Required - The name of the data source. - **z** (integer) - Required - Zoom level. - **x** (integer) - Required - X coordinate. - **y** (integer) - Required - Y coordinate. ### Response #### Success Response (200) - **Content-Type** (application/x-protobuf) - The vector tile data. #### Response Example [Binary MVT Data] ``` -------------------------------- ### Schedule Tile Rebuilds with Cron Source: https://github.com/muimsd/tilefeed/blob/main/examples/ogr-fdw/README.md Example cron job entry for scheduling periodic rebuilding of vector tiles. This is necessary because foreign tables do not support PostgreSQL's LISTEN/NOTIFY mechanism. ```bash # Rebuild tiles every 15 minutes */15 * * * * cd /path/to/tilefeed && ./tilefeed -c examples/ogr-fdw/config.toml generate ``` -------------------------------- ### Define tilefeed Configuration in TOML Source: https://github.com/muimsd/tilefeed/blob/main/docs/configuration.md A complete example of a config.toml file for tilefeed, including database, update, server, publishing, and source layer definitions. ```toml [database] host = "localhost" port = 5432 user = "postgres" password = "postgres" dbname = "geodata" pool_size = 4 [updates] debounce_ms = 200 worker_concurrency = 8 [serve] host = "0.0.0.0" port = 3000 cors_origins = ["http://localhost:8080"] [publish] backend = "none" publish_on_generate = true publish_on_update = true [[sources]] name = "basemap" mbtiles_path = "./basemap.mbtiles" min_zoom = 0 max_zoom = 14 generation_backend = "tippecanoe" [[sources.layers]] name = "buildings" schema = "public" table = "buildings" geometry_column = "geom" id_column = "id" srid = 4326 properties = ["name", "type", "height"] filter = "type != 'demolished'" simplify_tolerance = 0.00001 generate_label_points = true generate_boundary_lines = true ``` -------------------------------- ### GET /{layer}.json Source: https://context7.com/muimsd/tilefeed/llms.txt Retrieves TileJSON metadata for a specific layer, including zoom ranges and available vector layers. ```APIDOC ## GET /{layer}.json ### Description Returns the TileJSON metadata for the requested layer. ### Method GET ### Endpoint /{layer}.json ### Parameters #### Path Parameters - **layer** (string) - Required - The name of the map layer. ### Response #### Success Response (200) - **tilejson** (string) - Version string. - **tiles** (array) - List of tile URL templates. - **vector_layers** (array) - List of available layers and their fields. ### Response Example { "tilejson": "3.0.0", "name": "basemap", "tiles": ["http://localhost:3000/basemap/{z}/{x}/{y}.pbf"], "minzoom": 0, "maxzoom": 14 } ``` -------------------------------- ### Configure tilefeed for Foreign Tables Source: https://github.com/muimsd/tilefeed/blob/main/docs/ogr-fdw.md Example TOML configuration for tilefeed to consume data from a foreign table created via OGR_FDW. ```toml [[sources]] name = "external" mbtiles_path = "./external.mbtiles" min_zoom = 0 max_zoom = 14 [[sources.layers]] name = "parcels" table = "parcels" geometry_column = "geom" id_column = "ogc_fid" srid = 4326 properties = ["owner", "area_sqm", "land_use"] ``` -------------------------------- ### Configure Tippecanoe Source Settings (TOML) Source: https://github.com/muimsd/tilefeed/blob/main/docs/tippecanoe.md Example TOML configuration for a data source, specifying Tippecanoe settings like dropping densest features, disabling tile size limits, and setting buffer zones. This allows fine-grained control over tile generation for specific sources. ```toml [[sources]] name = "basemap" mbtiles_path = "./basemap.mbtiles" min_zoom = 0 max_zoom = 14 [sources.tippecanoe] drop_densest_as_needed = true no_tile_size_limit = true no_feature_limit = true buffer = 5 full_detail = 12 extra_args = ["--cluster-distance=10"] ``` -------------------------------- ### Configure OGR_FDW Foreign Data Servers Source: https://github.com/muimsd/tilefeed/blob/main/docs/ogr-fdw.md SQL commands to install the OGR_FDW extension and create foreign server connections for various data sources including Esri FeatureServer, SQL Server, and GeoPackage. ```sql CREATE EXTENSION ogr_fdw; -- Example 1: Esri FeatureServer CREATE SERVER esri_server FOREIGN DATA WRAPPER ogr_fdw OPTIONS ( datasource 'https://services.arcgis.com/ORG_ID/arcgis/rest/services/MyService/FeatureServer/0', format 'ESRIJSON' ); IMPORT FOREIGN SCHEMA ogr_all FROM SERVER esri_server INTO public; -- Example 2: SQL Server via ODBC CREATE SERVER mssql_server FOREIGN DATA WRAPPER ogr_fdw OPTIONS ( datasource 'MSSQL:server=db.example.com;database=geodata;uid=user;pwd=pass', format 'MSSQLSpatial' ); IMPORT FOREIGN SCHEMA ogr_all FROM SERVER mssql_server INTO public; -- Example 3: GeoPackage file CREATE SERVER gpkg_server FOREIGN DATA WRAPPER ogr_fdw OPTIONS ( datasource '/data/parcels.gpkg', format 'GPKG' ); IMPORT FOREIGN SCHEMA ogr_all FROM SERVER gpkg_server INTO public; ``` -------------------------------- ### Cleanup Project Resources Source: https://github.com/muimsd/tilefeed/blob/main/examples/serve-with-simplification/README.md Removes the temporary database and generated MBTiles files to clean up the environment. ```bash dropdb tilefeed_example rm -f examples/serve-with-simplification/parks.mbtiles ``` -------------------------------- ### Initialize PostGIS database and triggers Source: https://github.com/muimsd/tilefeed/blob/main/README.md SQL commands to prepare a PostGIS database for tilefeed. This includes enabling the PostGIS extension and setting up the necessary notify triggers on source tables. ```bash createdb geodata psql -d geodata -c "CREATE EXTENSION IF NOT EXISTS postgis" psql -d geodata < sql/setup_notify.sql ``` ```sql CREATE TRIGGER tile_update_trigger AFTER INSERT OR UPDATE OR DELETE ON your_table FOR EACH ROW EXECUTE FUNCTION notify_tile_update('your_layer_name'); ``` -------------------------------- ### Storage Publishing Configuration (TOML) Source: https://context7.com/muimsd/tilefeed/llms.txt Configures different backends for publishing generated tiles, including local filesystem, Amazon S3, Mapbox Studio, and custom commands. Each backend has specific configuration options like destination paths, bucket names, API tokens, or command-line arguments. The configuration also allows specifying whether publishing should occur on tile generation or update events. ```toml # Local filesystem copy [publish] backend = "local" destination = "/var/www/tiles/basemap.mbtiles" publish_on_generate = true publish_on_update = true # S3 upload [publish] backend = "s3" destination = "s3://my-tiles-bucket/basemap/tiles.mbtiles" args = ["--endpoint-url", "https://s3.us-east-1.amazonaws.com"] publish_on_generate = true publish_on_update = true # Mapbox Studio upload [publish] backend = "mapbox" mapbox_tileset_id = "username.basemap" mapbox_token = "sk.eyJ1IjoiZXhhbXBsZSJ9.secret_token_here" publish_on_generate = true publish_on_update = false # Full uploads only # Custom command (uses $TILEFEED_MBTILES_PATH env var) [publish] backend = "command" command = "rclone" args = ["copy", "$TILEFEED_MBTILES_PATH", "remote:tiles/"] publish_on_generate = true publish_on_update = true ``` -------------------------------- ### Subscribe to Server-Sent Events (SSE) Source: https://context7.com/muimsd/tilefeed/llms.txt Connect to the real-time event stream to receive updates on tile generation and modification status. ```bash curl -N http://localhost:3000/events ``` -------------------------------- ### Build and Test Commands (Bash) Source: https://github.com/muimsd/tilefeed/blob/main/AGENTS.md Provides essential bash commands for building and testing the project. Includes options for development and release builds, running all or specific tests, and performing fast type-checking. ```bash cargo build # dev build cargo build --release # release build cargo test # run all tests cargo test tiles::tests # run specific test module cargo check # fast type-check without codegen ``` -------------------------------- ### Docker Compose for Tilefeed and PostgreSQL Deployment Source: https://context7.com/muimsd/tilefeed/llms.txt Sets up a Docker Compose environment for Tilefeed, including a PostgreSQL database with PostGIS extension. Configures environment variables and volumes for persistence and configuration. ```yaml version: '3.8' services: db: image: postgis/postgis:16-3.4 environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: geodata volumes: - pgdata:/var/lib/postgresql/data - ./sql/setup_notify.sql:/docker-entrypoint-initdb.d/01-notify.sql ports: - "5432:5432" tilefeed: build: . depends_on: - db environment: TILES_DATABASE__HOST: db TILES_DATABASE__PORT: 5432 TILES_DATABASE__USER: postgres TILES_DATABASE__PASSWORD: postgres TILES_DATABASE__DBNAME: geodata volumes: - ./config.toml:/data/config.toml - ./tiles:/data/tiles ports: - "3000:3000" command: serve volumes: pgdata: ``` -------------------------------- ### Verify Tile Server Functionality Source: https://github.com/muimsd/tilefeed/blob/main/examples/serve-with-simplification/README.md Uses curl to verify the TileJSON endpoint, fetch specific vector tiles, and test ETag caching support. These commands ensure the server is responding correctly to HTTP requests. ```bash # TileJSON curl -s http://localhost:3000/parks.json | jq . # Fetch a tile (SF area at zoom 10) curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/parks/10/163/395.pbf # ETag support (304 on second request) ETAG=$(curl -sI http://localhost:3000/parks/10/163/395.pbf | grep -i etag | tr -d '\r' | awk '{print $2}') curl -s -o /dev/null -w "%{http_code}" -H "If-None-Match: $ETAG" http://localhost:3000/parks/10/163/395.pbf ``` -------------------------------- ### Inspect and Diff MBTiles Source: https://github.com/muimsd/tilefeed/blob/main/examples/serve-with-simplification/README.md Inspects generated MBTiles files and performs a diff after database modifications to verify incremental updates. Useful for debugging geometry changes. ```bash # Inspect the generated MBTiles cargo run -- inspect examples/serve-with-simplification/parks.mbtiles # Make a change, re-generate, and diff cp examples/serve-with-simplification/parks.mbtiles /tmp/before.mbtiles psql -d tilefeed_example -c "INSERT INTO parks (name, type, geom) VALUES ('New Park', 'city_park', ST_GeomFromText('POLYGON((-122.42 37.76, -122.41 37.76, -122.41 37.77, -122.42 37.77, -122.42 37.76))', 4326));" # Wait for incremental update, then: cargo run -- diff /tmp/before.mbtiles examples/serve-with-simplification/parks.mbtiles ``` -------------------------------- ### Discover Layers with ogr_fdw_info Source: https://github.com/muimsd/tilefeed/blob/main/examples/ogr-fdw/README.md Demonstrates how to use the `ogr_fdw_info` command-line tool to inspect available layers and columns from different OGR-supported data sources. ```bash # Esri FeatureServer ogr_fdw_info -s 'https://services.arcgis.com/YOUR_ORG/arcgis/rest/services/Buildings/FeatureServer/0' # SQL Server ogr_fdw_info -s 'MSSQL:server=db.example.com;database=geodata;uid=user;pwd=pass' # GeoPackage ogr_fdw_info -s '/data/parcels.gpkg' ``` -------------------------------- ### Execute tilefeed CLI commands Source: https://github.com/muimsd/tilefeed/blob/main/README.md Common command-line operations for generating, watching, serving, and inspecting MBTiles files. These commands allow for full rebuilds, incremental updates, and configuration management. ```bash tilefeed generate tilefeed watch tilefeed run tilefeed serve tilefeed inspect tilefeed validate tilefeed diff tilefeed -c other.toml serve cargo run --release -- serve ``` -------------------------------- ### tilefeed Webhook Signature Header Source: https://github.com/muimsd/tilefeed/blob/main/docs/serving.md Example of the `X-Tilefeed-Signature` header generated by tilefeed when webhooks are configured with a secret. This header contains a hex-encoded HMAC-SHA256 hash of the request body, used for server-side verification. ```text X-Tilefeed-Signature: sha256= ``` -------------------------------- ### Curl Commands for Tilefeed API Interaction Source: https://context7.com/muimsd/tilefeed/llms.txt Demonstrates how to fetch map tiles and TileJSON metadata from a running Tilefeed server using curl. Assumes the server is running on localhost:3000. ```bash # Tiles served at separate endpoints curl http://localhost:3000/basemap/12/655/1583.pbf curl http://localhost:3000/poi/14/2620/6332.pbf # TileJSON for each source curl http://localhost:3000/basemap.json curl http://localhost:3000/poi.json ``` -------------------------------- ### Cleanup Database and Files Source: https://github.com/muimsd/tilefeed/blob/main/examples/ogr-fdw/README.md Commands to remove the created PostgreSQL database and any generated MBTiles files or output directories. ```bash dropdb tilefeed_ogr_example rm -f examples/ogr-fdw/buildings.mbtiles rm -rf examples/ogr-fdw/output/ ``` -------------------------------- ### Configure tilefeed settings Source: https://github.com/muimsd/tilefeed/blob/main/README.md TOML configuration structure for defining database connections, server settings, and source layer definitions. This file controls how data is extracted from PostGIS and converted into MBTiles. ```toml [database] host = "localhost" port = 5432 user = "postgres" password = "postgres" dbname = "geodata" [serve] host = "0.0.0.0" port = 3000 [[sources]] name = "basemap" mbtiles_path = "./basemap.mbtiles" min_zoom = 0 max_zoom = 14 [[sources.layers]] name = "buildings" table = "buildings" geometry_column = "geom" id_column = "id" srid = 4326 properties = ["name", "type", "height"] simplify_tolerance = 0.00001 generate_label_points = true [[sources.layers.property_rules]] below_zoom = 8 exclude = ["height"] ``` -------------------------------- ### Docker Compose Commands (Bash) Source: https://github.com/muimsd/tilefeed/blob/main/AGENTS.md Demonstrates Docker Compose commands for setting up and managing the PostGIS and tilefeed services. Includes commands to bring services up and rebuild images after code changes. ```bash docker compose up # PostGIS + tilefeed serve docker compose up --build # rebuild after code changes ``` -------------------------------- ### Verify and Cleanup Project Artifacts Source: https://github.com/muimsd/tilefeed/blob/main/examples/local-parks/README.md Commands to verify the generated MBTiles file contents and remove temporary database and output files. ```bash sqlite3 examples/local-parks/parks.mbtiles "SELECT COUNT(*) FROM tiles;" dropdb tilefeed_example rm -f examples/local-parks/parks.mbtiles rm -rf examples/local-parks/output/ ``` -------------------------------- ### Incremental Update Configuration (TOML) Source: https://context7.com/muimsd/tilefeed/llms.txt Configures parameters for incremental tile updates, focusing on debouncing and worker concurrency. Debouncing helps batch notifications within a specified time window to avoid excessive updates, while worker concurrency controls the maximum number of simultaneous tile regeneration processes. These settings optimize performance and resource usage during updates. ```toml [updates] debounce_ms = 200 # Batch notifications within 200ms window worker_concurrency = 8 # Max concurrent tile regeneration workers ``` -------------------------------- ### Configure tilefeed via Environment Variables Source: https://github.com/muimsd/tilefeed/blob/main/docs/configuration.md Demonstrates how to override configuration settings using shell environment variables. Use the TILES_ prefix and double underscores (__) to represent nested sections. ```bash export TILES_DATABASE__HOST=db.example.com export TILES_DATABASE__PORT=5432 export TILES_DATABASE__USER=myuser export TILES_DATABASE__PASSWORD=secret export TILES_DATABASE__DBNAME=geodata ``` -------------------------------- ### TOML Configuration for Tippecanoe Advanced Settings Source: https://context7.com/muimsd/tilefeed/llms.txt Details advanced configuration options for the Tippecanoe generation backend in Tilefeed. Covers feature dropping, simplification, tile limits, and geometry tuning. ```toml [sources.tippecanoe] # Feature dropping strategies drop_densest_as_needed = true # Drop features in dense areas drop_fraction_as_needed = false # Drop random fraction of features drop_smallest_as_needed = false # Drop smallest features first coalesce_densest_as_needed = false # Merge nearby features in dense areas extend_zooms_if_still_dropping = true # Drop rate control drop_rate = 2.5 # Rate features drop at lower zooms base_zoom = 14 # Base zoom for drop rate calculation # Detail and simplification simplification = 10.0 # Simplification in tile units detect_shared_borders = true # Simplify shared polygon borders identically no_tiny_polygon_reduction = false # Allow tiny polygon collapse # Tile limits no_feature_limit = true # Remove 200,000 feature limit no_tile_size_limit = true # Remove 500KB tile size limit no_tile_compression = false # Keep gzip compression # Geometry tuning buffer = 5 # Pixel buffer around tile edges full_detail = 12 # Detail at max zoom (4096 units) low_detail = 12 # Detail at lower zooms minimum_detail = 7 # Min detail before feature drop # Escape hatch for any Tippecanoe option extra_args = [ "--cluster-distance=10", "--accumulate-attribute=count:sum" ] ``` -------------------------------- ### Webhook Notification Configuration (TOML) Source: https://context7.com/muimsd/tilefeed/llms.txt Configures HTTP POST webhooks for receiving notifications about tile generation and updates. It supports HMAC signing for security, cooldown throttling to aggregate events, and configurable retry mechanisms. The configuration specifies the URLs to send notifications to and the secret key for signing. ```toml [webhook] urls = ["https://example.com/hooks/tilefeed", "https://backup.example.com/hooks"] secret = "my-signing-secret" # HMAC-SHA256 signing (optional) cooldown_secs = 300 # Aggregate events for 5 minutes timeout_ms = 5000 # Per-request timeout retry_count = 2 # Retries with exponential backoff on_generate = true # Notify on full generation on_update = true # Notify on incremental updates ``` -------------------------------- ### Running tilefeed Commands (Bash) Source: https://github.com/muimsd/tilefeed/blob/main/AGENTS.md Lists various bash commands to run the tilefeed application with different functionalities. These include full tile generation, incremental updates, serving tiles over HTTP, inspecting MBTiles files, and comparing them. ```bash cargo run -- generate # full tile generation from PostGIS via Tippecanoe cargo run -- watch # watch LISTEN/NOTIFY and apply incremental updates cargo run -- run # generate then watch cargo run -- serve # generate, watch, and serve tiles over HTTP cargo run -- inspect out.mbtiles # dump MBTiles metadata and stats cargo run -- validate # check config against database cargo run -- diff a.mbtiles b.mbtiles # compare two MBTiles files cargo run -- -c other.toml watch # use alternate config file ``` -------------------------------- ### Configure Native Generation Backend Source: https://github.com/muimsd/tilefeed/blob/main/docs/configuration.md Specify the 'native' generation backend for creating tiles directly from PostGIS queries using tilefeed's built-in Rust MVT encoder. This method has no external dependencies and supports geometry simplification and derived layers, making it suitable for development or restricted environments. ```toml [[sources]] name = "parks" mbtiles_path = "./parks.mbtiles" min_zoom = 0 max_zoom = 8 generation_backend = "native" ``` -------------------------------- ### MapLibre GL JS Integration for Live Tile Refresh (JavaScript) Source: https://context7.com/muimsd/tilefeed/llms.txt Integrates MapLibre GL JS to display vector tiles and uses Server-Sent Events (SSE) to listen for tile update notifications. It forces a re-fetch of tiles when an update event is received, ensuring the map displays the latest data. The code includes error handling for the SSE connection and a reconnection mechanism. ```javascript const TILE_SERVER = 'http://localhost:3000'; const SOURCE_NAME = 'basemap'; const map = new maplibregl.Map({ container: 'map', style: { version: 8, sources: { [SOURCE_NAME]: { type: 'vector', tiles: [`${TILE_SERVER}/${SOURCE_NAME}/{z}/{x}/{y}.pbf`], minzoom: 0, maxzoom: 14, }, }, layers: [ { id: 'buildings-fill', type: 'fill', source: SOURCE_NAME, 'source-layer': 'buildings', paint: { 'fill-color': '#2ecc71', 'fill-opacity': 0.5 }, }, ], }, center: [-122.4194, 37.7749], zoom: 12, }); // SSE for live tile refresh const es = new EventSource(`${TILE_SERVER}/events`); es.addEventListener('update_complete', (e) => { const data = JSON.parse(e.data); const source = map.getSource(data.source); if (source) { // Force re-fetch with cache-busting parameter source.setTiles([ `${TILE_SERVER}/${data.source}/{z}/{x}/{y}.pbf?_t=${Date.now()}` ]); } }); es.addEventListener('generate_complete', (e) => { const data = JSON.parse(e.data); const source = map.getSource(data.source); if (source) { source.setTiles([ `${TILE_SERVER}/${data.source}/{z}/{x}/{y}.pbf?_t=${Date.now()}` ]); } }); es.onerror = () => { es.close(); setTimeout(() => connectSSE(), 3000); // Reconnect after 3s }; ``` -------------------------------- ### Tippecanoe Advanced Settings Source: https://context7.com/muimsd/tilefeed/llms.txt Detailed configuration options for fine-tuning Tippecanoe tile generation within Tilefeed. ```APIDOC ## Tippecanoe Settings ### Description Fine-tune Tippecanoe tile generation with advanced options for feature dropping, simplification, and tile limits. ### Configuration (`config.toml`) ```toml [sources.tippecanoe] # Feature dropping strategies drop_densest_as_needed = true # Drop features in dense areas drop_fraction_as_needed = false # Drop random fraction of features drop_smallest_as_needed = false # Drop smallest features first coalesce_densest_as_needed = false # Merge nearby features in dense areas extend_zooms_if_still_dropping = true # Drop rate control drop_rate = 2.5 # Rate features drop at lower zooms base_zoom = 14 # Base zoom for drop rate calculation # Detail and simplification simplification = 10.0 # Simplification in tile units detect_shared_borders = true # Simplify shared polygon borders identically no_tiny_polygon_reduction = false # Allow tiny polygon collapse # Tile limits no_feature_limit = true # Remove 200,000 feature limit no_tile_size_limit = true # Remove 500KB tile size limit no_tile_compression = false # Keep gzip compression # Geometry tuning buffer = 5 # Pixel buffer around tile edges full_detail = 12 # Detail at max zoom (4096 units) low_detail = 12 # Detail at lower zooms minimum_detail = 7 # Min detail before feature drop # Escape hatch for any Tippecanoe option extra_args = [ "--cluster-distance=10", "--accumulate-attribute=count:sum" ] ``` ``` -------------------------------- ### TOML Configuration for Tilefeed Sources Source: https://context7.com/muimsd/tilefeed/llms.txt Defines map tile sources with different backends (Tippecanoe, native) and zoom level configurations. Specifies layer details, geometry columns, and properties. ```toml [[sources]] name = "basemap" mbtiles_path = "./basemap.mbtiles" min_zoom = 0 max_zoom = 14 generation_backend = "tippecanoe" [sources.tippecanoe] drop_densest_as_needed = true no_tile_size_limit = true [[sources.layers]] name = "buildings" table = "buildings" geometry_column = "geom" id_column = "id" srid = 4326 properties = ["name", "type", "height"] simplify_tolerance = 0.00001 generate_label_points = true [[sources.layers.property_rules]] below_zoom = 10 exclude = ["height"] [[sources.layers]] name = "roads" table = "roads" geometry_column = "geom" id_column = "id" srid = 4326 properties = ["name", "class", "surface"] [[sources]] name = "poi" mbtiles_path = "./poi.mbtiles" min_zoom = 10 max_zoom = 16 generation_backend = "native" [[sources.layers]] name = "pois" table = "points_of_interest" geometry_column = "geom" id_column = "id" srid = 4326 properties = ["name", "category", "rating"] ``` -------------------------------- ### Materialize Foreign Data for Performance Source: https://github.com/muimsd/tilefeed/blob/main/docs/ogr-fdw.md SQL commands to create a materialized view from a foreign table to improve query performance for large remote datasets. ```sql CREATE MATERIALIZED VIEW parcels_local AS SELECT * FROM parcels; REFRESH MATERIALIZED VIEW CONCURRENTLY parcels_local; ``` -------------------------------- ### Initialize MapLibre Map and SSE Connection Source: https://github.com/muimsd/tilefeed/blob/main/examples/webhook-sse/map.html Configures a MapLibre GL map instance with a vector tile source and initializes an EventSource listener to handle live tile refresh events from the server. ```javascript const TILE_SERVER = 'http://localhost:3000'; const SOURCE_NAME = 'parks'; const map = new maplibregl.Map({ container: 'map', style: { version: 8, sources: { [SOURCE_NAME]: { type: 'vector', tiles: [`${TILE_SERVER}/${SOURCE_NAME}/{z}/{x}/{y}.pbf`], minzoom: 0, maxzoom: 14 } }, layers: [ { id: `${SOURCE_NAME}-fill`, type: 'fill', source: SOURCE_NAME, 'source-layer': SOURCE_NAME, paint: { 'fill-color': '#2ecc71', 'fill-opacity': 0.5 } }, { id: `${SOURCE_NAME}-outline`, type: 'line', source: SOURCE_NAME, 'source-layer': SOURCE_NAME, paint: { 'line-color': '#27ae60', 'line-width': 1.5 } } ] }, center: [0, 30], zoom: 3 }); function refreshSource(sourceName) { const source = map.getSource(sourceName); if (!source) return; const ts = Date.now(); source.setTiles([`${TILE_SERVER}/${sourceName}/{z}/{x}/{y}.pbf?_t=${ts}`]); } function connectSSE() { const es = new EventSource(`${TILE_SERVER}/events`); es.addEventListener('update_complete', (e) => { const data = JSON.parse(e.data); refreshSource(data.source); }); es.onerror = () => { es.close(); setTimeout(connectSSE, 3000); }; } map.on('load', connectSSE); ``` -------------------------------- ### Discover Layers with ogr_fdw_info Source: https://github.com/muimsd/tilefeed/blob/main/docs/ogr-fdw.md Command-line utility to inspect remote data sources and identify available layers and columns before creating foreign tables. ```bash ogr_fdw_info -s 'https://services.arcgis.com/.../FeatureServer/0' ``` -------------------------------- ### Configure Webhook Notifications Source: https://github.com/muimsd/tilefeed/blob/main/docs/configuration.md Set up webhook endpoints to receive HTTP POST notifications for tile generation events. Supports HMAC-SHA256 signing, cooldown periods for aggregation, and retry mechanisms for failed requests. Can trigger notifications on full generation completion or incremental updates. ```toml [webhook] urls = ["https://example.com/hooks/tilefeed"] secret = "my-signing-secret" cooldown_secs = 300 # aggregate events for 5 minutes on_generate = true on_update = true ``` -------------------------------- ### Materialize Foreign Table for Performance Source: https://github.com/muimsd/tilefeed/blob/main/examples/ogr-fdw/README.md SQL commands to create a local materialized view from a foreign table for improved performance with large datasets. Includes creating an index and refreshing the materialized view. ```sql -- Create a local materialized view CREATE MATERIALIZED VIEW buildings_local AS SELECT * FROM buildings; CREATE INDEX idx_buildings_local_geom ON buildings_local USING GIST (geom); -- Refresh periodically (or via pg_cron) REFRESH MATERIALIZED VIEW CONCURRENTLY buildings_local; ``` -------------------------------- ### Configure PostgreSQL LISTEN/NOTIFY Triggers Source: https://context7.com/muimsd/tilefeed/llms.txt This SQL script creates a trigger function that broadcasts database changes via pg_notify and attaches it to specific tables. It captures feature modifications and spatial bounds to facilitate incremental tile updates. ```sql CREATE OR REPLACE FUNCTION notify_tile_update() RETURNS trigger AS $$ DECLARE payload TEXT; layer_name TEXT; feature_id BIGINT; BEGIN layer_name := TG_ARGV[0]; IF TG_OP = 'DELETE' THEN feature_id := OLD.id; payload := json_build_object( 'layer', layer_name, 'id', feature_id, 'op', 'delete', 'old_bounds', json_build_object( 'min_lon', ST_XMin(ST_Envelope(ST_Transform(OLD.geom, 4326))), 'min_lat', ST_YMin(ST_Envelope(ST_Transform(OLD.geom, 4326))), 'max_lon', ST_XMax(ST_Envelope(ST_Transform(OLD.geom, 4326))), 'max_lat', ST_YMax(ST_Envelope(ST_Transform(OLD.geom, 4326))) ) )::TEXT; ELSIF TG_OP = 'UPDATE' THEN feature_id := NEW.id; payload := json_build_object( 'layer', layer_name, 'id', feature_id, 'op', 'update', 'old_bounds', json_build_object( 'min_lon', ST_XMin(ST_Envelope(ST_Transform(OLD.geom, 4326))), 'min_lat', ST_YMin(ST_Envelope(ST_Transform(OLD.geom, 4326))), 'max_lon', ST_XMax(ST_Envelope(ST_Transform(OLD.geom, 4326))), 'max_lat', ST_YMax(ST_Envelope(ST_Transform(OLD.geom, 4326))) ) )::TEXT; ELSE feature_id := NEW.id; payload := json_build_object( 'layer', layer_name, 'id', feature_id, 'op', 'insert' )::TEXT; END IF; PERFORM pg_notify('tile_update', payload); RETURN NEW; END; $$ LANGUAGE plpgsql; CREATE TRIGGER tile_update_trigger AFTER INSERT OR UPDATE OR DELETE ON buildings FOR EACH ROW EXECUTE FUNCTION notify_tile_update('buildings'); CREATE TRIGGER tile_update_trigger AFTER INSERT OR UPDATE OR DELETE ON roads FOR EACH ROW EXECUTE FUNCTION notify_tile_update('roads'); ``` -------------------------------- ### MapLibre SSE Tile Update Handling Source: https://github.com/muimsd/tilefeed/blob/main/docs/serving.md JavaScript code snippet demonstrating how to use the EventSource API to listen for 'update_complete' events from the tilefeed server. Upon receiving an update, it refreshes the tiles for the affected source in a MapLibre map. ```javascript const es = new EventSource('http://localhost:3000/events'); es.addEventListener('update_complete', (e) => { const data = JSON.parse(e.data); const source = map.getSource(data.source); if (source) { source.setTiles([`http://localhost:3000/${data.source}/{z}/{x}/{y}.pbf?_t=${Date.now()}`]); } }); ``` -------------------------------- ### Tile Serving Endpoints Source: https://context7.com/muimsd/tilefeed/llms.txt Access map tiles directly from specified sources or retrieve TileJSON metadata for each source. ```APIDOC ## GET /basemap/{z}/{x}/{y}.pbf ### Description Retrieves map tiles for the 'basemap' source at a specific zoom level (z), x-coordinate, and y-coordinate. ### Method GET ### Endpoint `/basemap/{z}/{x}/{y}.pbf` ### Parameters #### Path Parameters - **z** (integer) - Required - The zoom level of the tile. - **x** (integer) - Required - The x-coordinate of the tile. - **y** (integer) - Required - The y-coordinate of the tile. ### Response #### Success Response (200) - **binary** (bytes) - The requested map tile in PBF format. ## GET /poi/{z}/{x}/{y}.pbf ### Description Retrieves map tiles for the 'poi' source at a specific zoom level (z), x-coordinate, and y-coordinate. ### Method GET ### Endpoint `/poi/{z}/{x}/{y}.pbf` ### Parameters #### Path Parameters - **z** (integer) - Required - The zoom level of the tile. - **x** (integer) - Required - The x-coordinate of the tile. - **y** (integer) - Required - The y-coordinate of the tile. ### Response #### Success Response (200) - **binary** (bytes) - The requested map tile in PBF format. ## GET /basemap.json ### Description Retrieves the TileJSON metadata for the 'basemap' source. ### Method GET ### Endpoint `/basemap.json` ### Response #### Success Response (200) - **TileJSON Object** (object) - Metadata describing the 'basemap' tile source. ## GET /poi.json ### Description Retrieves the TileJSON metadata for the 'poi' source. ### Method GET ### Endpoint `/poi.json` ### Response #### Success Response (200) - **TileJSON Object** (object) - Metadata describing the 'poi' tile source. ``` -------------------------------- ### tilefeed Server Configuration Source: https://github.com/muimsd/tilefeed/blob/main/docs/serving.md Configuration options for the built-in tilefeed server, including the host address, port number, and allowed CORS origins. These settings control network accessibility and cross-origin resource sharing. ```toml [serve] host = "0.0.0.0" # bind address (default: 127.0.0.1) port = 3000 # port (default: 3000) cors_origins = ["http://localhost:8080"] # omit for wildcard ```