const NightCityMap = (() => { const Z = 4, SCALE = 256 * 16; const B = { x0: 0, y0: 0, x1: 14 * 256, y1: 13 * 256 }; const fracToLatLng = (fx, fy) => { const px = B.x0 + fx * (B.x1 - B.x0); const py = B.y0 + fy * (B.y1 - B.y0); return L.latLng(pyToLat(py), pxToLng(px)); }; const pxToLng = (px) => (px / SCALE) * 360 - 180; const pyToLat = (py) => { const n = Math.PI * (1 - (2 * py) / SCALE); return (Math.atan(Math.sinh(n)) * 180) / Math.PI; }; const latLngToUnits = (latlng) => { const p = L.CRS.EPSG3857.latLngToPoint(L.latLng(latlng), Z); const u = ((p.x - B.x0) / (B.x1 - B.x0)) * 1000; const v = ((p.y - B.y0) / (B.y1 - B.y0)) * 700; return { x: Math.max(0, Math.min(1000, u)), y: Math.max(0, Math.min(700, v)), }; }; const DISTRICTS = [ { name: 'Watson', box: [0.03, 0.03, 0.30, 0.24] }, { name: 'City Center', box: [0.33, 0.02, 0.54, 0.18] }, { name: 'Westbrook', box: [0.55, 0.04, 0.90, 0.28] }, { name: 'Heywood', box: [0.22, 0.26, 0.66, 0.60] }, { name: 'Santo Domingo', box: [0.66, 0.28, 0.95, 0.62] }, { name: 'Pacifica', box: [0.06, 0.62, 0.42, 0.95] }, { name: 'Badlands', box: [0.42, 0.62, 1.00, 0.97] }, { name: 'Badlands', box: [0.90, 0.10, 1.00, 0.60] }, ]; const POIS = [ { id: 'kabuki', name: 'Kabuki Market', fx: 0.13, fy: 0.10 }, { id: 'arasaka', name: 'Arasaka Waterfront', fx: 0.50, fy: 0.045 }, { id: 'corpo', name: 'Corpo Plaza', fx: 0.44, fy: 0.10 }, { id: 'japantown', name: 'Japantown', fx: 0.63, fy: 0.15 }, { id: 'afterlife', name: 'Afterlife', fx: 0.42, fy: 0.30 }, { id: 'mbh10', name: 'Megabuilding H10', fx: 0.33, fy: 0.42 }, { id: 'dogtown', name: 'Dogtown Gate', fx: 0.55, fy: 0.70 }, { id: 'mall', name: 'Grand Illusion Mall', fx: 0.23, fy: 0.78 }, ].map((p) => ({ ...p, latlng: fracToLatLng(p.fx, p.fy), units: { x: p.fx * 1000, y: p.fy * 700 } })); let map; const points = { A: null, B: null }; let onChange = () => {}; let routeLine = null; const markers = { A: null, B: null }; function districtAt(units) { const fx = units.x / 1000, fy = units.y / 700; for (const d of DISTRICTS) { const [x0, y0, x1, y1] = d.box; if (fx >= x0 && fx <= x1 && fy >= y0 && fy <= y1) return d.name; } return 'Night City outskirts'; } function nearestPOI(units) { let best = null, bestD = 55; for (const p of POIS) { const d = Math.hypot(p.units.x - units.x, (p.units.y - units.y) * (10 / 7)); if (d < bestD) { bestD = d; best = p; } } return best; } function placeName(units) { const poi = nearestPOI(units); return poi ? poi.name : districtAt(units); } function pinIcon(color, label) { return L.divIcon({ className: 'nc-pin-wrap', html: `