Make a fresh clone servable after `git lfs pull` alone, and rebuildable with `tools/build.py` without re-rendering unchanged PSDs: - Track build/ (rendered base PNGs, previews, world composites), web/tiles/, web/tiles-trimmed/, web/data/world.json and web/data/markers/. Large PNGs and the tile pyramids go through Git LFS (.gitattributes); JSON stays plain. - build.py: decide PSD re-export from build/<id>/base.stamp.json (PSD size, mtime, SHA-256 recorded at export time) instead of file mtimes, which are meaningless after an LFS checkout. Same size + new mtime hashes once and refreshes the stamp; --stamp-only writes stamps for existing base.pngs. - Ignore .DS_Store and .env files; track sources/**/*.jpg through LFS. Viewer: - Right-click (long-press) the map for a category menu that drops a draft marker under the pointer and enters marker edit mode for that map. - Marker editing moves out of the side panel into a box anchored next to the marker: Enter or a left click anywhere else saves, Esc cancels, Delete inside the box; drags save position plus the box contents. - Maps panel expands on hover, header click pins/unpins (status shown in the header), unpinned collapses 2 s after the pointer leaves; Overview is the first list entry instead of a separate button. Only the panel scrolls; the page never grows past the viewport. Hover tooltips render above markers. Also includes the pending source additions (overall square base, skirt textures, AI regeneration tooling and notes), service worker, Caddyfile and map config updates. Co-Authored-By: Claude Fable 5 <[email protected]>
863 lines
38 KiB
Markdown
863 lines
38 KiB
Markdown
# TarkovMap — Technical Documentation
|
||
|
||
Complete reference for how this project works. For a five-line quickstart see
|
||
[README.md](README.md); for the step-by-step runbook to add a map see
|
||
[docs/adding-a-map.md](docs/adding-a-map.md); for project status and open work
|
||
see [PLAN.md](PLAN.md).
|
||
|
||
**Contents**
|
||
|
||
1. [What this is](#1-what-this-is)
|
||
2. [How it fits together](#2-how-it-fits-together)
|
||
3. [Coordinate systems](#3-coordinate-systems)
|
||
4. [The tile grid, and why maps are padded](#4-the-tile-grid-and-why-maps-are-padded)
|
||
5. [The build pipeline](#5-the-build-pipeline)
|
||
6. [Configuration reference — `maps.json`](#6-configuration-reference--mapsjson)
|
||
7. [Data contract — `world.json`](#7-data-contract--worldjson)
|
||
8. [The viewer](#8-the-viewer)
|
||
9. [Serving](#9-serving)
|
||
10. [Source-art findings](#10-source-art-findings)
|
||
11. [Traps and workarounds](#11-traps-and-workarounds)
|
||
12. [Design decisions and rejected alternatives](#12-design-decisions-and-rejected-alternatives)
|
||
13. [Troubleshooting](#13-troubleshooting)
|
||
14. [Current state](#14-current-state)
|
||
15. [Licence](#15-licence)
|
||
|
||
---
|
||
|
||
## 1. What this is
|
||
|
||
A self-hosted, mobile-friendly Escape from Tarkov map viewer.
|
||
|
||
Layered Photoshop files from [re3mr.com](https://re3mr.com) go in; a Leaflet
|
||
XYZ tile pyramid comes out. Every map is placed onto **one shared world
|
||
canvas** — the overall satellite map of Tarkov, rotated so north is up. Zoom
|
||
out for the whole region; zoom into a location and the full-resolution map for
|
||
it takes over.
|
||
|
||
Two deliberate scope choices:
|
||
|
||
- **Base map art only.** Markers, spawns, extracts, captions, legends and
|
||
titles are dropped during the render. Only terrain survives.
|
||
- **Approximate placement.** The game's individual maps are not drawn to match
|
||
the satellite view, so exact registration is impossible. The goal is
|
||
"clearly the right place".
|
||
|
||
---
|
||
|
||
## 2. How it fits together
|
||
|
||
```
|
||
sources/<id>/*.psd layered source art (Git LFS, 0.2-1.1 GB each)
|
||
│
|
||
│ tools/export_base.py keep only baseLayers, drop everything else
|
||
▼
|
||
build/<id>/base.png flat RGBA render at full PSD canvas size
|
||
│
|
||
│ tools/tile.py crop, scale to world size, pad, cut tiles
|
||
▼
|
||
web/tiles/<id>/{z}/{x}/{y}.webp + web/data/world.json
|
||
│
|
||
│ server/run.ps1 Caddy (or serve.py)
|
||
▼
|
||
web/index.html + app.js Leaflet viewer
|
||
```
|
||
|
||
`tools/build.py` orchestrates export → tile → manifest. `maps.json` is the only
|
||
file you edit to add or change a map.
|
||
|
||
### File inventory
|
||
|
||
| Path | Lines | Role |
|
||
| --- | --- | --- |
|
||
| `maps.json` | — | **The only input you edit.** Every map, its layers, crop and placement |
|
||
| `tools/common.py` | 131 | Config loading, rotation maths, world placement |
|
||
| `tools/psd_tree.py` | 48 | Print a PSD's layer tree — run first when onboarding |
|
||
| `tools/export_base.py` | 168 | PSD → `build/<id>/base.png`, keeping only `baseLayers` |
|
||
| `tools/tile.py` | 153 | `base.png` → placed, padded XYZ tile pyramid |
|
||
| `tools/build.py` | 102 | Orchestrator; writes `web/data/world.json` |
|
||
| `tools/place_preview.py` | 69 | Gridded north-up base map for positioning |
|
||
| `tools/retilt.py` | 53 | Change `world.rotate` without moving any map |
|
||
| `tools/preview.py` | 71 | Stitch built tiles into one overview image |
|
||
| `web/app.js` | 179 | The whole viewer |
|
||
| `web/style.css` | 114 | Dark minimal UI |
|
||
| `server/serve.py` | 81 | Dependency-free static server (fallback) |
|
||
| `server/Caddyfile` | — | Production static server config |
|
||
|
||
Roughly 1200 lines total, plus vendored Leaflet 1.9.4.
|
||
|
||
### Dependencies
|
||
|
||
```
|
||
psd-tools[composite]>=1.18 the [composite] extra is required, see §11
|
||
Pillow>=11
|
||
```
|
||
|
||
Python 3.13 on the build machine. No ImageMagick, libvips or GDAL. Node is not
|
||
required — Leaflet is vendored, and there is no build step for the web app.
|
||
|
||
---
|
||
|
||
## 3. Coordinate systems
|
||
|
||
Four spaces, converted in this order:
|
||
|
||
**1. PSD pixels** — the source canvas, e.g. Customs is 7832 × 5016. `crop` is
|
||
expressed here.
|
||
|
||
**2. Overall-map pixels (unrotated)** — `overall.jpeg`, 1308 × 1296. Only used
|
||
internally; you never author in this space.
|
||
|
||
**3. Overall-map pixels (rotated)** — the same image after
|
||
`rotate(world.rotate, expand=True)`, currently 1842 × 1842 at 45°. **This is
|
||
where `place` lives**, because it is the north-up image you actually look at.
|
||
`tools/place_preview.py` draws a 100 px grid over it so you can read
|
||
coordinates directly.
|
||
|
||
**4. World pixels** — rotated overall-map pixels × `world.overallScale` (64).
|
||
The world is 117 824 × 117 824. Tiles, origins and Leaflet coordinates all use
|
||
this space.
|
||
|
||
In the viewer, a Leaflet `LatLng` is `(y, x)` in world pixels at native
|
||
resolution, via a custom CRS:
|
||
|
||
```js
|
||
const CRS = L.extend({}, L.CRS.Simple, {
|
||
transformation: new L.Transformation(1, 0, 1, 0), // y grows downward
|
||
scale: (z) => 2 ** (z - ZMAX),
|
||
zoom: (s) => Math.log(s) / Math.LN2 + ZMAX,
|
||
});
|
||
```
|
||
|
||
so at `maxZoom` one world pixel is one CSS pixel, and `lat` increases
|
||
downward — matching image coordinates rather than geographic north.
|
||
|
||
### Rotation
|
||
|
||
`rotate_point()` in `common.py` reproduces PIL's `rotate(deg, expand=True)`
|
||
analytically, and `unrotate_point()` inverts it. Both are **verified sub-pixel
|
||
against PIL** (max error 0.7 px over test points; predicted canvas size within
|
||
1 px).
|
||
|
||
`overallScale = 64` was chosen so Customs lands at almost exactly its native
|
||
7832 px source width. It also makes the base map's native level land on a whole
|
||
number: `maxZoom − log2(64) = 9 − 6 = 3`.
|
||
|
||
---
|
||
|
||
## 4. The tile grid, and why maps are padded
|
||
|
||
This is the core mechanism; everything else follows from it.
|
||
|
||
Each map is tiled independently and numbered **from its own cell origin**. For
|
||
that to work, a map's tile-index offset must be a whole number of tiles at
|
||
every zoom level. That holds only when the origin is a multiple of
|
||
|
||
```
|
||
cellSize = tileSize · 2^maxZoom = 256 · 2^9 = 131 072 world pixels
|
||
```
|
||
|
||
131 072 px is larger than the entire world (117 824 px). Useless for
|
||
positioning — every map would land at (0, 0).
|
||
|
||
**The fix is to pad, not to snap.** The tiler:
|
||
|
||
1. computes the map's exact world rect from `place`;
|
||
2. takes `cell = floor(origin / cellSize)` — in practice always `(0, 0)`;
|
||
3. records `pad = origin − cell · cellSize`, the exact sub-cell offset;
|
||
4. renders the map into that padded position;
|
||
5. **visits only the tile indices that actually contain content.**
|
||
|
||
Step 5 is what makes it free. The padded canvas is notionally enormous, but the
|
||
tiler computes the content's tile range directly:
|
||
|
||
```python
|
||
tx0, tx1 = floor(px / ts), ceil((px + cw) / ts)
|
||
ty0, ty1 = floor(py / ts), ceil((py + ch) / ts)
|
||
```
|
||
|
||
and never iterates the empty region. Result: exact placement, an integral grid,
|
||
and no cost for the padding.
|
||
|
||
Because every map shares the world origin, tile `(z, x, y)` of any map sits at
|
||
world-level pixel `(x · 256, y · 256)` — which is why `tools/preview.py` can
|
||
stitch all maps into one image by simply pasting at `x·ts, y·ts`.
|
||
|
||
### Native levels
|
||
|
||
A map is tiled only down to its **native level** — the deepest zoom at which we
|
||
are still downscaling its source:
|
||
|
||
```python
|
||
native = maxZoom + log2(source_width / target_world_width)
|
||
native_level = min(maxZoom, floor(native + 0.25))
|
||
```
|
||
|
||
The `+ 0.25` slack matters. Customs computes to 7.88; plain `floor()` would
|
||
give 7 and render its 7832 px source at 4240 px, discarding almost half the
|
||
detail. The slack tolerates up to a 1.19× upscale — invisible — to keep it.
|
||
|
||
Past its native level the browser upscales, which looks identical to upscaling
|
||
during the build but stores nothing. Each map also carries a `minZoom` below
|
||
which it is not loaded at all, so the overview costs only the base map.
|
||
|
||
---
|
||
|
||
## 5. The build pipeline
|
||
|
||
### `export_base.py` — PSD → flat RGBA
|
||
|
||
Renders only the layers named in `baseLayers` and hides everything else. The
|
||
visibility walk keeps a layer if it *is* a target, is an **ancestor** of one
|
||
(so the target is reachable), or is a **descendant** of one; everything else is
|
||
hidden before a single whole-document composite.
|
||
|
||
Output is **RGBA**, deliberately: these maps are composited onto terrain, so
|
||
regions outside the map art must be transparent rather than opaque black or
|
||
white rectangles.
|
||
|
||
A `baseLayers` entry matching nothing is a hard error — silently rendering the
|
||
wrong thing after a five-minute wait is worse than failing. `excludeLayers`
|
||
misses only warn.
|
||
|
||
One failed map no longer aborts the batch; failures are collected and reported
|
||
at the end.
|
||
|
||
### `tile.py` — place, pad, cut
|
||
|
||
Crops, scales to the world size implied by `place`, pads to the cell boundary,
|
||
and writes WebP tiles (quality 78, method 5). Fully-transparent tiles are
|
||
skipped; fully-opaque tiles are written as RGB rather than RGBA.
|
||
|
||
It refuses to tile a map larger than one cell with an actionable message.
|
||
|
||
### `build.py` — orchestration
|
||
|
||
Skips the PSD render when `base.png` is newer than the PSD, so iterating on
|
||
`place` or `crop` takes seconds rather than minutes. Maps not part of the
|
||
current run are preserved in `world.json`, so partial builds don't drop layers.
|
||
|
||
### Commands
|
||
|
||
```bash
|
||
python tools/build.py # base + every map
|
||
python tools/build.py customs # one map
|
||
python tools/build.py overall # just retile the base
|
||
python tools/build.py --tiles-only # skip the slow PSD render
|
||
python tools/build.py --force-export # re-render even if base.png is current
|
||
```
|
||
|
||
```bash
|
||
python tools/psd_tree.py sources/woods/woods.psd --depth 2
|
||
python tools/place_preview.py # gridded base for positioning
|
||
python tools/retilt.py 35 # change tilt, keeping placements
|
||
python tools/preview.py 4 # stitch tiles into one overview
|
||
```
|
||
|
||
### Timings
|
||
|
||
PSD render is the long pole, roughly 3 minutes per GB:
|
||
|
||
| Map | PSD | Render |
|
||
| --- | --- | --- |
|
||
| Reserve | 299 MB | 16 s |
|
||
| Lighthouse | 486 MB | 20 s |
|
||
| Shoreline | 203 MB | 60 s |
|
||
| Customs | 1143 MB | 158 s |
|
||
| Streets | 811 MB | 225 s |
|
||
| Woods | 530 MB | 236 s |
|
||
| Shoreline Resort | 527 MB | 292 s |
|
||
| Interchange | 1064 MB | 347 s |
|
||
|
||
Tiling the whole world takes well under a minute. Peak memory during render is
|
||
around 8 GB for the largest PSDs.
|
||
|
||
---
|
||
|
||
## 6. Configuration reference — `maps.json`
|
||
|
||
### Top level
|
||
|
||
| Key | Value | Meaning |
|
||
| --- | --- | --- |
|
||
| `tileSize` | 256 | Tile edge in pixels |
|
||
| `maxZoom` | 9 | World zoom depth; sets `cellSize = tileSize · 2^maxZoom` |
|
||
| `attribution` | HTML | Shown in the viewer; **must** keep the re3mr credit |
|
||
| `world.image` | path | The base map |
|
||
| `world.rotate` | 45 | Degrees counter-clockwise to put north up |
|
||
| `world.overallScale` | 64 | World pixels per overall-map pixel |
|
||
|
||
### Per map
|
||
|
||
| Key | Required | Meaning |
|
||
| --- | --- | --- |
|
||
| `id` | yes | URL-safe; becomes `web/tiles/<id>/` |
|
||
| `name` | yes | Label in the picker |
|
||
| `psd` | yes | Path under `sources/` |
|
||
| `baseLayers` | yes | Slash-paths from the document root; everything else hidden |
|
||
| `excludeLayers` | no | Layer names to hide anywhere inside the kept set |
|
||
| `crop` | no | `[x0, y0, x1, y1]` in PSD pixels, or `null` |
|
||
| `minZoom` | no | Raise the automatically derived zoom at which a nested detail layer appears |
|
||
| `place` | yes | `{cx, cy, w, h?}`: center anchor and dimensions in **rotated** overall-map pixels |
|
||
| `pxPerMeter` | no | From the map's scale bar; recorded for future use |
|
||
| `skirt` | no | EXPERIMENTAL: `{image, scale?, featherIn?, fadeOut?, matchColours?}` — AI terrain texture baked around the playable polygon in the trimmed pyramid; generated by `tools/skirt.py` (MiniMax `mmx`). See README → *Experimental: AI-generated skirts* |
|
||
| `background` | no | Colour baked under the artwork at tile time — only where there is artwork, grown by `halo` source px and feathered, at `opacity`. A string (`"#5c6168"`) or `{color, halo?: 48, opacity?: 1}`. For floor plans drawn on transparency (Factory) |
|
||
| `trim` | no | `{points, outsideTransparency}` playable-area polygon; see below |
|
||
| `parent` | no | parent map id for grouped navigation and dropdown ordering |
|
||
|
||
`place.w` is the map's width in overall-map pixels. Height follows from the
|
||
source aspect ratio unless optional `place.h` is set, in which case width and
|
||
height can be tuned independently.
|
||
|
||
Detail layers default to `minZoom: 0`, keeping main location maps visible in
|
||
the overview. An explicit `minZoom` delays a nested detail layer until a closer
|
||
zoom, and cannot be set above its native tile level.
|
||
|
||
`trim.points` is a list of `[x, y]` vertices normalized to the map rectangle,
|
||
where both axes run from 0 to 1. Normalization keeps the boundary attached when
|
||
the map is moved or stretched. `outsideTransparency` runs from 0 (unchanged)
|
||
to 1 (fully transparent). Saving generates `build/<id>/trimmed.png` and a
|
||
separate `web/tiles-trimmed/<id>/` pyramid; `base.png` and the original tile
|
||
pyramid remain available and unchanged.
|
||
|
||
**Changing `world.rotate` by hand will move every map**, because `place` lives
|
||
in the rotated frame. Use `python tools/retilt.py <deg>`, which converts each
|
||
placement back through the old angle and forward through the new one.
|
||
|
||
---
|
||
|
||
## 7. Data contract — `world.json`
|
||
|
||
Generated into `web/data/`. The viewer hard-codes nothing about any map; adding
|
||
a map is a data change.
|
||
|
||
```json
|
||
{
|
||
"tileSize": 256,
|
||
"maxZoom": 9,
|
||
"worldSize": [117824, 117824],
|
||
"cellSize": 131072,
|
||
"rotate": 45.0,
|
||
"overallScale": 64.0,
|
||
"attribution": "Maps by <a href=\"https://re3mr.com\">re3mr.com</a> · CC BY-NC-SA 4.0",
|
||
"maps": [
|
||
{
|
||
"id": "customs",
|
||
"name": "Customs",
|
||
"cell": [0, 0],
|
||
"origin": [53600, 58752],
|
||
"size": [16960, 6529],
|
||
"minZoom": 3,
|
||
"maxNativeZoom": 8,
|
||
"base": false,
|
||
"version": "120c7eae",
|
||
"pxPerMeter": 7.39
|
||
}
|
||
]
|
||
}
|
||
```
|
||
|
||
`maps` is ordered base-first, then by descending footprint. `version` is a hash
|
||
of the map's geometry, zoom range and source file stamp — see §11.
|
||
|
||
---
|
||
|
||
## 8. The viewer
|
||
|
||
### Semantic PSD markers
|
||
|
||
`tools/extract_markers.py` reads PSD layer metadata only; it never composites
|
||
marker pixels. Visible leaves in on-map overlay/marker groups are classified,
|
||
normalized against the configured crop, and deduplicated when a PSD icon and
|
||
text component share the same point. Legends, credits, titles, compass art and
|
||
large region overlays are excluded. Each generated
|
||
`web/data/markers/<map-id>.json` contains only that map's
|
||
`{mapId, x, y, category, label, source}` records.
|
||
|
||
`tools/render_marker_audit.py` composites all visible PSD layers, uses the
|
||
configured crop for both panes, and produces one side-by-side comparison per
|
||
map plus a contact sheet. This is the visual QA step for finding off-map
|
||
records, helper/legend artifacts, missing names, and PMC/Scav/shared/hidden
|
||
extract role mismatches. Source PSDs and generated map tiles are never changed.
|
||
|
||
The viewer converts normalized coordinates through each map's current
|
||
`origin`/`size`, so placement and stretch changes also move the marker layer.
|
||
One **Markers** control toggles the complete layer, while the grouped category
|
||
controls toggle individual marker types. Visibility choices are saved in local
|
||
browser storage. Hover tooltips show the marker name, category and source map.
|
||
|
||
**Marker edit** enables existing markers as draggable Leaflet markers. Clicking
|
||
one opens an edit box anchored next to it (a Leaflet popup in its own pane)
|
||
with the label, category and a delete button; Enter or a left click anywhere
|
||
outside the box saves, Escape cancels. Dragging persists normalized map-local
|
||
coordinates. Right-clicking the map opens a category menu that creates a
|
||
draggable draft at the pointer (entering marker edit mode for the map under it)
|
||
and opens the same box; **Drop new marker** does the same with a click. A draft
|
||
is written only when its box is committed. `/api/marker` stores extracted
|
||
marker changes as overrides, new markers as additions, and deletions as default
|
||
marker ID tombstones in
|
||
`web/data/marker-edits/<map-id>.json`; it never rewrites the corresponding
|
||
generated marker file. Deleting a user-added marker removes only that addition.
|
||
|
||
`tools/backup_markers.py` copies every current generated map file into
|
||
`web/data/marker-defaults/`, refuses to overwrite a differing snapshot, and
|
||
marks each backup read-only. Neither the viewer nor the server API has a write
|
||
path to this directory, preserving a restoration source independent of future
|
||
extraction runs.
|
||
|
||
`web/data/marker-config.json` controls each category's group, label, color,
|
||
size, symbol (plain text or emoji), visible text and default visibility. Its
|
||
defaults also control the text-label zoom, spatial-index cell size and viewport
|
||
padding. At runtime, `web/app.js` indexes records into world-space grid cells,
|
||
queries only cells intersecting the padded viewport, and reconciles that small
|
||
result with the currently rendered Leaflet markers. Focus fetches only the
|
||
active parent/sub-map family and unloads the previous family's records. A child
|
||
is always loaded with its root map, so Customs includes Dorms and Shoreline
|
||
includes Resort without requiring a second selection.
|
||
|
||
Extract categories have their own earlier label threshold and higher stacking
|
||
order. They are visible by default; noisy bulk categories start hidden but
|
||
remain individually toggleable. `visibilityVersion` provides a clean default
|
||
set when those defaults change without overwriting later user choices.
|
||
|
||
After viewport marker reconciliation, a label-layout pass reserves marker,
|
||
panel and already-placed label rectangles in a small spatial grid. It searches
|
||
bounded nearby positions, prioritizes extracts, and draws a short leader line
|
||
when a label must move away from its icon. Icon avoidance is relaxed before a
|
||
label is ever sent far from its marker. Layout reruns after marker, viewport or
|
||
panel-size changes without rebuilding the marker index.
|
||
|
||
The viewer has no build step or framework and uses vendored Leaflet.
|
||
|
||
### Layers
|
||
|
||
Every map becomes an `OffsetTileLayer` — a `L.TileLayer` subclass whose
|
||
`getTileUrl` translates world tile coordinates into the map's local grid and
|
||
appends the cache-busting version:
|
||
|
||
```js
|
||
const perCell = (o.baseTileSize * 2 ** coords.z) / o.tileSize;
|
||
x: coords.x - o.cell[0] * perCell
|
||
y: coords.y - o.cell[1] * perCell
|
||
```
|
||
|
||
`perCell` is derived from `baseTileSize` rather than assuming `2^z`, so the
|
||
maths stays exact under the density boost (§8, *Sharpness*).
|
||
|
||
### Stacking
|
||
|
||
Placements are approximate, so map rectangles overlap where the real locations
|
||
don't — Reserve clips Customs, Lighthouse clipped Shoreline. Two rules:
|
||
|
||
1. **Baseline order** — by `maxNativeZoom`, then smaller footprint, so the
|
||
finer map is on top. The base map is always at the bottom.
|
||
2. **Focus override** — the map whose centre you are viewing is lifted above
|
||
everything else.
|
||
|
||
Rule 2 is what actually solves it. Chasing perfect boxes would not: whichever
|
||
neighbour overlaps you, the map you navigated to now wins.
|
||
|
||
### No black gaps
|
||
|
||
The base map is the backdrop: 85 tiles / 0.3 MB, always resident, and Leaflet
|
||
upscales it past its native z3. Any gap while detail tiles load shows blurry
|
||
terrain rather than the page background.
|
||
|
||
### Sharpness
|
||
|
||
Leaflet picks its tile 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` halves each tile's CSS size and adds a matching `zoomOffset`,
|
||
so Leaflet downscales a denser level instead of upscaling a coarser one.
|
||
Measured at DPR 1.5, in source pixels per device pixel (higher is sharper):
|
||
|
||
| | Before | After |
|
||
| --- | --- | --- |
|
||
| Below native level | 0.56 | **1.33** |
|
||
| At native level | 0.67 | 0.67 |
|
||
|
||
It costs roughly 4× the tiles in view (~17 KB each) in DOM nodes, decodes and
|
||
bytes, so it is conditional: on above DPR 1.05 in Auto, always on in Sharp,
|
||
always off in Fast (see *Performance profile*). A 1:1 display in Auto accepts
|
||
at most a 1.19× stretch at quarter zooms.
|
||
|
||
### Performance profile
|
||
|
||
`app.js` derives `PERF` and `DENSITY_BOOST` from a *Detail* mode
|
||
(`localStorage` key `tarkov-quality`: `auto` | `fast` | `sharp`; the panel
|
||
button cycles it and reloads, because tile size and layer options are fixed at
|
||
layer creation):
|
||
|
||
| | Auto | Fast | Sharp |
|
||
| --- | --- | --- | --- |
|
||
| density boost | DPR > 1.05 | off | on |
|
||
| `fadeAnimation` | on | off | on |
|
||
| `updateWhenIdle` | `L.Browser.mobile` | on | `L.Browser.mobile` |
|
||
| `updateInterval` / `keepBuffer` | 200 ms / 2 | 400 ms / 1 | 200 ms / 2 |
|
||
| cache-warm depth | z ≤ 5 | z ≤ 4 | z ≤ 5 |
|
||
|
||
Auto becomes Fast on a low-end device (`deviceMemory` ≤ 4, `hardwareConcurrency`
|
||
≤ 2) or a slow connection (`saveData`, 2G/3G); warming is skipped on slow
|
||
connections. The base layer always loads mid-pan (`updateWhenIdle: false`).
|
||
|
||
Independent of mode:
|
||
|
||
- **Low-res underlay** — a second `OffsetTileLayer` per detail map with
|
||
`maxNativeZoom` capped at `PERF.previewLevel` (4), `updateWhenIdle`,
|
||
`keepBuffer 4`, `zIndex 0` in the same pane (`.tile-preview`). Its container
|
||
is set to opacity 1 on the main layer's `loading` event and 0 on `load`, so
|
||
a trimmed map's translucent margin never stacks twice once real tiles are
|
||
in. Created before the main layer so its few requests leave first; URL and
|
||
version follow `setLayerSource`.
|
||
- **Cache warming** — `precacheUrls()` reproduces `tile.py`'s grid maths
|
||
(`pad · scale / tileSize`) from `world.json` and fetches every map's shallow
|
||
levels at idle (`requestIdleCallback`, two in flight, `priority: 'low'`,
|
||
paused between `movestart` and `moveend`). Empty tiles inside the bounding
|
||
box 404 and are ignored. A `tarkov-precache` stamp (versions + time) skips
|
||
the pass for a week.
|
||
- **Per-frame work** — `updatePreviewTransforms` iterates only `movedPreviews`
|
||
(maps whose placement preview differs from the saved geometry), so outside
|
||
the placement editor the `move`/`zoom` handler is a no-op. `focus()` returns
|
||
early when the focused family is unchanged (it used to re-stack every pane
|
||
and re-fetch the family's marker files on every `moveend`).
|
||
`updateMarkerDensity` runs on `zoomend`. `createTile` sets
|
||
`decoding = 'async'`.
|
||
- **Markers** — `layoutMarkerLabels` resets all labels first (writes) and then
|
||
measures (reads); returns early when no label class is active; indexes icon
|
||
rectangles in the same cell grid as labels (`makeRectIndex`) instead of a
|
||
linear `some()` per candidate; generates the 8 rings × 16 angles lazily and
|
||
stops at the first acceptable spot; reads cached `_poi` parts (label, leader,
|
||
size, extract flag, set by `cacheMarkerParts` when a marker is added) instead
|
||
of `querySelector` per pass; and decides label visibility from the
|
||
container's `marker-labels-visible` / `marker-extract-labels-visible`
|
||
classes, mirroring style.css, instead of `getComputedStyle`. `categoryConfig`
|
||
is memoised. `refreshMarkers` keeps markers inside `viewportPadding × 3`
|
||
through short pans. Each pass is recorded as a `tarkov:marker-labels`
|
||
`performance.measure`.
|
||
- **Marker size slider** — `#marker-scale-control` (top right; bottom left
|
||
under 640 px) sets `--marker-scale` on the map container; `.poi-content` is
|
||
`transform: scale(var(--marker-scale))` about its centre, so no icon is
|
||
rebuilt. The layout works in visual (scaled) pixels and converts to the
|
||
icon's local space when writing styles: `local = size/2 + (visual − point)/scale`.
|
||
Tooltip offsets follow the scale. Logarithmic slider, 0.5×–2×, persisted as
|
||
`tarkov-marker-scale`; clicking the readout resets to 1×.
|
||
- **Service worker** — `web/sw.js`: tiles/vendor cache-first, shell
|
||
stale-while-revalidate, `data/*.json` network-first with cache fallback,
|
||
`capabilities.json` and `api/` network only. Registered only when
|
||
`capabilities.mapEditing` is false; the authoring server unregisters any
|
||
existing worker. The page posts the live `version`/`trimmedVersion` list so
|
||
tiles from superseded builds are evicted. Needs HTTPS or `localhost`.
|
||
|
||
### Other behaviour
|
||
|
||
- URL hash `#zoom/y/x` for shareable positions.
|
||
- Map picker; the active map is marked.
|
||
- `window.tarkovMap` / `window.tarkovWorld` exposed for console debugging.
|
||
- Non-dismissible attribution control (licence requirement), flush in the
|
||
bottom-right corner below the zoom buttons (added first; Leaflet stacks
|
||
bottom-corner controls upwards).
|
||
- Zoom buttons are Leaflet's `<a href="#">` made non-draggable (`draggable =
|
||
false`, `dragstart` prevented, `-webkit-user-drag: none`) and styled like the
|
||
toolbar buttons — a moving click used to start a ghost-image link drag.
|
||
- Mobile: `viewport-fit=cover`, safe-area insets, 44 px touch targets,
|
||
collapsible picker, zoom buttons hidden under 640 px in favour of pinch.
|
||
|
||
### Placement editor
|
||
|
||
Each detail map's `place.cx/cy` is its center anchor in rotated overall-map
|
||
pixels. Select a map and choose **Edit placement** to expose that anchor. A
|
||
drag or numeric X/Y edit translates the map's dedicated Leaflet pane live.
|
||
Width and Height scale the same pane independently around the anchor, providing
|
||
horizontal and vertical stretch with a live aspect-ratio readout.
|
||
|
||
Placement editing temporarily hides any trim overlay and renders the complete
|
||
selected map at exactly 50% opacity, making underlying satellite landmarks
|
||
visible during alignment.
|
||
|
||
**Save & rebuild** posts the new center and dimensions to `server/serve.py`.
|
||
The server writes `maps.json` atomically, runs a tiles-only build for that map,
|
||
and returns only after `world.json` contains its new origin, size and
|
||
cache-busting version. Use
|
||
`pwsh server/run.ps1 -Editable`; the Caddy-only mode remains read-only.
|
||
|
||
### Trim editor
|
||
|
||
**Trim area** authors a single playable-area polygon. Map clicks append points;
|
||
points are draggable, and Undo/Clear support correction. The outside
|
||
transparency slider previews the result immediately.
|
||
|
||
While editing, the untouched tile pane and a clipped duplicate provide an
|
||
immediate preview without rebuilding on every drag. **Save trim** posts the
|
||
normalized points and transparency to `/api/trim`; the server writes
|
||
`maps.json`, bakes the outside alpha into `build/<id>/trimmed.png`, and creates
|
||
a separately versioned `web/tiles-trimmed/<id>/` pyramid. The normal viewer
|
||
then uses those already-rasterized tiles with no dynamic CSS mask. Clearing and
|
||
saving a trim returns the viewer to the original tiles. The trim-only build
|
||
leaves both `base.png` and `web/tiles/<id>/` untouched.
|
||
|
||
The original rectangle remains the raster/tile coordinate frame so alignment
|
||
does not move. The viewer separately derives a viewable bounding box and exact
|
||
point-in-polygon hit area from `trim.points`; map-button focusing and automatic
|
||
active-map selection therefore follow the saved playable zone.
|
||
|
||
---
|
||
|
||
## 9. Serving
|
||
|
||
Tiles are inert static files. `server/run.ps1` uses Caddy when
|
||
`server/caddy.exe` exists (fetch with `server/get-caddy.ps1`) and falls back to
|
||
`server/serve.py` so a fresh clone works with nothing installed.
|
||
|
||
Measured on loopback, 480 tile requests over reused connections:
|
||
|
||
| | `serve.py` | Caddy |
|
||
| --- | --- | --- |
|
||
| Dependencies | none (stdlib) | one 47 MB binary |
|
||
| concurrency 8 | 2 622 req/s · p95 4.0 ms | **6 987 req/s** · p95 1.9 ms |
|
||
| concurrency 32 | 462 req/s · max **1 013 ms** | **5 877 req/s** · max 21 ms |
|
||
| ETags / compression | no | yes (zstd, gzip) |
|
||
|
||
The second row is the argument. `serve.py` is thread-per-connection behind the
|
||
GIL, so under load throughput *falls* below its 8-thread figure and tail
|
||
latency crosses a second. Caddy stays flat.
|
||
|
||
`serve.py` also inherited `SimpleHTTPRequestHandler`'s **HTTP/1.0** default,
|
||
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 serves HTTP/2**: browsers only negotiate h2 over TLS, and trusting a
|
||
local CA on every phone is not worth it on a LAN. The Caddy win is Go's I/O.
|
||
|
||
Cache policy: tiles `public, max-age=31536000, immutable`; app shell,
|
||
`sw.js` and `world.json` `no-cache` (a service worker script must never be
|
||
served stale — Caddy's `@shell` matcher includes `/sw.js`).
|
||
|
||
To reach it from a phone, allow the port once (elevated):
|
||
|
||
```bash
|
||
netsh advfirewall firewall add rule name="TarkovMap 8080" dir=in action=allow protocol=TCP localport=8080
|
||
```
|
||
|
||
---
|
||
|
||
## 10. Source-art findings
|
||
|
||
### There is no naming convention
|
||
|
||
Customs' tidy `LOCATION` / `OVERLAY` / `LEGEND` / `TITLE` structure turned out
|
||
to be a Customs thing. Every map differs:
|
||
|
||
| Map | PSD | Base layers |
|
||
| --- | --- | --- |
|
||
| Customs | 7832 × 5016 | `LOCATION` |
|
||
| Customs — Dorms | 4301 × 4904 | `LOCATION` |
|
||
| Woods | 7680 × 5168 | `re3mr.com/Map&Art/Map&OverlayArt/{RawMapLayer,WaterDetail}` |
|
||
| Interchange | 9600 × 5400 | `3DRENDER` |
|
||
| Reserve | 5760 × 3240 | `Day copy` |
|
||
| Shoreline | 5760 × 3240 | `Baselayer` |
|
||
| Shoreline — Resort | 10694 × 6016 | `BGCOLOR PATTERN`, `BASEMAP+2DLAYERS` |
|
||
| Lighthouse | 8259 × 7560 | `Day` (a hidden `Night` also exists) |
|
||
| Streets of Tarkov | 7605 × 4841, 16-bit | `Map - 3D map portion…` |
|
||
|
||
Several need more than one top-level layer; Woods buries its terrain three
|
||
groups deep. Always run `psd_tree.py`.
|
||
|
||
**Watch for plates.** Interchange's `Background` and Reserve's `Color Fill 1`
|
||
are solid white; Woods' `MapBlackout` and Streets' `Layer 1` are solid black.
|
||
Including them hides the terrain beneath.
|
||
|
||
### Detail ceilings are real
|
||
|
||
Customs' terrain is a smart object embedding a 473 MB PSB — but its header says
|
||
**7832 × 3720, placed 1:1**. There is no hidden resolution to recover. Its
|
||
7832 px source is the hard ceiling.
|
||
|
||
### Scale
|
||
|
||
Customs' scale bar gives **≈ 7.39 px/metre** (cross-checked at the 5, 25, 50
|
||
and 100 m ticks). Recorded as `pxPerMeter`; not yet used by the viewer.
|
||
|
||
### Two maps are floor plans
|
||
|
||
Customs — Dorms and Shoreline — Resort are interior schematics, not terrain.
|
||
They are placed at their building locations, which is geometrically right but
|
||
reads oddly over satellite imagery.
|
||
|
||
---
|
||
|
||
## 11. Traps and workarounds
|
||
|
||
Each of these cost real debugging time. They are documented so nobody pays
|
||
twice.
|
||
|
||
### psd-tools fills stroke-only vector shapes
|
||
|
||
A `shape` layer with a stroke and no fill renders as a **solid fill**. Customs'
|
||
`Map Borders` painted the entire playable area white — the first render was a
|
||
white blob. Worked around with `excludeLayers`.
|
||
|
||
Side effect: Customs no longer shows its dotted play-area boundary. The
|
||
out-of-bounds grey-out still marks it. Accepted.
|
||
|
||
### psd-tools crashes on stroke effects with empty bboxes
|
||
|
||
A layer carrying a stroke effect but an empty bbox feeds a zero-size array into
|
||
scikit-image's rank filter: `The parameter 'image' cannot be an empty array`.
|
||
Woods hits this. `export_base.py` patches `Compositor._apply_stroke_effect` to
|
||
skip the effect rather than lose the whole render.
|
||
|
||
### `psd_tools.composite` shadows its own submodule
|
||
|
||
`from psd_tools.composite import composite` returns a **function**, not the
|
||
module. Use `importlib.import_module("psd_tools.composite.composite")`.
|
||
|
||
### Layer effects need the `[composite]` extra
|
||
|
||
Without scikit-image, psd-tools raises `ImportError` on any layer with a
|
||
stroke. Hence `psd-tools[composite]` in `requirements.txt`.
|
||
|
||
### Immutable caching versus rebuilt tiles
|
||
|
||
Tile paths are stable across rebuilds but their contents are not: move a map's
|
||
`place` and `tiles/<id>/6/17/33.webp` becomes different imagery at the same
|
||
URL. Served `immutable` for a week, a browser that had seen the old build
|
||
blended the two and drew **duplicated, offset terrain**.
|
||
|
||
Every map now carries a `version` — hashed from geometry, zoom range and source
|
||
file stamp — appended to tile URLs as `?v=`. Re-tiled maps get fresh URLs;
|
||
identical rebuilds keep the same hash so nothing is re-fetched needlessly.
|
||
|
||
### The base map's tilt could not be measured automatically
|
||
|
||
Two attempts failed:
|
||
|
||
- **Aspect-ratio fit** of the Customs zone outline gave 31°, but the zone
|
||
polygon encloses more than the playable strip, so the estimate ran low.
|
||
- **Polygon registration** between the overall map and the PSD's `MapBorder`
|
||
failed because the zone outline is *dashed* and will not flood-fill — the
|
||
filled region came out at 2 % coverage with elongation 1.24 against the
|
||
PSD's 3.73.
|
||
|
||
The current **45°** is a visual judgement, not a measurement. `retilt.py` makes
|
||
it a one-number change.
|
||
|
||
### PowerShell here-strings in Bash
|
||
|
||
`@'...'@` is PowerShell syntax. Used in the Bash tool it silently prepends a
|
||
literal `@` to the commit message. Use a heredoc with `git commit -F -`.
|
||
|
||
---
|
||
|
||
## 12. Design decisions and rejected alternatives
|
||
|
||
| Decision | Why | Rejected |
|
||
| --- | --- | --- |
|
||
| XYZ tile pyramid + Leaflet | Standard, mobile gestures free, no client deps | `L.imageOverlay` (39 MP in one request); IIIF/DZI (extra dependency) |
|
||
| 256 px tiles | Works cleanly with the density boost (128 CSS px at 2×) | 512 px — fewer requests but coarser boost granularity |
|
||
| Conditional density boost + Detail modes | 4× tiles only where a display can show them; weak devices and slow links get 256 px tiles | Unconditional boost (4× tiles on every 1:1 display) |
|
||
| Low-res underlay shown only while loading | "Blurry then sharp" with no double-alpha on trimmed margins | Always-on underlay (stacks translucent margins); nothing (holes while loading) |
|
||
| WebP q78 / method 5 | ~4× smaller than PNG, alpha supported everywhere in scope; ~15–20 % smaller than q82 at no visible cost on map art | PNG (too large); JPEG (no alpha); method 6 (~60× slower on RGBA tiles, no smaller) |
|
||
| Pad maps onto the grid | Exact placement with an integral tile grid, zero cost | Snapping origins (131 072 px granularity — unusable); one giant baked world raster (gigapixels, rebuild everything per change) |
|
||
| Per-map pyramids | Adding a map never re-tiles the others | Single world pyramid |
|
||
| Pure-Python pipeline | No native binaries across several machines; 39 MP fits in RAM | libvips `dzsave` (faster, but a native dep) |
|
||
| Focus-based stacking | Robust to overlapping approximate placements | Chasing perfect placement boxes |
|
||
| Loose tile files | Trivially served and debuggable | PMTiles — worth revisiting past ~5 more maps |
|
||
| Caddy default, `serve.py` fallback | Fast where it matters, works from a bare clone | nginx (heavier Windows setup) |
|
||
| Base map art only | The user's explicit scope | Marker/overlay layers — cheap to revive, see below |
|
||
|
||
**Reviving marker overlays** would be inexpensive if wanted: the PSDs keep
|
||
every marker as its own layer with a known bounding box, so positions can be
|
||
extracted programmatically rather than hand-placed. Customs alone has 28 PMC
|
||
spawns, 15 scav spawns, 5 boss and 4 sniper markers already separated.
|
||
|
||
---
|
||
|
||
## 13. Troubleshooting
|
||
|
||
**Duplicated or offset terrain.** Cached tiles from an older build. Should be
|
||
impossible now that tile URLs carry `?v=`, but a browser that cached before
|
||
that change needs one hard reload (Ctrl+Shift+R).
|
||
|
||
**A map renders as a flat colour block.** A shape layer is filling, or you kept
|
||
a white/black plate layer. Check `build/<id>/base.png`, then fix `baseLayers`
|
||
or add to `excludeLayers`.
|
||
|
||
**Markers or legends survived.** Wrong `baseLayers` — re-run `psd_tree.py`.
|
||
|
||
**A map sits in the wrong place.** Run `place_preview.py`, read the grid, edit
|
||
`place`, re-run `build.py --tiles-only <id>`.
|
||
|
||
**Every map moved at once.** You edited `world.rotate` by hand. Restore it and
|
||
use `retilt.py`.
|
||
|
||
**`baseLayers entry '…' matched nothing`.** A typo, or the path is nested —
|
||
`psd_tree.py --depth 3`.
|
||
|
||
**Blurry at full zoom.** Expected past a map's native level; the source has no
|
||
more detail. Check `maxNativeZoom` in `world.json`.
|
||
|
||
**Tiles 404 in the browser.** Usually a stale `world.json` referencing a map
|
||
whose tiles were deleted. Re-run `build.py`.
|
||
|
||
**Phone cannot reach the LAN URL.** Firewall rule missing — see §9.
|
||
|
||
---
|
||
|
||
## 14. Current state
|
||
|
||
World 117 824 × 117 824 px, `maxZoom` 9, rotated 45°. Ten layers, **6101 tiles,
|
||
45.1 MB**.
|
||
|
||
| Layer | Origin | World size | Zooms | Tiles | Size |
|
||
| --- | --- | --- | --- | --- | --- |
|
||
| overall (base) | 0, 0 | 117824 × 117824 | z0–3 | 85 | 0.2 MB |
|
||
| woods | 38272, 37001 | 24320 × 16365 | z2–7 | 486 | 4.2 MB |
|
||
| shoreline | 41920, 75016 | 24320 × 13680 | z2–7 | 498 | 3.1 MB |
|
||
| lighthouse | 30560, 65929 | 17600 × 16110 | z3–8 | 1639 | 16.2 MB |
|
||
| customs | 55072, 58944 | 16960 × 6529 | z3–8 | 623 | 9.3 MB |
|
||
| reserve | 48704, 66408 | 8960 × 5040 | z4–8 | 287 | 1.7 MB |
|
||
| shoreline-resort | 44544, 77724 | 8320 × 4680 | z6–9 | 871 | 2.4 MB |
|
||
| streets | 63104, 25215 | 7040 × 4481 | z4–9 | 707 | 2.8 MB |
|
||
| interchange | 70368, 52434 | 6080 × 3420 | z6–9 | 375 | 3.3 MB |
|
||
| customs-dorms | 64768, 60806 | 4480 × 5108 | z6–9 | 530 | 1.9 MB |
|
||
|
||
Verified across zoom 0–9: zero broken tiles; every tile carries `?v=`; the
|
||
focused map is topmost in all seven tested cases.
|
||
|
||
### Known gaps
|
||
|
||
- **Placement accuracy varies.** Customs, Streets, Interchange and Reserve land
|
||
well. Lighthouse and Shoreline are noticeably offset.
|
||
- **Some maps keep dark surrounds** baked into their art (Streets, Lighthouse,
|
||
Shoreline's red band). The identifiable plates were stripped; the rest is
|
||
part of the source renders.
|
||
- **Nothing has been tested on a real phone.** The CSS is responsive with
|
||
proper touch targets, but this is unproven — the browser pane used during
|
||
development would not composite frames, so verification was DOM- and
|
||
network-level, never pixels.
|
||
- **Labs** is on the base map but has no detail map. Ground Zero, Factory, and
|
||
Labyrinth have been imported; Transit is intentionally reserved for a later
|
||
route-visualization style.
|
||
- **Source PSDs are Git LFS objects.** A full clone requires Git LFS and several
|
||
gigabytes of storage.
|
||
|
||
---
|
||
|
||
## 15. Licence
|
||
|
||
Map art is by [re3mr.com](https://re3mr.com) under **CC BY-NC-SA 4.0**,
|
||
confirmed in every PSD.
|
||
|
||
- Attribution is displayed in the viewer and **must stay there**.
|
||
- Non-commercial use only.
|
||
- Derivative map images inherit the same licence.
|
||
|
||
Local and LAN hosting is unambiguously fine. **Get sign-off before hosting
|
||
publicly** — ShareAlike would apply to the tiles as adapted works.
|
||
|
||
The `sources/` directory is versioned through Git LFS for large source assets.
|
||
`overall.jpeg` remains a normal Git object and is the anchor every placement is
|
||
expressed against.
|