import { useState } from 'react'; import { Marker, Popup, Source, Layer } from 'react-map-gl/maplibre'; import { KOREA_SUBMARINE_CABLES, KOREA_LANDING_POINTS } from '../services/submarineCable'; import type { SubmarineCable } from '../services/submarineCable'; export function SubmarineCableLayer() { const [selectedCable, setSelectedCable] = useState(null); const [selectedPoint, setSelectedPoint] = useState<{ name: string; lat: number; lng: number; cables: string[] } | null>(null); // Build GeoJSON for all cables const geojson: GeoJSON.FeatureCollection = { type: 'FeatureCollection', features: KOREA_SUBMARINE_CABLES.map(cable => ({ type: 'Feature' as const, properties: { id: cable.id, name: cable.name, color: cable.color, }, geometry: { type: 'LineString' as const, coordinates: cable.route, }, })), }; return ( <> {/* Cable lines */} {/* Landing points */} {KOREA_LANDING_POINTS.map(pt => ( { e.originalEvent.stopPropagation(); setSelectedPoint(pt); setSelectedCable(null); }}>
))} {/* Cable name labels along route (midpoint) */} {KOREA_SUBMARINE_CABLES.map(cable => { const mid = cable.route[Math.floor(cable.route.length / 3)]; if (!mid) return null; return ( { e.originalEvent.stopPropagation(); setSelectedCable(cable); setSelectedPoint(null); }}>
{cable.name}
); })} {/* Landing point popup */} {selectedPoint && ( setSelectedPoint(null)} closeOnClick={false} anchor="bottom" maxWidth="260px" className="gl-popup">
📡 {selectedPoint.name} 해저케이블 기지
연결 케이블: {selectedPoint.cables.length}개
{selectedPoint.cables.map(cid => { const c = KOREA_SUBMARINE_CABLES.find(cc => cc.id === cid); if (!c) return null; return (
{c.name}
); })}
)} {/* Cable info popup */} {selectedCable && ( setSelectedCable(null)} closeOnClick={false} anchor="bottom" maxWidth="280px" className="gl-popup">
🔌 {selectedCable.name}
경유지: {selectedCable.landingPoints.join(' → ')}
{selectedCable.rfsYear && (
개통: {selectedCable.rfsYear}년
)} {selectedCable.length && (
총 길이: {selectedCable.length}
)} {selectedCable.owners && (
운영: {selectedCable.owners}
)}
)} ); }