Leaflet chooses its tile level with Math.round(mapZoom), so the default fit view at zoom 2.25 took level 2 and stretched it 1.19x. With a devicePixelRatio of 1.5 that compounded to a 1.78x upscale of every source pixel. DENSITY_BOOST halves a tile's CSS size and adds a matching zoomOffset, so Leaflet downscales a denser level instead of upscaling a coarser one. The per-cell tile offset is now derived from baseTileSize rather than assuming 2**z, so the world-grid translation stays exact under the boost. Source pixels per device pixel at DPR 1.5, higher being sharper: view zoom 0-4 0.56 -> 1.33 view zoom 5 0.67 (unchanged; this is the 1:1 source level) Costs ~4x the tiles in view, ~17 KB each, cached for a week. z5 is a genuine ceiling: the embedded terrain smart object is a PSB of exactly 7832x3720 placed 1:1, so no further source detail exists. Verified zoom 0-7: zero broken tiles. Co-Authored-By: Claude Opus 5 <[email protected]>
TarkovMap
Self-hosted, mobile-friendly Escape from Tarkov map viewer. Layered PSDs go in, a Leaflet tile pyramid comes out, and every map — related or not — sits side by side on one shared canvas you can pan across.
Only the base map art is extracted. Markers, spawns, legends, captions and titles are dropped during the render.
Quickstart
python -m pip install -r tools/requirements.txt
python tools/build.py
pwsh server/get-caddy.ps1
pwsh server/run.ps1
Open the printed URL. The LAN address works from a phone on the same network.
run.ps1 uses Caddy when server/caddy.exe is present and falls back to
serve.py otherwise, so the first step is optional — see Serving.
Source PSDs are not in the repo (see .gitignore) — get them from the shared
drive and put them under sources/.
Adding a map
See docs/adding-a-map.md. Short version: run
tools/psd_tree.py to find the group holding the art, add an entry to
maps.json, run tools/build.py. No application code changes.
Layout
maps.json the only thing you edit to add or change a map
tools/
psd_tree.py inspect a PSD's layer tree
export_base.py PSD -> build/<id>/base.png (base group only)
tile.py base.png -> web/tiles/<id>/{z}/{x}/{y}.webp
build.py orchestrator; also writes web/data/world.json
preview.py stitch built tiles into one overview image
common.py config loading + the world-grid maths
server/serve.py dependency-free static server with sane cache headers
web/ the site: index.html, app.js, style.css, vendored Leaflet
sources/ gitignored — source PSDs
build/ gitignored — intermediate PNGs
web/tiles/ gitignored — generated tiles
How the shared canvas works
Maps are placed on a grid of 8192 × 8192 px cells (tileSize · 2^maxZoom). At
that cell size, a map's tile indices shift into world coordinates by exactly
cell · 2^z at every zoom — always an integer. So each map keeps its own
locally numbered pyramid, the browser translates on the fly, and adding a map
never re-tiles the others.
A map must fit in one cell. Raising maxZoom in maps.json doubles the cell.
No black gaps
Each map is drawn twice. Underneath sits a backdrop layer pinned to
underlayZoom (default 2) — Leaflet serves that one level at every view zoom,
scaled to fit. The whole world at z2 is 17 tiles / 134 KB, so it lands almost
immediately and then stays resident, and detail tiles draw over it.
Any gap while detail tiles load shows blurry map instead of the page
background. Raising underlayZoom sharpens the backdrop but costs a lot more
up front (z3 is 49 tiles / 471 KB) — z2 is the sweet spot.
Current maps
| Map | Source size | Tiled | Tiles |
|---|---|---|---|
| Customs | 7832 × 5016 | 7832 × 3015 | 503 (8.4 MB) |
| Customs — Dorms | 4301 × 4904 | 4301 × 4904 | 469 (1.4 MB) |
Tile resolution and sharpness
maxZoom is derived from the largest map: ceil(log2(7832 / 256)) = 5. At z5
one source pixel is one CSS pixel, and z5 is the full PSD — verified by
reading the embedded terrain smart object, which is exactly 7832 × 3720 placed
1:1. There is no hidden detail to recover, so z5 is a hard ceiling.
Sharpness is therefore about level selection, not pyramid depth. Leaflet
picks its level with Math.round(mapZoom), so at zoom 2.25 it takes level 2 and
stretches it 1.19×. On a 150 %-scaled Windows display (devicePixelRatio 1.5)
that compounds to a 1.78× upscale — visibly soft.
DENSITY_BOOST in app.js fixes it: halve the CSS size of a tile and request
one level deeper, so we downscale a denser level instead of upscaling a coarser
one. Measured at devicePixelRatio 1.5, in source pixels delivered per device
pixel (higher is sharper, 1.0 is pixel-perfect):
| View zoom | Before | After |
|---|---|---|
| 0–4 | 0.56 | 1.33 |
| 5 (1:1 source) | 0.67 | 0.67 |
It costs ~4× the tiles in view (99 at the busiest level on a 1315 px viewport, ~17 KB each). Cached for a week and served by Caddy, that is a fair trade.
At z5 and beyond you are past the source resolution and the browser upscales —
unavoidable, and ZOOM_HEADROOM deliberately allows two levels of it.
Serving
Two options, both driven by server/run.ps1:
serve.py |
Caddy | |
|---|---|---|
| Dependencies | none (stdlib) | one 47 MB binary |
| conc 8 | 2,622 req/s · p95 4.0 ms | 6,987 req/s · p95 1.9 ms |
| conc 32 | 462 req/s · max 1,013 ms | 5,877 req/s · max 21 ms |
| ETags / compression | no | yes (zstd, gzip) |
Measured on loopback, 480 tile requests over reused connections.
The number that matters is the second row. serve.py is thread-per-connection
behind the GIL, so under load it doesn't just slow down — throughput falls and
tail latency goes past a second. Caddy stays flat. Use Caddy for anything real;
serve.py exists so a fresh clone works with nothing installed.
serve.py was also defaulting to HTTP/1.0, which closes the socket after
every response — one TCP handshake per tile, ~30 per map view. It now sets
HTTP/1.1, which is most of its improvement above.
Neither runs HTTP/2: browsers only negotiate h2 over TLS, and putting a trusted cert on every phone isn't worth it on a LAN. The Caddy win is Go's I/O, not h2.
To reach it from a phone, allow the port once (elevated):
netsh advfirewall firewall add rule name="TarkovMap 8080" dir=in action=allow protocol=TCP localport=8080
Licence
Map art is by re3mr.com under CC BY-NC-SA 4.0. Attribution is shown in the viewer and must stay there. Use is non-commercial, and derivative map images inherit the same licence. Local and LAN hosting is fine; get sign-off before hosting publicly.