제주 드론 도로영상 지원: DJI 로그 어댑터·분할영상 연속재생·카메라 자동감지·오버레이 개선
- 제주 DJI 시간기반 비행로그(CSV) 파싱 어댑터: 세그먼트 창 정렬, 가상 fps 환산 - 분할 영상(이름 오름차순) 연속재생 + 좌상단 영상목록 콤보(선택 재생), 세그먼트별 드론 로그 재정렬 - KML 다중 파일 병합 파싱: STA 체이니지 측점(71개) + 지장물 신포맷(타입/이름/텍스트박스_색상) - 시설물 라벨: 지정색 배경 박스 + 흰 글자, 팝업 중앙 정렬, 호버 구간 깜빡임 수정 - 카메라 자동감지(djmd: ZenmuseP1, focal 29.9mm) + <영상명>.camera.json PC 저장/폴더 자동 적용 - Yaw 자동추정(GPS 진행방위 기반) + 라벨 드래그 Yaw 역산 모드 - 스테이션바: GPS 이동거리 진행도(호버 시 정지), 노선밖 거리 표기, 원거리 구조물 마크 제외 - 서버: /api/camera 라우트, ecosystem 포트 54000·제주 데이터 경로 - docs/history: 작업 이력 21건 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+315
-39
@@ -33,6 +33,7 @@ import type {
|
||||
PoiOverrideMap,
|
||||
} from '../types/geo';
|
||||
import { stationOrder, getWorldOrigin } from './geoSearch';
|
||||
import { detectCameraInfo } from './cameraMeta';
|
||||
import { unzipSync, strFromU8 } from 'fflate';
|
||||
|
||||
// ── CSV 파싱 헬퍼 ─────────────────────────────────────────────────────
|
||||
@@ -120,11 +121,33 @@ function findBuildingFile(files: File[], keyword: string): File | null {
|
||||
|
||||
const VIDEO_EXT = /\.(mp4|webm)$/i;
|
||||
|
||||
/** 영상 파일 찾기 (mp4/webm, building 제외). */
|
||||
/** 폴더 내 모든 영상 파일 (이름순 정렬 — DJI 분할본 _0002, _0003… 순서 보장). */
|
||||
export function findVideoFiles(files: File[]): File[] {
|
||||
return files
|
||||
.filter((f) => !isInBuilding(f) && VIDEO_EXT.test(baseNameOf(relPath(f))))
|
||||
.sort((a, b) => baseNameOf(relPath(a)).localeCompare(baseNameOf(relPath(b))));
|
||||
}
|
||||
|
||||
/** 영상 파일 찾기 (mp4/webm, building 제외). 여러 개면 이름순 첫 번째. */
|
||||
export function findVideoFile(files: File[]): File | null {
|
||||
return (
|
||||
files.find((f) => !isInBuilding(f) && VIDEO_EXT.test(baseNameOf(relPath(f)))) ?? null
|
||||
);
|
||||
return findVideoFiles(files)[0] ?? null;
|
||||
}
|
||||
|
||||
/** 영상 File 의 재생 길이(초) — 메타데이터만 읽는다(전체 로드 없음). 실패 시 null. */
|
||||
export function probeVideoDuration(file: File): Promise<number | null> {
|
||||
return new Promise((resolve) => {
|
||||
const url = URL.createObjectURL(file);
|
||||
const v = document.createElement('video');
|
||||
v.preload = 'metadata';
|
||||
const done = (d: number | null): void => {
|
||||
URL.revokeObjectURL(url);
|
||||
v.removeAttribute('src');
|
||||
resolve(d);
|
||||
};
|
||||
v.onloadedmetadata = () => done(isFinite(v.duration) ? v.duration : null);
|
||||
v.onerror = () => done(null);
|
||||
v.src = url;
|
||||
});
|
||||
}
|
||||
|
||||
/** 영상 파일명에서 base(확장자 제거) 추출. */
|
||||
@@ -133,17 +156,44 @@ export function deriveBaseName(videoFile: File | null): string | null {
|
||||
return baseNameOf(relPath(videoFile)).replace(VIDEO_EXT, '');
|
||||
}
|
||||
|
||||
// ── 파서: 드론 프레임 (변경 없음) ─────────────────────────────────────
|
||||
// ── 파서: 드론 프레임 ─────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 드론 프레임 CSV 파싱 (UTF-8 BOM, 헤더 이름 인덱스).
|
||||
* 헤더: frame_cnt,latitude,longitude,altitude,yaw,pitch,roll,focal_len
|
||||
* DJI 비행로그(시간 기반) → 프레임 환산용 가상 fps.
|
||||
* frame = 영상 상대시간(초) × 이 값. 소비측(effectiveFps = maxFrame ÷ 영상길이)이
|
||||
* 같은 값을 역산해 시간으로 되돌리므로 상수 자체는 임의여도 정합이 유지된다.
|
||||
* 59.94 는 이 데이터셋(DJI 4K60) 실제 fps 와 일치시켜 HUD 표기도 자연스럽게 한 것.
|
||||
*/
|
||||
const DJI_VIRTUAL_FPS = 59.94;
|
||||
|
||||
/** 영상 세그먼트 창 — DJI 시간 기반 로그를 특정 영상 구간에 정렬할 때 사용. */
|
||||
export interface SegmentWindow {
|
||||
/** 전체 녹화 기준 이 영상의 시작 오프셋(초). 첫 세그먼트는 0. */
|
||||
offsetSec: number;
|
||||
/** 이 영상의 길이(초). 미상(null)이면 클리핑 없이 전체 로그를 쓴다. */
|
||||
durationSec: number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 드론 프레임 CSV 파싱 (UTF-8 BOM, 헤더 이름 인덱스). 두 형식 지원:
|
||||
*
|
||||
* ① 프레임 기반(회덕 v2.0): frame_cnt,latitude,longitude,altitude,yaw,pitch,roll,focal_len
|
||||
* ② 시간 기반(DJI 비행로그, 제주): time(millisecond),latitude,longitude,…,
|
||||
* altitude_above_seaLevel/compass_heading/gimbal_heading(degrees) 등.
|
||||
* - 첫 행 time = 녹화 시작으로 보고(로그 폭 ≈ 분할영상 총길이 검증됨),
|
||||
* frame = ((time−t0)/1000 − offsetSec) × DJI_VIRTUAL_FPS 로 환산.
|
||||
* - 자세는 카메라 방향인 gimbal_* 우선, 없으면 기체 compass/pitch/roll 폴백.
|
||||
* - focal_len 이 없어 35mm 환산 24mm(DJI 광각 기본)로 둔다 → 카메라 파라미터 UI로 보정.
|
||||
* - segmentWindow.durationSec 가 있으면 해당 영상 구간 밖 행을 버린다
|
||||
* (분할 영상에서 effectiveFps 자기보정이 성립하려면 필수).
|
||||
*
|
||||
* 루트(building 제외)의 <base>.csv 를 식별한다. base 가 없으면 루트 .csv 중
|
||||
* POI 가 아닌 첫 파일을 사용한다(영상명 비의존 폴백).
|
||||
*/
|
||||
export async function parseDroneFrames(
|
||||
files: File[],
|
||||
baseName: string | null,
|
||||
segmentWindow: SegmentWindow | null = null,
|
||||
): Promise<DroneFrame[]> {
|
||||
const rootCsv = files.filter((f) => {
|
||||
if (isInBuilding(f)) return false;
|
||||
@@ -164,6 +214,51 @@ export async function parseDroneFrames(
|
||||
|
||||
const fi = makeFieldIndexer(rows[0]);
|
||||
|
||||
// ② 시간 기반(DJI 비행로그) — time(millisecond) 헤더로 감지.
|
||||
const iTime = fi('time(millisecond)');
|
||||
if (iTime >= 0) {
|
||||
const iLat = fi('latitude');
|
||||
const iLon = fi('longitude');
|
||||
const iAlt = fi('altitude_above_seaLevel(meter)');
|
||||
const iYaw = fi('gimbal_heading(degrees)') >= 0 ? fi('gimbal_heading(degrees)') : fi('compass_heading(degrees)');
|
||||
const iPitch = fi('gimbal_pitch(degrees)') >= 0 ? fi('gimbal_pitch(degrees)') : fi('pitch(degrees)');
|
||||
const iRoll = fi('gimbal_roll(degrees)') >= 0 ? fi('gimbal_roll(degrees)') : fi('roll(degrees)');
|
||||
|
||||
const raw = rows
|
||||
.slice(1)
|
||||
.map((r) => ({
|
||||
timeMs: parseFloat(cell(r, iTime)),
|
||||
lat: parseFloat(cell(r, iLat)),
|
||||
lon: parseFloat(cell(r, iLon)),
|
||||
altitude: parseFloat(cell(r, iAlt)),
|
||||
yaw: parseFloat(cell(r, iYaw)),
|
||||
pitch: parseFloat(cell(r, iPitch)),
|
||||
roll: parseFloat(cell(r, iRoll)) || 0,
|
||||
focalLen: 24,
|
||||
}))
|
||||
.filter((f) => !isNaN(f.lat) && !isNaN(f.timeMs));
|
||||
if (!raw.length) return [];
|
||||
|
||||
const t0 = raw[0].timeMs;
|
||||
const offsetSec = segmentWindow?.offsetSec ?? 0;
|
||||
const durationSec = segmentWindow?.durationSec ?? null;
|
||||
const maxFrame = durationSec != null ? durationSec * DJI_VIRTUAL_FPS : Infinity;
|
||||
|
||||
const frames = raw
|
||||
.map(({ timeMs, ...rest }) => ({
|
||||
...rest,
|
||||
frame: Math.round(((timeMs - t0) / 1000 - offsetSec) * DJI_VIRTUAL_FPS),
|
||||
}))
|
||||
.filter((f) => f.frame >= 0 && f.frame <= maxFrame);
|
||||
|
||||
console.log(
|
||||
`[geo] DJI 시간기반 로그: ${raw.length}행 중 ${frames.length}행 사용 ` +
|
||||
`(구간 ${offsetSec.toFixed(1)}s~${durationSec != null ? (offsetSec + durationSec).toFixed(1) : '끝'}s, 가상fps ${DJI_VIRTUAL_FPS})`,
|
||||
);
|
||||
return frames;
|
||||
}
|
||||
|
||||
// ① 프레임 기반(회덕 v2.0)
|
||||
return rows
|
||||
.slice(1)
|
||||
.map((r) => ({
|
||||
@@ -290,48 +385,91 @@ function childLocal(el: Element, local: string): Element | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** KMZ/KML 파싱 — 있으면 { pois, structures }, 없거나 실패 시 null.
|
||||
* bare .kml(구글 직접 다운로드) 우선, 없으면 .kmz(zip) 해제. */
|
||||
/** 한국어 색상명 → CSS 색 (KML 텍스트박스_색상 속성). 어두운 색은 렌더 시 밝은 외곽선 처리. */
|
||||
const KOR_LABEL_COLORS: Record<string, string> = {
|
||||
검정: '#1f2937', 흰색: '#ffffff', 회색: '#9ca3af',
|
||||
빨강: '#ef4444', 주황: '#fb923c', 노랑: '#facc15',
|
||||
연두: '#a3e635', 초록: '#22c55e', 하늘: '#38bdf8',
|
||||
파랑: '#3b82f6', 남색: '#3730a3', 보라: '#a855f7', 분홍: '#f472b6',
|
||||
};
|
||||
|
||||
function koreanColorToCss(v?: string): string | undefined {
|
||||
if (!v) return undefined;
|
||||
const key = v.trim();
|
||||
if (KOR_LABEL_COLORS[key]) return KOR_LABEL_COLORS[key];
|
||||
for (const k in KOR_LABEL_COLORS) if (key.includes(k)) return KOR_LABEL_COLORS[k];
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Placemark 인라인 IconStyle 색 — KML aabbggrr → CSS #rrggbb. */
|
||||
function inlineIconColor(pm: Element): string | undefined {
|
||||
const icon = pm.getElementsByTagName('IconStyle')[0];
|
||||
const c = icon?.getElementsByTagName('color')[0]?.textContent?.trim();
|
||||
if (!c || !/^[0-9a-fA-F]{8}$/.test(c)) return undefined;
|
||||
const bb = c.slice(2, 4), gg = c.slice(4, 6), rr = c.slice(6, 8);
|
||||
return `#${rr}${gg}${bb}`.toLowerCase();
|
||||
}
|
||||
|
||||
/** KMZ/KML 파싱 — 있으면 { pois, structures, stations }, 없거나 실패 시 null.
|
||||
* bare .kml(구글 직접 다운로드) 우선, 없으면 .kmz(zip) 해제.
|
||||
*
|
||||
* 속성 소스 2종을 모두 props 로 수집한다:
|
||||
* - description CDATA HTML 표 (구글어스/지오코딩 산출물 — 회덕 v2.0)
|
||||
* - ExtendedData/SchemaData/SimpleData (CAD·GIS 내보내기 — 제주 도로 KML)
|
||||
*
|
||||
* 측점(STA): 이름이 도로 체이니지(`6+998`) 형식이거나 STA 속성이 있는 Point 는
|
||||
* POI 가 아니라 측점(type='station')으로 수집한다. km 속성(단위 km) 우선, 없으면
|
||||
* 이름에서 미터값을 파싱해 기존 철도식 제목(`6k998`)으로 변환 — stationOrder/stationKm
|
||||
* 등 측점 파이프라인(스테이션바·노선패널·검색)과 그대로 호환된다. */
|
||||
export async function parseKmz(
|
||||
files: File[],
|
||||
): Promise<{ pois: GeoPoint[]; structures: RouteStructure[] } | null> {
|
||||
const kmlFile = files.find(
|
||||
): Promise<{ pois: GeoPoint[]; structures: RouteStructure[]; stations: GeoPoint[] } | null> {
|
||||
// 폴더 내 모든 KML/KMZ 를 파싱해 병합한다 (예: 제주 — 측점 KML + 지장물 KML 별도 파일).
|
||||
const kmlFiles = files.filter(
|
||||
(f) => !isInBuilding(f) && /\.kml$/i.test(baseNameOf(relPath(f))),
|
||||
);
|
||||
const kmzFile = files.find(
|
||||
const kmzFiles = files.filter(
|
||||
(f) => !isInBuilding(f) && /\.kmz$/i.test(baseNameOf(relPath(f))),
|
||||
);
|
||||
if (!kmlFile && !kmzFile) return null;
|
||||
if (!kmlFiles.length && !kmzFiles.length) return null;
|
||||
|
||||
let kmlText: string;
|
||||
try {
|
||||
if (kmlFile) {
|
||||
kmlText = await kmlFile.text(); // 구글 KML 은 UTF-8
|
||||
} else {
|
||||
const buf = new Uint8Array(await kmzFile!.arrayBuffer());
|
||||
const kmlTexts: string[] = [];
|
||||
for (const kf of kmlFiles) {
|
||||
try {
|
||||
kmlTexts.push(await kf.text()); // 구글 KML 은 UTF-8
|
||||
} catch (e) {
|
||||
console.warn(`[KML] 읽기 실패: ${baseNameOf(relPath(kf))}`, e);
|
||||
}
|
||||
}
|
||||
for (const kf of kmzFiles) {
|
||||
try {
|
||||
const buf = new Uint8Array(await kf.arrayBuffer());
|
||||
const entries = unzipSync(buf);
|
||||
const kmlName =
|
||||
Object.keys(entries).find((n) => /(^|\/)doc\.kml$/i.test(n)) ??
|
||||
Object.keys(entries).find((n) => /\.kml$/i.test(n));
|
||||
if (!kmlName || !entries[kmlName]) return null;
|
||||
kmlText = strFromU8(entries[kmlName]);
|
||||
if (kmlName && entries[kmlName]) kmlTexts.push(strFromU8(entries[kmlName]));
|
||||
} catch (e) {
|
||||
console.warn(`[KMZ] 읽기 실패: ${baseNameOf(relPath(kf))}`, e);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[KMZ/KML] 읽기 실패 → CSV 폴백', e);
|
||||
return null;
|
||||
}
|
||||
|
||||
const doc = new DOMParser().parseFromString(kmlText, 'application/xml');
|
||||
if (doc.getElementsByTagName('parsererror').length) return null;
|
||||
if (!kmlTexts.length) return null;
|
||||
|
||||
const pois: GeoPoint[] = [];
|
||||
const structures: RouteStructure[] = [];
|
||||
const stations: GeoPoint[] = [];
|
||||
let nStruct = 0;
|
||||
|
||||
const handlePlacemark = (pm: Element, folder: string): void => {
|
||||
const name = childLocal(pm, 'name')?.textContent?.trim() ?? '';
|
||||
const desc = childLocal(pm, 'description')?.textContent ?? '';
|
||||
const props = parseKmlDescProps(desc);
|
||||
// ExtendedData/SchemaData/SimpleData 속성 (CAD·GIS 내보내기) — HTML 표 props 와 통합.
|
||||
for (const sd of Array.from(pm.getElementsByTagName('SimpleData'))) {
|
||||
const k = sd.getAttribute('name') ?? '';
|
||||
const v = sd.textContent?.trim() ?? '';
|
||||
if (k) props.push({ k, v });
|
||||
}
|
||||
const pget = (k: string): string | undefined => props.find((p) => p.k === k)?.v;
|
||||
|
||||
// 좌표: <coordinates> lon,lat[,alt] 우선, 없으면 속성 lat/lon.
|
||||
@@ -347,6 +485,32 @@ export async function parseKmz(
|
||||
}
|
||||
if (isNaN(lat) || isNaN(lon) || lat < 33 || lat > 39 || lon < 124 || lon > 132) return;
|
||||
|
||||
// 새 포맷: 구글어스 CSV 변환 지장물 KML — Schema(타입/타입상세/이름/연장/텍스트박스_색상/높이),
|
||||
// 폴더 구분 없이 Placemark 직속. '타입' 키 존재로 감지한다(회덕 desc표/STA 스키마엔 없음).
|
||||
// 좌표는 SimpleData X/Y(저정밀)가 아니라 Point coordinates(고정밀)를 쓴다(위에서 이미 추출).
|
||||
if (pget('타입') !== undefined) {
|
||||
const title = pget('이름') || name;
|
||||
if (!title) return;
|
||||
const category = pget('타입') || '지장물';
|
||||
const lenM = parseFloat(pget('연장') ?? '');
|
||||
// 라벨 색: 텍스트박스_색상(한국어명) 우선, 없으면 인라인 IconStyle 색.
|
||||
const labelColor = koreanColorToCss(pget('텍스트박스_색상')) ?? inlineIconColor(pm);
|
||||
// z: '높이'는 표고가 아니라 구조물 높이라 사용하지 않음(팝업 props 로만 노출).
|
||||
// 지면표고 미상(0) → 오버레이 기본(드론고도−이격) 모드 및 중심선 z 폴백으로 표시.
|
||||
pois.push({
|
||||
title, category, lat, lon, z: 0, type: 'poi',
|
||||
...(labelColor ? { labelColor } : {}),
|
||||
props,
|
||||
});
|
||||
// 교량/터널은 스테이션바·노선패널 마크용 구조물로도 등록.
|
||||
if (category.includes('교량')) {
|
||||
structures.push({ id: `교량-${nStruct++}`, type: 'bridge', category: '교량', name: title, lat, lon, ...(isFinite(lenM) ? { lengthM: lenM } : {}), props });
|
||||
} else if (category.includes('터널')) {
|
||||
structures.push({ id: `터널-${nStruct++}`, type: 'tunnel', category: '터널', name: title, lat, lon, ...(isFinite(lenM) ? { lengthM: lenM } : {}), props });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const lenNum = parseFloat(pget('연장(m)') ?? '');
|
||||
if (folder.includes('교량')) {
|
||||
structures.push({ id: `교량-${nStruct++}`, type: 'bridge', category: '교량', name: pget('구분') || name, lat, lon, ...(isNaN(lenNum) ? {} : { lengthM: lenNum }), ...(pget('시설종별') ? { grade: pget('시설종별') } : {}), props });
|
||||
@@ -358,6 +522,21 @@ export async function parseKmz(
|
||||
const title = pget('출입문번호') || name;
|
||||
if (title) pois.push({ title, category: '출입문', lat, lon, z: parseFloat(pget('z') ?? pget('절대고도') ?? '0') || 0, type: 'poi', props });
|
||||
} else {
|
||||
// 도로 체이니지 측점 (예: "0+100" 또는 STA 속성) → type='station' 으로 수집.
|
||||
// km 속성(단위 km) 우선, 없으면 이름의 "k+m" 파싱. 제목은 철도식 NkNNN 으로 변환.
|
||||
const staName = pget('STA') || name;
|
||||
const staMatch = staName.match(/^(\d+)\+(\d+)$/);
|
||||
if (staMatch || pget('STA') !== undefined) {
|
||||
const kmProp = parseFloat(pget('km') ?? '');
|
||||
const meters = isFinite(kmProp)
|
||||
? Math.round(kmProp * 1000)
|
||||
: staMatch ? parseInt(staMatch[1], 10) * 1000 + parseInt(staMatch[2], 10) : NaN;
|
||||
if (!isFinite(meters)) return;
|
||||
const title = `${Math.floor(meters / 1000)}k${String(meters % 1000).padStart(3, '0')}`;
|
||||
// z 미상(KML 고도 0) — 소비측(loadFolderGeoData)에서 드론 고도 기반으로 보정.
|
||||
stations.push({ title, category: '측점', lat, lon, z: 0, type: 'station', props });
|
||||
return;
|
||||
}
|
||||
// 02)지장물 등 = 지오코딩 POI. 모든 POI 는 영상에 표출(철도역 포함).
|
||||
if (!name) return;
|
||||
const src = pget('source');
|
||||
@@ -384,9 +563,52 @@ export async function parseKmz(
|
||||
}
|
||||
}
|
||||
};
|
||||
if (doc.documentElement) walk(doc.documentElement, '');
|
||||
for (const text of kmlTexts) {
|
||||
const doc = new DOMParser().parseFromString(text, 'application/xml');
|
||||
if (doc.getElementsByTagName('parsererror').length) {
|
||||
console.warn('[KML] XML 파싱 실패 — 해당 파일 건너뜀');
|
||||
continue;
|
||||
}
|
||||
if (doc.documentElement) walk(doc.documentElement, '');
|
||||
}
|
||||
|
||||
return { pois, structures };
|
||||
return { pois, structures, stations };
|
||||
}
|
||||
|
||||
// ── 카메라 파라미터 파일 (<base>.camera.json) ─────────────────────────
|
||||
|
||||
/**
|
||||
* 폴더에서 카메라 파라미터 파일을 읽는다. 서버 '카메라값 저장'(PUT /api/camera/:videoId)이
|
||||
* 영상 옆에 만든 `<영상 base>.camera.json`(또는 `<영상 base>.json`) 형식:
|
||||
* { "camera": { focalLen, sensorW, sensorH, yawOffset, pitch, roll, offX, offY, offZ, geoidOffset, cx0, cy0 }, ... }
|
||||
* 폴더 내 어떤 영상의 base 와도 매칭 허용(분할본 공용). 숫자 필드만 통과시킨다.
|
||||
*/
|
||||
export async function parseCameraJson(
|
||||
files: File[],
|
||||
videoFiles: File[],
|
||||
): Promise<Record<string, number> | null> {
|
||||
const bases = videoFiles.map((v) => baseNameOf(relPath(v)).replace(VIDEO_EXT, '').toLowerCase());
|
||||
const file = files.find((f) => {
|
||||
if (isInBuilding(f)) return false;
|
||||
const name = baseNameOf(relPath(f)).toLowerCase();
|
||||
const m = name.match(/^(.+?)(\.camera)?\.json$/);
|
||||
if (!m) return false;
|
||||
if (/\.route\.json$|_poi_overrides\.json$/.test(name)) return false;
|
||||
return bases.includes(m[1]);
|
||||
});
|
||||
if (!file) return null;
|
||||
try {
|
||||
const obj = JSON.parse(await file.text());
|
||||
const cam = obj && typeof obj === 'object' ? (obj.camera ?? obj) : null;
|
||||
if (!cam || typeof cam !== 'object') return null;
|
||||
const out: Record<string, number> = {};
|
||||
for (const [k, v] of Object.entries(cam)) {
|
||||
if (typeof v === 'number' && isFinite(v)) out[k] = v;
|
||||
}
|
||||
return Object.keys(out).length ? out : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ── route.json 보정 ───────────────────────────────────────────────────
|
||||
@@ -409,7 +631,9 @@ export async function parseRouteMeta(
|
||||
const file =
|
||||
(wantBase &&
|
||||
rootJson.find((f) => baseNameOf(relPath(f)).toLowerCase() === wantBase)) ||
|
||||
rootJson.find((f) => baseNameOf(relPath(f)).toLowerCase() === 'route.json');
|
||||
rootJson.find((f) => baseNameOf(relPath(f)).toLowerCase() === 'route.json') ||
|
||||
// 임의 접두 `<이름>.route.json` 허용 (예: 제주 중산간도로 경로 1-1.route.json)
|
||||
rootJson.find((f) => /\.route\.json$/i.test(baseNameOf(relPath(f))));
|
||||
if (!file) return null;
|
||||
|
||||
try {
|
||||
@@ -533,33 +757,80 @@ export async function loadFolderGeoData(
|
||||
): Promise<FolderGeoData> {
|
||||
const files = Array.from(input);
|
||||
|
||||
const videoFile = findVideoFile(files);
|
||||
const videoFiles = findVideoFiles(files);
|
||||
const videoFile = videoFiles[0] ?? null;
|
||||
const baseName = deriveBaseName(videoFile);
|
||||
|
||||
const [frames, stationResult, routeMeta, poiOverrides, kmz] = await Promise.all([
|
||||
parseDroneFrames(files, baseName),
|
||||
// 각 영상 길이를 메타데이터로 측정 — DJI 시간 기반 로그의 세그먼트 정렬(누적 오프셋)과
|
||||
// ended 연속재생(geoStore.loadSegment)에 쓴다. 분할본이 아니면 1개만 측정.
|
||||
const videoDurations: (number | null)[] = [];
|
||||
for (const vf of videoFiles) videoDurations.push(await probeVideoDuration(vf));
|
||||
|
||||
// 첫 세그먼트 창 — 로그는 전체 녹화(분할본 합)를 커버하므로 첫 영상 구간만 잘라 쓴다.
|
||||
const segmentWindow: SegmentWindow | null = videoFile
|
||||
? { offsetSec: 0, durationSec: videoDurations[0] }
|
||||
: null;
|
||||
if (videoFiles.length > 1) {
|
||||
console.log(
|
||||
`[geo] 분할 영상 ${videoFiles.length}개 감지 (이름 오름차순 연속재생): ` +
|
||||
videoFiles.map((vf, i) => `${baseNameOf(relPath(vf))}(${videoDurations[i]?.toFixed(1) ?? '?'}s)`).join(' → '),
|
||||
);
|
||||
}
|
||||
|
||||
const [frames, stationResult, routeMeta, poiOverrides, kmz, cameraInfo, cameraJson] = await Promise.all([
|
||||
parseDroneFrames(files, baseName, segmentWindow),
|
||||
parseStations(files),
|
||||
parseRouteMeta(files, baseName),
|
||||
parsePoiOverrides(files, baseName),
|
||||
parseKmz(files),
|
||||
videoFile ? detectCameraInfo(videoFile) : Promise.resolve(null),
|
||||
parseCameraJson(files, videoFiles),
|
||||
]);
|
||||
|
||||
if (cameraJson) {
|
||||
console.log('[camera] <base>.camera.json 발견 — 저장된 카메라 파라미터 적용:', cameraJson);
|
||||
}
|
||||
|
||||
// 감지된 초점거리를 드론 프레임 focalLen 에도 반영 (검색/투영 FOV 판정 일관성).
|
||||
if (cameraInfo?.focalLen35) {
|
||||
for (const f of frames) f.focalLen = cameraInfo.focalLen35;
|
||||
console.log(
|
||||
`[camera] ${cameraInfo.model} 감지 — focal ${cameraInfo.focalLen35}mm` +
|
||||
(cameraInfo.width ? `, ${cameraInfo.width}x${cameraInfo.height}@${cameraInfo.fps ?? '?'}fps` : ''),
|
||||
);
|
||||
} else if (cameraInfo) {
|
||||
console.log(`[camera] ${cameraInfo.model} 감지 (초점거리 정보 없음)`);
|
||||
}
|
||||
|
||||
// POI/구조물 출처: KMZ(원본)가 유일한 소스다(지장물·출입문·교량/터널/구교·철도역).
|
||||
// KMZ 정책상 필수 — 없거나 비어 있으면 "데이터 누락"으로 보고 경고만 남기고 빈 상태로 둔다
|
||||
// (CSV 폴백 없음. building/ POI·구조물 CSV는 사용하지 않음). 측점·중심선은 항상 CSV(측점)에서 온다.
|
||||
const kmzMissing = !kmz || (kmz.pois.length === 0 && kmz.structures.length === 0);
|
||||
// KMZ 파일 자체가 없을 때만 "데이터 누락"(kmzMissing=alert 대상)으로 본다.
|
||||
// 파일은 있는데 POI/구조물이 0건인 경우(예: 제주 — 노선 KML만 있고 POI 없음)는
|
||||
// 정상 데이터셋으로 취급하고 콘솔 경고만 남긴다.
|
||||
const kmzMissing = !kmz;
|
||||
if (kmzMissing) {
|
||||
console.warn(
|
||||
'[KMZ] 누락/비어있음 — POI·구조물이 표시되지 않습니다. ' +
|
||||
'[KMZ] 누락 — POI·구조물이 표시되지 않습니다. ' +
|
||||
'KMZ(원본)를 포함해 데이터를 재구축·전달하세요. (측점·드론 정보는 정상 로드)',
|
||||
);
|
||||
} else if (kmz!.pois.length === 0 && kmz!.structures.length === 0 && kmz!.stations.length === 0) {
|
||||
console.warn('[KMZ] POI·구조물·측점 0건 — 이 데이터셋엔 표출할 지물이 없습니다(드론 궤적은 무관).');
|
||||
} else {
|
||||
console.log(`[KMZ] POI ${kmz!.pois.length} · 구조물 ${kmz!.structures.length} 로드(원본)`);
|
||||
console.log(`[KMZ] POI ${kmz!.pois.length} · 구조물 ${kmz!.structures.length} · 측점 ${kmz!.stations.length} 로드(원본)`);
|
||||
}
|
||||
const pois = kmz?.pois ?? [];
|
||||
const baseStructures = kmz?.structures ?? [];
|
||||
|
||||
const stations = stationResult.stations.sort(
|
||||
// 측점 소스: CSV(01)측점 — 실측 표고 보유) 우선, 없으면 KML 체이니지 측점(STA) 사용.
|
||||
// KML 측점은 표고 미상 → z=0 그대로 둔다(미상 표식). 드론고도 기반 근사(−24m)는
|
||||
// 실제 지면과 수십 m 어긋나 라벨이 공중에 떠서 시차 불일치(카메라 전진 시 라벨 밀림)를
|
||||
// 유발했음 → 오버레이가 z=0 라벨을 '경로 표고' 평면에 앵커하는 방식으로 대체.
|
||||
let rawStations = stationResult.stations;
|
||||
if (!rawStations.length && kmz?.stations.length) {
|
||||
rawStations = kmz.stations;
|
||||
console.log(`[KMZ] 체이니지 측점 ${rawStations.length}개 로드 (표고 미상 → 오버레이 '경로 표고' 평면 앵커)`);
|
||||
}
|
||||
|
||||
const stations = rawStations.sort(
|
||||
(a, b) => stationOrder(a.title) - stationOrder(b.title),
|
||||
);
|
||||
const directionChanges = stationResult.directionChanges;
|
||||
@@ -591,5 +862,10 @@ export async function loadFolderGeoData(
|
||||
directionChanges,
|
||||
poiOverrides,
|
||||
kmzMissing,
|
||||
videoFiles,
|
||||
videoDurations,
|
||||
folderFiles: files,
|
||||
cameraInfo,
|
||||
cameraJson,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user