building-use-map/src/components/PrintView.tsx
HangerThem bb5ecbcd6d feat(hg3): align with the HG3 semester project assignment
- Default "Zadání HG3" mode with exactly the 16 categories of the assignment
  (9 built-up, 7 undeveloped) and its legend colours; replaces the old simple mode
- Whole map coloured: RÚIAN cadastral parcels are fetched and classified from
  land type / land use; built-up parcels take the category of their building
- Field corrections per building or parcel (info panel), saved locally and in a
  project file (save/open JSON) to move between devices
- A4 frame at 1 : 3 780 (300 dpi, landscape/portrait) shown on the map; data
  loading covers the frame
- Built-up territory meter against the 66 % rule (built-up areas + gardens +
  maintained greenery; strict legend share shown too) and area statistics
  per category with CSV export
- Submission print/PDF: 1 map (title, author, scale, source), 2 legend (only
  categories present), 3-4 commentary
- Commentary editor with the assignment's questions and a 3 600-character counter
- Field worksheet: blank A4 base map with house numbers and an empty legend
  to colour with crayons
- Buildings CSV gains HG3 category, correction flag and parcels

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 12:48:42 +01:00

106 lines
3.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useEffect } from 'preact/hooks'
import { HG, hgColor, type HgCat } from '../categories'
import { lang, t, tKey } from '../i18n'
import { mapBoxMM } from '../page'
import { commentary, mapAuthor, mapTitle, orientation, printJob } from '../state'
import { frameStats } from '../stats'
/** Short legend label: "Ostatní plochy" under its group heading, like the assignment's legend. */
const legendLabel = (k: string) => {
const s = tKey('hgs.' + k)
return s.startsWith('hgs.') ? tKey('hg.' + k) : s
}
/**
* Pages for printing / "Save as PDF", shown only while a print job is prepared.
* Submission: 1 map, 2 legend, 3–4 commentary. Worksheet: blank map and a legend to colour in.
*/
export function PrintView() {
const job = printJob.value
useEffect(() => {
const done = () => {
const j = printJob.value
if (!j) return
URL.revokeObjectURL(j.mapUrl)
printJob.value = null
}
window.addEventListener('afterprint', done)
return () => window.removeEventListener('afterprint', done)
}, [])
useEffect(() => {
document.documentElement.classList.toggle('printing', !!job)
}, [job])
if (!job) return null
const ws = job.kind === 'worksheet',
o = orientation.value,
[wmm, hmm] = mapBoxMM(o)
const title = mapTitle.value.trim() || t('title'),
author = mapAuthor.value.trim()
const date = new Date().toLocaleDateString(lang.value, {
day: 'numeric',
month: 'long',
year: 'numeric',
})
const st = frameStats.value
// the legend lists only categories that occur in the frame (the worksheet lists all 16)
const present = (c: HgCat) => ws || !st || (st.area[c.key] ?? 0) > 0
const group = (built: boolean) => HG.filter((c) => c.built === built && present(c))
return (
<div class="print-root">
<section class={`pg pg-map ${o}`}>
<header class="pg-head">
<b>{ws ? `${t('worksheetTitle')} – ${title}` : title}</b>
<span>{author}</span>
</header>
<img src={job.mapUrl} alt="" style={{ width: `${wmm}mm`, height: `${hmm}mm` }} />
<footer class="pg-foot">
<span>{t('scaleText')}</span>
<span>{t('source')}</span>
<span>{date}</span>
</footer>
</section>
<section class="pg pg-legend">
<h1>{ws ? t('worksheetLegend') : t('legendTitle')}</h1>
{[true, false].map((built) => {
const cats = group(built)
if (!cats.length) return null
return (
<div class="pg-group" key={String(built)}>
<h2>{t(built ? 'g_built' : 'g_open')}</h2>
{cats.map((c) => {
const desc = tKey('hgd.' + c.key)
return (
<div class="pg-leg" key={c.key}>
<span
class={ws ? 'pg-sw empty' : 'pg-sw'}
style={ws ? undefined : { background: hgColor(c.key) }}
/>
<span>
{legendLabel(c.key)}
{!desc.startsWith('hgd.') && <small> ({desc})</small>}
</span>
{ws && <span class="pg-crayon">{t('crayonNo')}: ______</span>}
</div>
)
})}
</div>
)
})}
<p class="pg-note">
{title}
{author ? ` · ${author}` : ''} · {t('scaleText')} · {t('source')}
</p>
</section>
{!ws && (
<section class="pg pg-text">
<h1>{t('commentaryTitle')}</h1>
<div class="pg-body">{commentary.value}</div>
</section>
)}
</div>
)
}