Files
TarkovMaps/web/app.js
T
Claude e8d8738892 Place all nine maps onto a north-up geographic world canvas
The canvas is no longer an abstract grid of unrelated cells. overall.jpeg is
now the base, rotated 31 degrees so north is up, and every detail map is
scaled and positioned onto its real location. Zoom out for all of Tarkov;
zoom in and the full-resolution re3mr map takes over.

The 31 degrees was measured, not guessed: Customs' detail map is north-up
(its PSD compass confirms it) and runs 2.6:1 east-west, so solving its
259x207 zone outline for the band angle gives 31. rotate_point is verified
sub-pixel against PIL.

Adds Woods, Interchange, Reserve, Shoreline, Shoreline Resort, Lighthouse
and Streets, and moves every source under sources/<id>/.

baseGroup becomes baseLayers, a list of slash-paths. These PSDs share no
naming convention at all -- the base is variously LOCATION, Baselayer, Day,
3DRENDER, BASEMAP+2DLAYERS or Map&Art; several need more than one top-level
layer, and Woods buries its terrain three groups deep. Exports also keep
alpha now, so maps composite onto the terrain instead of sitting in opaque
rectangles.

Placement needs sub-cell precision, but tile grids stay integral only when
a map's origin is a multiple of tileSize * 2^maxZoom (131072 px). So rather
than snapping a map to the grid, the tiler pads it up-and-left to the
nearest cell boundary and visits only tiles holding content: exact
placement, integral grid, no cost. Each map is tiled to its native level
and carries a minZoom, so the overview stays cheap.

Two psd-tools failures worked around: stroke effects on empty-bbox layers
crash scikit-image (patched to skip), and psd_tools.composite exports a
function that shadows its own submodule.

Verified zoom 0-9: 10 layers, zero broken tiles.

Co-Authored-By: Claude Opus 5 <[email protected]>
2026-08-08 04:02:38 -07:00

152 lines
5.2 KiB
JavaScript

/* Tarkov Maps -- every map on one shared canvas.
*
* The base layer is the overall satellite map, rotated so north is up. Every
* detail map is scaled and positioned onto it, so zooming into Customs on the
* world map lands you in the full-resolution re3mr Customs map.
*
* Coordinates: LatLng is (y, x) in *world pixels* at native resolution, where
* one world pixel is 1/overallScale of an overall-map pixel. Each map's tiles
* are numbered from its own padded cell origin -- see tools/common.py.
*/
const ZOOM_HEADROOM = 1; // how far past a layer's native detail we allow
const ZOOM_SNAP = 0.25;
const BLANK = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
/* Leaflet picks its tile level with Math.round(mapZoom), so at zoom 2.25 it
* takes level 2 and stretches it 1.19x; on a 1.5x display that compounds to a
* visibly soft 1.78x upscale. Halving a tile's CSS size and asking for one
* level deeper makes us downscale a denser level instead. */
const DENSITY_BOOST = (window.devicePixelRatio > 1.05 || ZOOM_SNAP < 1) ? 1 : 0;
const OffsetTileLayer = L.TileLayer.extend({
getTileUrl(coords) {
const o = this.options;
const perCell = (o.baseTileSize * 2 ** coords.z) / o.tileSize;
return L.Util.template(this._url, {
z: coords.z + o.zoomOffset,
x: coords.x - o.cell[0] * perCell,
y: coords.y - o.cell[1] * perCell,
});
},
});
const rectOf = (m) => L.latLngBounds(
[m.origin[1], m.origin[0]],
[m.origin[1] + m.size[1], m.origin[0] + m.size[0]],
);
function readHash() {
const p = location.hash.replace(/^#/, '').split('/');
if (p.length !== 3) return null;
const [z, y, x] = p.map(Number);
return [z, y, x].every(Number.isFinite) ? { z, y, x } : null;
}
async function main() {
const world = await fetch('data/world.json', { cache: 'no-cache' }).then((r) => {
if (!r.ok) throw new Error(`world.json: ${r.status}`);
return r.json();
});
if (!world.maps.length) throw new Error('world.json contains no maps');
const ZMAX = world.maxZoom;
const base = world.maps.find((m) => m.base) ?? world.maps[0];
const CRS = L.extend({}, L.CRS.Simple, {
transformation: new L.Transformation(1, 0, 1, 0),
scale: (z) => 2 ** (z - ZMAX),
zoom: (s) => Math.log(s) / Math.LN2 + ZMAX,
});
const extent = L.latLngBounds([0, 0], [world.worldSize[1], world.worldSize[0]]);
const map = L.map('map', {
crs: CRS,
minZoom: 0,
maxZoom: ZMAX + ZOOM_HEADROOM,
zoomSnap: ZOOM_SNAP,
zoomDelta: 0.5,
wheelPxPerZoomLevel: 90,
maxBounds: extent.pad(0.05),
maxBoundsViscosity: 0.75,
attributionControl: false,
});
L.control.attribution({ prefix: false })
.addAttribution(world.attribution)
.addTo(map);
const boost = DENSITY_BOOST;
for (const [i, m] of world.maps.entries()) {
// The base map is the backdrop: it is a handful of tiles, always loaded,
// and Leaflet upscales it past its native level -- so a gap while detail
// tiles load shows blurry terrain rather than the page background.
const isBase = !!m.base;
new OffsetTileLayer(`tiles/${m.id}/{z}/{x}/{y}.webp`, {
cell: m.cell,
bounds: rectOf(m),
baseTileSize: world.tileSize,
tileSize: world.tileSize / 2 ** boost,
zoomOffset: boost,
minZoom: isBase ? 0 : m.minZoom,
maxZoom: ZMAX + ZOOM_HEADROOM,
maxNativeZoom: Math.max(0, m.maxNativeZoom - boost),
minNativeZoom: 0,
noWrap: true,
keepBuffer: isBase ? 6 : 2,
updateWhenIdle: false,
errorTileUrl: BLANK,
zIndex: isBase ? 1 : 2 + i,
className: isBase ? 'tile-base' : undefined,
}).addTo(map);
}
// --- picker -----------------------------------------------------------
const list = document.getElementById('maplist');
const targets = [base, ...world.maps.filter((m) => !m.base)];
const buttons = targets.map((m) => {
const b = document.createElement('button');
b.textContent = m.base ? 'Overview' : m.name;
b.dataset.id = m.id;
b.addEventListener('click', () => {
map.flyToBounds(rectOf(m), { padding: [24, 24], duration: 0.7 });
if (window.matchMedia('(max-width: 640px)').matches) {
document.getElementById('panel').open = false;
}
});
list.appendChild(b);
return b;
});
const syncUI = () => {
const c = map.getCenter();
// Smallest non-base map containing the centre wins -- Dorms beats Customs.
const hit = world.maps
.filter((m) => !m.base && rectOf(m).contains(c) && map.getZoom() >= m.minZoom)
.sort((a, b) => a.size[0] * a.size[1] - b.size[0] * b.size[1])[0];
buttons.forEach((b) => b.setAttribute(
'aria-current', String(hit ? hit.id === b.dataset.id : b.dataset.id === base.id)));
const z = Math.round(map.getZoom() * 4) / 4;
history.replaceState(null, '', `#${z}/${Math.round(c.lat)}/${Math.round(c.lng)}`);
};
map.on('moveend zoomend', syncUI);
const h = readHash();
if (h) map.setView([h.y, h.x], h.z);
else map.fitBounds(rectOf(base), { padding: [10, 10] });
syncUI();
document.getElementById('boot').remove();
window.tarkovMap = map;
window.tarkovWorld = world;
}
main().catch((err) => {
document.getElementById('boot').textContent = `Failed to load: ${err.message}`;
console.error(err);
});