/* ============================================================================= * map_legend.ts * 공용 지도 범례(PLAN 569-2 · 622-2 · 624-2 · 요구 530) — 켠 겹 범례 칸 하나(줄마다 `createLegend`) + 페이지가 붙이는 덧 줄. * 조각 겹 범례(산사태위험 · 국유림 임도 · 경제림 · 생태자연도) = 받을 자료 없음 → 켬끔만 보고 여기서 만듦(`tileLegendRows`). * 받은 자료 범례(수 · 넓이 · 급경사 범위)는 받는 페이지 몫 — 줄을 만들어 `show` 에 넘김. * 쓰는 법 = `const legend = createMapLegend("d03-plan__legend")` → `legend.show(rows, [덧 줄])` · 줄 · 덧 없으면 숨김. * ========================================================================== */ import { createLegend, type LegendItem } from "@ui/ui_template_flow_legend"; import { forestLegendRows } from "./map_forest_layers"; import { LANDSLIDE_LEGEND, type MapLayerKey } from "./map_layer_list"; export interface MapLegend { root: HTMLElement; show: (rows: LegendItem[][], tail?: HTMLElement[]) => void; } /** 켠 조각 겹 범례 — 산사태위험 다음 산림 셋. */ export const tileLegendRows = (on: Record): LegendItem[][] => [ ...(on.landslide ? [LANDSLIDE_LEGEND] : []), ...forestLegendRows(on), ]; /** `className` = 자리 · 꼴(페이지 CSS). */ export function createMapLegend(className: string): MapLegend { const root = document.createElement("div"); root.className = className; root.title = "켠 겹 범례 — 받은 지형 범위 안 수 · 넓이"; return { root, show(rows, tail = []) { root.replaceChildren(...rows.map((row) => createLegend(row)), ...tail); root.hidden = !rows.length && !tail.length; }, }; }