kcg-monitoring/frontend/src/components/SatelliteLayer.tsx
htlee 2534faa488 feat: 프론트엔드 모노레포 이관 + signal-batch 연동 + Tailwind/i18n/테마 전환
- frontend/ 폴더로 프론트엔드 전체 이관
- signal-batch API 연동 (한국 선박 위치 데이터)
- Tailwind CSS 4 + CSS 변수 테마 토큰 (dark/light)
- i18next 다국어 (ko/en) 인프라 + 28개 컴포넌트 적용
- 레이어 패널 트리 구조 재설계 (카테고리별 온/오프, 범례)
- Google OAuth 로그인 화면 + DEV LOGIN 우회
- 외부 API CORS 프록시 전환 (Airplanes.live, OpenSky, CelesTrak)
- ShipLayer 이미지 탭 전환 (signal-batch / MarineTraffic)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 13:54:41 +09:00

184 lines
6.7 KiB
TypeScript

import { memo, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Marker, Popup, Source, Layer } from 'react-map-gl/maplibre';
import type { SatellitePosition } from '../types';
interface Props {
satellites: SatellitePosition[];
}
const CAT_COLORS: Record<SatellitePosition['category'], string> = {
reconnaissance: '#ef4444',
communications: '#3b82f6',
navigation: '#22c55e',
weather: '#a855f7',
other: '#6b7280',
};
const CAT_LABELS: Record<SatellitePosition['category'], string> = {
reconnaissance: 'RECON', communications: 'COMMS',
navigation: 'NAV', weather: 'WX', other: 'SAT',
};
const SVG_RECON = (
<>
<rect x={8} y={6} width={8} height={12} rx={1.5} fill="currentColor" opacity={0.9} />
<rect x={1} y={8} width={6} height={3} rx={0.5} fill="currentColor" opacity={0.7} />
<rect x={17} y={8} width={6} height={3} rx={0.5} fill="currentColor" opacity={0.7} />
<circle cx={12} cy={16} r={1.8} fill="none" stroke="currentColor" strokeWidth={1} opacity={0.6} />
<circle cx={12} cy={16} r={0.6} fill="currentColor" opacity={0.6} />
</>
);
const SVG_COMMS = (
<>
<rect x={9} y={7} width={6} height={10} rx={1} fill="currentColor" opacity={0.9} />
<rect x={1} y={9} width={7} height={2.5} rx={0.5} fill="currentColor" opacity={0.7} />
<rect x={16} y={9} width={7} height={2.5} rx={0.5} fill="currentColor" opacity={0.7} />
<path d="M10 4 Q12 2 14 4" fill="none" stroke="currentColor" strokeWidth={1.2} opacity={0.8} />
<line x1={12} y1={4} x2={12} y2={7} stroke="currentColor" strokeWidth={0.8} />
</>
);
const SVG_NAV = (
<>
<rect x={9} y={6} width={6} height={12} rx={1} fill="currentColor" opacity={0.9} />
<rect x={2} y={8} width={6} height={2.5} rx={0.5} fill="currentColor" opacity={0.7} />
<rect x={16} y={8} width={6} height={2.5} rx={0.5} fill="currentColor" opacity={0.7} />
<line x1={12} y1={3} x2={12} y2={6} stroke="currentColor" strokeWidth={1} />
<circle cx={12} cy={2.5} r={1} fill="currentColor" opacity={0.7} />
</>
);
const SVG_WEATHER = (
<>
<rect x={8} y={7} width={8} height={10} rx={1.5} fill="currentColor" opacity={0.9} />
<rect x={1} y={9} width={6} height={2.5} rx={0.5} fill="currentColor" opacity={0.7} />
<rect x={17} y={9} width={6} height={2.5} rx={0.5} fill="currentColor" opacity={0.7} />
<circle cx={12} cy={12} r={2.5} fill="none" stroke="currentColor" strokeWidth={0.8} opacity={0.5} />
</>
);
const SVG_OTHER = (
<>
<rect x={9} y={7} width={6} height={10} rx={1} fill="currentColor" opacity={0.9} />
<rect x={2} y={9} width={6} height={2.5} rx={0.5} fill="currentColor" opacity={0.7} />
<rect x={16} y={9} width={6} height={2.5} rx={0.5} fill="currentColor" opacity={0.7} />
</>
);
const SVG_MAP: Record<SatellitePosition['category'], React.ReactNode> = {
reconnaissance: SVG_RECON, communications: SVG_COMMS,
navigation: SVG_NAV, weather: SVG_WEATHER, other: SVG_OTHER,
};
export function SatelliteLayer({ satellites }: Props) {
const trackData = useMemo(() => {
const features: GeoJSON.Feature[] = [];
for (const sat of satellites) {
if (!sat.groundTrack || sat.groundTrack.length < 2) continue;
const color = CAT_COLORS[sat.category];
let segment: [number, number][] = [];
for (let i = 0; i < sat.groundTrack.length; i++) {
const [lat, lng] = sat.groundTrack[i];
if (i > 0) {
const [, prevLng] = sat.groundTrack[i - 1];
if (Math.abs(lng - prevLng) > 180) {
if (segment.length > 1) {
features.push({
type: 'Feature',
properties: { color },
geometry: { type: 'LineString', coordinates: segment.map(([la, lo]) => [lo, la]) },
});
}
segment = [];
}
}
segment.push([lat, lng]);
}
if (segment.length > 1) {
features.push({
type: 'Feature',
properties: { color },
geometry: { type: 'LineString', coordinates: segment.map(([la, lo]) => [lo, la]) },
});
}
}
return { type: 'FeatureCollection' as const, features };
}, [satellites]);
return (
<>
{trackData.features.length > 0 && (
<Source id="satellite-tracks" type="geojson" data={trackData}>
<Layer
id="satellite-track-lines"
type="line"
paint={{
'line-color': ['get', 'color'],
'line-width': 1,
'line-opacity': 0.25,
'line-dasharray': [6, 4],
}}
/>
</Source>
)}
{satellites.map(sat => (
<SatelliteMarker key={sat.noradId} sat={sat} />
))}
</>
);
}
const SatelliteMarker = memo(function SatelliteMarker({ sat }: { sat: SatellitePosition }) {
const [showPopup, setShowPopup] = useState(false);
const { t } = useTranslation();
const color = CAT_COLORS[sat.category];
const svgBody = SVG_MAP[sat.category];
const size = 22;
return (
<>
<Marker longitude={sat.lng} latitude={sat.lat} anchor="center">
<div className="relative">
<div
style={{ color }} className="size-[22px] cursor-pointer"
onClick={(e) => { e.stopPropagation(); setShowPopup(true); }}
>
<svg viewBox="0 0 24 24" width={size} height={size} style={{ color }}>
{svgBody}
</svg>
</div>
<div className="gl-marker-label" style={{ color, fontSize: 10 }}>
{sat.name}
</div>
</div>
</Marker>
{showPopup && (
<Popup longitude={sat.lng} latitude={sat.lat}
onClose={() => setShowPopup(false)} closeOnClick={false}
anchor="bottom" maxWidth="200px" className="gl-popup">
<div className="min-w-[180px] font-mono text-xs">
<div className="mb-1.5 flex items-center gap-2">
<span style={{
background: color,
}} className="rounded-sm px-1.5 py-px text-[10px] font-bold text-black">
{CAT_LABELS[sat.category]}
</span>
<strong>{sat.name}</strong>
</div>
<table className="w-full text-[11px]">
<tbody>
<tr><td className="text-kcg-muted">{t('satellite.norad')}</td><td>{sat.noradId}</td></tr>
<tr><td className="text-kcg-muted">{t('satellite.lat')}</td><td>{sat.lat.toFixed(2)}&deg;</td></tr>
<tr><td className="text-kcg-muted">{t('satellite.lng')}</td><td>{sat.lng.toFixed(2)}&deg;</td></tr>
<tr><td className="text-kcg-muted">{t('satellite.alt')}</td><td>{Math.round(sat.altitude)} km</td></tr>
</tbody>
</table>
</div>
</Popup>
)}
</>
);
});