/* ============================================================================= * map_terrain_chip.ts * 공용 지도 지형 칩(PLAN 624-2 · 요구 530 · 결정 A④ · A⑤ · D2) — 도구줄 끝 분할 고르기 하나: 수치지형도 · 라이다. * 마우스 글 = 도구줄 표 호버제목(「수치지형도/라이다」 · 634-2) · 확인창은 B05 몫. * 없는 원천 = 막힘 + 「제목 — 까닭」(D03 라이다 = D 프로젝트에 LAS 올린 뒤 · 624-4). * 화면 칩만 — 바꾸는 일(서버 원천 인자 624-1 · B05 설계 지형 바꿈 626-1)은 `onChange` 로 페이지가 붙임. * 쓰는 법 = `createTerrainChip({ page: "d03", value: "sheet", have: ["sheet"] })` → `{ root, set, setHave }` · root 를 도구줄 `terrain` 칸에. * ========================================================================== */ import { createSegment } from "@ui/ui_template_segment"; import type { MapPage } from "./map_layer_list"; import { mapToolTitle } from "./map_toolbar"; /** 서버 겹 길 `terrain=` 값과 같음(624-1 · 빈 값 = 설계 지형). */ export type TerrainSource = "sheet" | "lidar"; export const TERRAIN_NAMES: Record = { sheet: "수치지형도", lidar: "라이다", }; /** 막힘 까닭(마우스 글 = 「수치지형도/라이다 — 까닭」 · 요구 546). */ const MISSING: Record = { sheet: "이 프로젝트 범위에 도엽 지형 없음", lidar: "올린 LAS 없음", }; const TITLE = mapToolTitle("terrain"); export interface TerrainChip { root: HTMLElement; /** 고름을 바꿈(onChange 는 안 부름). */ set: (value: TerrainSource) => void; /** 고를 수 있는 원천 — 없는 것은 막힘. */ setHave: (have: readonly TerrainSource[]) => void; } export function createTerrainChip(opts: { page: MapPage; value: TerrainSource; have: readonly TerrainSource[]; onChange?: (value: TerrainSource) => void; }): TerrainChip { const sources = Object.keys(TERRAIN_NAMES) as TerrainSource[]; const segment = createSegment({ options: sources.map((value) => ({ value, label: TERRAIN_NAMES[value] })), value: opts.value, size: 32, ariaLabel: TITLE, onChange: (value) => opts.onChange?.(value as TerrainSource), }); const root = segment.root; root.dataset.act = "terrain"; root.title = TITLE; const setHave = (have: readonly TerrainSource[]): void => { for (const value of sources) { const item = root.querySelector(`[data-value="${value}"]`)!; item.disabled = !have.includes(value); // 열림 = 글 없음(칩 글 「수치지형도/라이다」 그대로) · 막힘 = 「제목 — 까닭」 if (item.disabled) item.title = `${TITLE} — ${TERRAIN_NAMES[value]} ${MISSING[value]}`; else item.removeAttribute("title"); } }; setHave(opts.have); return { root, set: (value) => segment.set(value), setHave }; }