ADR-004: OSM Tile Integration for Region Textures
Metadata:
- ID: ADR-004
- Status: Accepted
- Date: 2025-03-18
- Tags: [rendering, tiles, osm]
- Decision Type: technology_choice
- Related: [ADR-001, ADR-003]
- Supersedes: []
- Superseded By: []
Context
Problem: Regions need textured ground planes. Use real-world map imagery for geographic context.
Requirements:
- Fetch map tiles by (x, y, z) coordinates
- Load asynchronously
- Cache for performance
- Integrate with Bevy's asset system
Decision
Use OpenStreetMap tiles fetched over HTTP (ureq) on a background worker thread, with a TileCache resource.
Approach:
TileKey(x, y, z)for lookup; regions anchored atREGION_ZOOM_LEVEL = 17(cartopolis_core/world.rs)TileCacheholds image handles + in-flight state; fetches run on a worker thread and post results back over an mpsc channel (non-blocking)RegionTilecomponent on region entities;load_region_tilesdrains results,update_region_materials(inrendering.rs) applies them- On-disk tile cache (
tile_cache_path) and a self-hosted OSM template viaOsmTileUrlTemplate;map_stream.rsstreams tiles for the globe/map view
Rationale
Primary Reasoning:
- OSM: free, legal tiles
- ureq: simple blocking HTTP on a worker thread — no async runtime pulled in for this
- TileCache: dedupe fetches (memory + on-disk)
- LOD:
RegionTile::lod_levelreserved for future LOD (currently unused)
Alternatives Considered:
| Alternative | Pros | Cons | Rejected Because |
|---|---|---|---|
| reqwest | Async | Extra deps | ureq is simpler |
| Pre-bake tiles | Faster load | Large assets | Dynamic tiles preferred |
| Mapbox | Better quality | Cost, API key | OSM is free |
Consequences
Positive:
- Realistic ground textures
- Caching reduces network traffic
- Standard tile format (z/x/y)
Negative:
- Network dependency (mitigation: memory + on-disk cache)
- OSM ToU: respect usage policy (mitigation: reasonable rate, attribution, self-hosted template option)