Disclosure: AI coding assistants were used to help draft code, iterate on image-processing scripts, and edit this write-up. All architecture decisions, graph metrics, overpass audits, and production benchmarks are from my own live deployment.

When building an interactive game map for a brand-new open world (GTA6 GPS, an interactive map of Leonida I maintain at gta6gps.com), players quickly ask for route planning between collectibles. Straight-line dashed segments are easy—real road and water routing is much harder when you don't have OpenStreetMap or a licensed vector street dataset.

All we had was a CC BY 4.0 raster base map (zoom-5 and zoom-6 tiles). Here is how we turned flat PNG/WebP map tiles into a fast server-side Drive / Walk / Boat routing engine in ~16 ms per request.

1. Extracting a road graph from raster colors

Game base maps are cleaner than satellite imagery: highways, city streets, park paths, and water each use consistent color palettes.

Our offline Python pipeline takes zoom-6 raster tiles (plus a zoom-5 street mask for thin pale roads and lavender park paths) and runs:

  1. Color-mask segmentation per road class (highway, street, park path).

  2. Morphological closing to bridge lane dividers and minor tile artifacts.

  3. Skeletonization to collapse multi-pixel road bands into 1-pixel centerlines.

  4. Graph extraction & simplification into nodes and weighted polyline edges.

The first prototype (v1) produced 7,823 nodes and 9,659 edges (~738k map units of road), with 80% of total road length in one connected component.

The biggest immediate failure mode was broken bridges and slight lane gaps leaving islands disconnected. In v2, we added a dead-end bridging pass that connects collinear dead ends across short gaps (joining 443 bridges/gaps), expanding total road length to 1,417k units and lifting the largest connected component from 80% to 94%. Across 200 seeded pin pairs, the median road-to-straight-line ratio improved from 1.45 to 1.32.

2. The flat-image trap: overpasses look like 4-way junctions

Skeletonizing a 2D raster creates a classic routing bug: every highway overpass looks like a 4-way intersection. A* happily tells players to make a 90-degree turn off an elevated freeway onto the surface street below.

To fix this in v3 without hand-drawing the entire map:

  • We classified every edge by its base-map color: 3,462 highway, 15,603 street, and 4,418 park-path edges.

  • We detected candidate highway-over-street crossings, rendered zoom-6 crops around each one, audited them by eye, and split 31 true overpasses into non-intersecting two-level edges.

That single pass eliminated the most jarring impossible turns.

3. Adding Boat mode with a 40.5 KB water graph

For coastal and island runs, Drive and Walk aren't enough. We applied a similar raster-extraction pipeline to water tiles to build a separate 40.5 KB server-only water graph (water-v1.json) with connected-water snapping, so Boat routes stay on navigable water instead of cutting across sandbars or piers.

Combined with edge-class speed weights (highways faster for Drive, park paths and shortcuts enabled for Walk), the same A* solver supports Drive, Walk, and Boat modes with per-mode ETA and turn-by-turn directions (angle-based bear/turn/sharp left-right + U-turn + region transitions, even without street names).

4. Moving routing off the client

Shipping the v2/v3 graph to the browser meant downloading 1.14 MB JSON (439 KB gzipped) on every visit—way too heavy for mobile players who just want to look up one location.

Moving A* to a lightweight server endpoint (GET /api/route?g=7&stops=...):

  • A typical 3-stop route response is ~0.5 KB instead of 439 KB.

  • Cold graph load per serverless instance takes ~240 ms; warm route queries take ~16 ms.

  • Responses are edge-cached for a week keyed by quantized stops + graph version, and the client caches per-leg segments so dragging one waypoint only recomputes the affected legs.

  • Multi-stop "Nearest next" ordering uses nearest-neighbor + 2-opt refinement.

Takeaways

  • You don't need vector tiles to ship real routing for a game map—consistent raster color classes + skeletonization + targeted overpass splitting gets you 94%+ connectivity quickly.

  • Keep the graph server-side and cache per leg. Players feel the difference immediately on mobile.

  • Measure with seeded test pairs (road/straight ratio, % of legs routed on road vs straight-line fallback) before every graph rebuild so you catch regressions automatically.

If you want to test the Drive/Walk/Boat routing or drag-to-edit waypoints yourself, it's live on GTA6 GPS. Happy to answer questions about the skeletonization or overpass-splitting scripts in the comments.