import { orientation, S } from './state' import type { BBox, Orientation } from './types' /* ================= A4 page geometry for the HG3 submission ================= * The assignment prints the ČÚZK base map on A4 at 300 dpi, which gives 1 : 3 780. */ export const SCALE = 3780 export const DPI = 300 const PAGE_MM: Record = { landscape: [297, 210], portrait: [210, 297], } export const MARGIN_MM = 8 export const HEADER_MM = 9 export const FOOTER_MM = 7 export const pageMM = (o: Orientation = orientation.value) => PAGE_MM[o] /** Size of the map image on the page, in mm. */ export function mapBoxMM(o: Orientation = orientation.value): [number, number] { const [w, h] = PAGE_MM[o] return [w - 2 * MARGIN_MM, h - 2 * MARGIN_MM - HEADER_MM - FOOTER_MM] } /** Ground size of the printed map in metres. */ export function frameMeters(o?: Orientation): [number, number] { const [w, h] = mapBoxMM(o) return [(w * SCALE) / 1000, (h * SCALE) / 1000] } /** The print frame in Web Mercator, centred on the current view. */ export function frameRect(o?: Orientation): BBox { const [w, h] = frameMeters(o) const hx = w / 2 / S.K, hy = h / 2 / S.K return [S.view.cx - hx, S.view.cy - hy, S.view.cx + hx, S.view.cy + hy] } /** Load radius (see fetchArea: the query box is ±1.1 × radius) that covers the frame. */ export function frameRadius(o?: Orientation): number { const [w, h] = frameMeters(o) return Math.ceil(Math.max(w, h) / 2 / 1.1 / 50) * 50 } /** Whether the loaded data covers the whole frame. */ export function frameCovered(o?: Orientation): boolean { const bb = S.loadedBB, f = frameRect(o) return !!bb && f[0] >= bb[0] && f[1] >= bb[1] && f[2] <= bb[2] && f[3] <= bb[3] }