Elffuss BraidHub

kikocis/osiris public

c80d57aec328 · 61.0 KiBRawPermalink
1'use client';
2
3import { useEffect, useRef, useState, useCallback, memo } from 'react';
4import maplibregl from 'maplibre-gl';
5import 'maplibre-gl/dist/maplibre-gl.css';
6
7interface OsirisMapProps {
8 data: any;
9 activeLayers: Record<string, boolean>;
10 onEntityClick?: (entity: any) => void;
11 onMouseCoords?: (coords: { lat: number; lng: number }) => void;
12 onRightClick?: (coords: { lat: number; lng: number }) => void;
13 onViewStateChange?: (vs: { zoom: number; latitude: number }) => void;
14 flyToLocation?: { lat: number; lng: number; ts: number } | null;
15 projection?: 'mercator' | 'globe';
16 mapStyle?: string;
17 sweepData?: any;
18}
19
20function computeSolarTerminator(): [number, number][] {
21 const now = new Date();
22 const dayOfYear = Math.floor((now.getTime() - new Date(now.getFullYear(), 0, 0).getTime()) / 86400000);
23 const declination = -23.44 * Math.cos((2 * Math.PI / 365) * (dayOfYear + 10));
24 const decRad = declination * Math.PI / 180;
25 const utcHours = now.getUTCHours() + now.getUTCMinutes() / 60;
26 const subsolarLng = (12 - utcHours) * 15;
27 const points: [number, number][] = [];
28 for (let lng = -180; lng <= 180; lng += 2) {
29 const lngRad = (lng - subsolarLng) * Math.PI / 180;
30 const lat = Math.atan(-Math.cos(lngRad) / Math.tan(decRad)) * 180 / Math.PI;
31 points.push([lng, lat]);
32 }
33 const darkSide = declination >= 0 ? -90 : 90;
34 points.push([180, darkSide]);
35 points.push([-180, darkSide]);
36 points.push(points[0]);
37 return points;
38}
39
40const EMPTY_FC = { type: 'FeatureCollection' as const, features: [] };
41
42function OsirisMap({ data, activeLayers, onEntityClick, onMouseCoords, onRightClick, onViewStateChange, flyToLocation, projection = 'globe', mapStyle = 'dark', sweepData }: OsirisMapProps) {
43 const containerRef = useRef<HTMLDivElement>(null);
44 const mapRef = useRef<maplibregl.Map | null>(null);
45 const popupRef = useRef<maplibregl.Popup | null>(null);
46 const [mapReady, setMapReady] = useState(false);
47 const prevStyleRef = useRef(mapStyle);
48
49 // Create aircraft icon on canvas (for WebGL symbol layer)
50 const createIcon = useCallback((map: maplibregl.Map, id: string, color: string, size: number) => {
51 if (map.hasImage(id)) return;
52 const canvas = document.createElement('canvas');
53 canvas.width = size; canvas.height = size;
54 const ctx = canvas.getContext('2d')!;
55 const cx = size / 2, cy = size / 2;
56 ctx.fillStyle = color;
57 ctx.beginPath();
58 ctx.moveTo(cx, cy - size * 0.4);
59 ctx.lineTo(cx - size * 0.12, cy + size * 0.1);
60 ctx.lineTo(cx - size * 0.4, cy + size * 0.2);
61 ctx.lineTo(cx - size * 0.4, cy + size * 0.3);
62 ctx.lineTo(cx - size * 0.12, cy + size * 0.15);
63 ctx.lineTo(cx, cy + size * 0.35);
64 ctx.lineTo(cx + size * 0.12, cy + size * 0.15);
65 ctx.lineTo(cx + size * 0.4, cy + size * 0.3);
66 ctx.lineTo(cx + size * 0.4, cy + size * 0.2);
67 ctx.lineTo(cx + size * 0.12, cy + size * 0.1);
68 ctx.closePath();
69 ctx.fill();
70 map.addImage(id, { width: size, height: size, data: new Uint8Array(ctx.getImageData(0, 0, size, size).data) });
71 }, []);
72
73 const createDot = useCallback((map: maplibregl.Map, id: string, color: string, size: number) => {
74 if (map.hasImage(id)) return;
75 const canvas = document.createElement('canvas');
76 canvas.width = size; canvas.height = size;
77 const ctx = canvas.getContext('2d')!;
78 ctx.fillStyle = color;
79 ctx.beginPath();
80 ctx.arc(size/2, size/2, size/2 - 1, 0, Math.PI * 2);
81 ctx.fill();
82 map.addImage(id, { width: size, height: size, data: new Uint8Array(ctx.getImageData(0, 0, size, size).data) });
83 }, []);
84
85 useEffect(() => {
86 if (!containerRef.current || mapRef.current) return;
87 const map = new maplibregl.Map({
88 container: containerRef.current,
89 style: 'https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json',
90 center: [25.48, 42.70], zoom: 6.5, minZoom: 1.5, maxZoom: 18,
91 attributionControl: false,
92 maxPitch: 85,
93 });
94
95 map.on('load', () => {
96 mapRef.current = map;
97 // Create icons
98 createIcon(map, 'plane-cyan', '#00E5FF', 24);
99 createIcon(map, 'plane-green', '#00E676', 24);
100 createIcon(map, 'plane-pink', '#FF69B4', 24);
101 createIcon(map, 'plane-red', '#FF3D3D', 24);
102 createIcon(map, 'plane-grey', '#555555', 24);
103 createDot(map, 'dot-gold', '#D4AF37', 8);
104 createDot(map, 'dot-red', '#FF3D3D', 10);
105 createDot(map, 'dot-orange', '#FF9500', 10);
106 createDot(map, 'dot-green', '#00E676', 10);
107 createDot(map, 'dot-fire', '#FF6B00', 10);
108 createDot(map, 'dot-cctv', '#39FF14', 10);
109
110 // Sources
111 const sources = ['flights','military','jets','private-fl','satellites','earthquakes','gdelt','gps-jamming','day-night','cctv','fires','weather','infrastructure','maritime','maritime-choke','maritime-ships','live-news','sigint-news','conflict-zones', 'war-alerts-targets', 'war-alerts-lines', 'balloons', 'radiation', 'ip-sweep-devices', 'ip-sweep-pulse', 'ip-sweep-connections'];
112 sources.forEach(s => map.addSource(s, { type: 'geojson', data: EMPTY_FC }));
113
114 // ── CONFLICT ZONES — small warning markers (not polygons) ──
115 // Create warning triangle icon
116 const warnSize = 20;
117 const warnCanvas = document.createElement('canvas');
118 warnCanvas.width = warnSize; warnCanvas.height = warnSize;
119 const warnCtx = warnCanvas.getContext('2d')!;
120 // Triangle
121 warnCtx.fillStyle = '#FF1744';
122 warnCtx.beginPath();
123 warnCtx.moveTo(warnSize/2, 1);
124 warnCtx.lineTo(warnSize - 1, warnSize - 1);
125 warnCtx.lineTo(1, warnSize - 1);
126 warnCtx.closePath();
127 warnCtx.fill();
128 // Exclamation mark
129 warnCtx.fillStyle = '#000';
130 warnCtx.font = 'bold 11px sans-serif';
131 warnCtx.textAlign = 'center';
132 warnCtx.fillText('!', warnSize/2, warnSize - 4);
133 map.addImage('warn-icon', { width: warnSize, height: warnSize, data: new Uint8Array(warnCtx.getImageData(0, 0, warnSize, warnSize).data) });
134
135 // Orange warning
136 const warnOCanvas = document.createElement('canvas');
137 warnOCanvas.width = warnSize; warnOCanvas.height = warnSize;
138 const warnOCtx = warnOCanvas.getContext('2d')!;
139 warnOCtx.fillStyle = '#FF9500';
140 warnOCtx.beginPath();
141 warnOCtx.moveTo(warnSize/2, 1);
142 warnOCtx.lineTo(warnSize - 1, warnSize - 1);
143 warnOCtx.lineTo(1, warnSize - 1);
144 warnOCtx.closePath();
145 warnOCtx.fill();
146 warnOCtx.fillStyle = '#000';
147 warnOCtx.font = 'bold 11px sans-serif';
148 warnOCtx.textAlign = 'center';
149 warnOCtx.fillText('!', warnSize/2, warnSize - 4);
150 map.addImage('warn-orange', { width: warnSize, height: warnSize, data: new Uint8Array(warnOCtx.getImageData(0, 0, warnSize, warnSize).data) });
151
152 // Yellow warning
153 const warnYCanvas = document.createElement('canvas');
154 warnYCanvas.width = warnSize; warnYCanvas.height = warnSize;
155 const warnYCtx = warnYCanvas.getContext('2d')!;
156 warnYCtx.fillStyle = '#FFD500';
157 warnYCtx.beginPath();
158 warnYCtx.moveTo(warnSize/2, 1);
159 warnYCtx.lineTo(warnSize - 1, warnSize - 1);
160 warnYCtx.lineTo(1, warnSize - 1);
161 warnYCtx.closePath();
162 warnYCtx.fill();
163 warnYCtx.fillStyle = '#000';
164 warnYCtx.font = 'bold 11px sans-serif';
165 warnYCtx.textAlign = 'center';
166 warnYCtx.fillText('!', warnSize/2, warnSize - 4);
167 map.addImage('warn-yellow', { width: warnSize, height: warnSize, data: new Uint8Array(warnYCtx.getImageData(0, 0, warnSize, warnSize).data) });
168
169 map.addLayer({ id: 'conflict-icons', type: 'symbol', source: 'conflict-zones', layout: {
170 'icon-image': ['match', ['get','severity'], 'war','warn-icon', 'high','warn-orange', 'warn-yellow'],
171 'icon-size': ['interpolate',['linear'],['zoom'], 1,0.6, 4,0.8, 8,1],
172 'icon-allow-overlap': true,
173 'text-field': ['get','label'],
174 'text-size': ['interpolate',['linear'],['zoom'], 1,7, 4,9, 8,11],
175 'text-font': ['Open Sans Bold'],
176 'text-offset': [0, 1.4],
177 'text-allow-overlap': false,
178 }, paint: {
179 'text-color': ['match', ['get','severity'], 'war','#FF1744', 'high','#FF9500', '#FFD500'],
180 'text-halo-color': '#000', 'text-halo-width': 1.5, 'text-opacity': 0.9,
181 }});
182
183
184 // Day/Night
185 map.addLayer({ id: 'day-night-fill', type: 'fill', source: 'day-night', paint: { 'fill-color': '#000022', 'fill-opacity': 0.35 }});
186
187 // Earthquakes
188 map.addLayer({ id: 'eq-circles', type: 'circle', source: 'earthquakes', paint: {
189 'circle-radius': ['interpolate',['linear'],['get','magnitude'], 2.5,4, 5,12, 7,24],
190 'circle-color': ['interpolate',['linear'],['get','magnitude'], 2.5,'#FFD700', 4,'#FF9500', 6,'#FF1744'],
191 'circle-opacity': 0.6, 'circle-blur': 0.3, 'circle-stroke-width': 1, 'circle-stroke-color': '#FFD700', 'circle-stroke-opacity': 0.3,
192 }});
193 map.addLayer({ id: 'eq-label', type: 'symbol', source: 'earthquakes', filter: ['>=',['get','magnitude'],4.5], layout: {
194 'text-field': ['concat','M',['to-string',['get','magnitude']]], 'text-size': 9, 'text-font': ['Open Sans Regular'], 'text-offset': [0,1.5],
195 }, paint: { 'text-color': '#FFD700', 'text-halo-color': '#000', 'text-halo-width': 1 }});
196
197 // Fires
198 map.addLayer({ id: 'fires-heat', type: 'circle', source: 'fires', paint: {
199 'circle-radius': ['interpolate',['linear'],['zoom'], 1,2, 5,4, 10,8],
200 'circle-color': '#FF6B00', 'circle-opacity': 0.5, 'circle-blur': 0.5,
201 }});
202
203 // CCTV — outer glow ring
204 map.addLayer({ id: 'cctv-glow', type: 'circle', source: 'cctv', paint: {
205 'circle-radius': ['interpolate',['linear'],['zoom'], 1,5, 5,8, 10,14, 14,20],
206 'circle-color': '#39FF14', 'circle-opacity': 0.08, 'circle-blur': 1,
207 }});
208 // CCTV — main dot
209 map.addLayer({ id: 'cctv-dots', type: 'circle', source: 'cctv', paint: {
210 'circle-radius': ['interpolate',['linear'],['zoom'], 1,3, 5,5, 10,8, 14,12],
211 'circle-color': '#39FF14', 'circle-opacity': 0.8,
212 'circle-stroke-width': 2, 'circle-stroke-color': '#39FF14', 'circle-stroke-opacity': 0.5,
213 }});
214 // CCTV — labels at zoom 10+
215 map.addLayer({ id: 'cctv-label', type: 'symbol', source: 'cctv', minzoom: 10, layout: {
216 'text-field': ['get','name'], 'text-size': 9, 'text-font': ['Open Sans Regular'],
217 'text-offset': [0, 1.8], 'text-max-width': 12, 'text-allow-overlap': false,
218 }, paint: { 'text-color': '#39FF14', 'text-halo-color': '#000', 'text-halo-width': 1, 'text-opacity': 0.7 }});
219
220 // GDELT
221 map.addLayer({ id: 'gdelt-dots', type: 'circle', source: 'gdelt', paint: {
222 'circle-radius': 4, 'circle-color': '#FF3D3D', 'circle-opacity': 0.5, 'circle-stroke-width': 1, 'circle-stroke-color': '#FF3D3D', 'circle-stroke-opacity': 0.3,
223 }});
224
225 // GPS Jamming
226 map.addLayer({ id: 'jam-fill', type: 'circle', source: 'gps-jamming', paint: { 'circle-radius': 30, 'circle-color': '#FF0000', 'circle-opacity': 0.15, 'circle-blur': 1 }});
227 map.addLayer({ id: 'jam-label', type: 'symbol', source: 'gps-jamming', layout: {
228 'text-field': ['concat','GPS JAM ',['to-string',['get','severity']],'%'], 'text-size': 10, 'text-font': ['Open Sans Bold'], 'text-allow-overlap': true,
229 }, paint: { 'text-color': '#FF4444', 'text-halo-color': '#000', 'text-halo-width': 1 }});
230
231 // Weather Events (NASA EONET — storms, volcanoes)
232 map.addLayer({ id: 'weather-glow', type: 'circle', source: 'weather', paint: {
233 'circle-radius': ['interpolate',['linear'],['zoom'], 1,12, 5,20, 10,30],
234 'circle-color': '#E040FB', 'circle-opacity': 0.1, 'circle-blur': 1,
235 }});
236 map.addLayer({ id: 'weather-dots', type: 'circle', source: 'weather', paint: {
237 'circle-radius': ['interpolate',['linear'],['zoom'], 1,5, 5,8, 10,14],
238 'circle-color': ['match', ['get','icon'], 'cyclone','#E040FB', 'volcano','#FF1744', '#E040FB'],
239 'circle-opacity': 0.8,
240 'circle-stroke-width': 2, 'circle-stroke-color': '#E040FB', 'circle-stroke-opacity': 0.4,
241 }});
242 map.addLayer({ id: 'weather-label', type: 'symbol', source: 'weather', layout: {
243 'text-field': ['get','title'], 'text-size': 9, 'text-font': ['Open Sans Regular'],
244 'text-offset': [0, 2], 'text-max-width': 14, 'text-allow-overlap': false,
245 }, paint: { 'text-color': '#E040FB', 'text-halo-color': '#000', 'text-halo-width': 1, 'text-opacity': 0.8 }});
246
247 // Nuclear Infrastructure
248 map.addLayer({ id: 'infra-glow', type: 'circle', source: 'infrastructure', paint: {
249 'circle-radius': ['interpolate',['linear'],['zoom'], 1,8, 5,14, 10,22],
250 'circle-color': '#76FF03', 'circle-opacity': 0.08, 'circle-blur': 1,
251 }});
252 map.addLayer({ id: 'infra-dots', type: 'circle', source: 'infrastructure', paint: {
253 'circle-radius': ['interpolate',['linear'],['zoom'], 1,4, 5,6, 10,10],
254 'circle-color': ['match', ['get','status'], 'Active Conflict Zone','#FF1744', 'Destroyed / Decommissioning','#757575', '#76FF03'],
255 'circle-opacity': 0.8,
256 'circle-stroke-width': 2, 'circle-stroke-color': '#76FF03', 'circle-stroke-opacity': 0.4,
257 }});
258 map.addLayer({ id: 'infra-label', type: 'symbol', source: 'infrastructure', minzoom: 5, layout: {
259 'text-field': ['get','name'], 'text-size': 9, 'text-font': ['Open Sans Regular'],
260 'text-offset': [0, 2], 'text-max-width': 14, 'text-allow-overlap': false,
261 }, paint: { 'text-color': '#76FF03', 'text-halo-color': '#000', 'text-halo-width': 1, 'text-opacity': 0.7 }});
262
263 // Satellites
264 map.addLayer({ id: 'sat-dots', type: 'circle', source: 'satellites', paint: {
265 'circle-radius': ['interpolate',['linear'],['zoom'], 1,1.5, 5,3], 'circle-color': ['get','color'], 'circle-opacity': 0.7,
266 }});
267
268 // Maritime — ports & naval bases
269 map.addLayer({ id: 'maritime-glow', type: 'circle', source: 'maritime', paint: {
270 'circle-radius': ['interpolate',['linear'],['zoom'], 1,6, 5,12, 10,20],
271 'circle-color': ['match', ['get','type'], 'naval','#FF3D3D', 'energy','#FF9500', '#00BCD4'],
272 'circle-opacity': 0.1, 'circle-blur': 1,
273 }});
274 map.addLayer({ id: 'maritime-dots', type: 'circle', source: 'maritime', paint: {
275 'circle-radius': ['interpolate',['linear'],['zoom'], 1,3, 5,5, 10,9],
276 'circle-color': ['match', ['get','type'], 'naval','#FF3D3D', 'energy','#FF9500', '#00BCD4'],
277 'circle-opacity': 0.85,
278 'circle-stroke-width': 2, 'circle-stroke-color': ['match', ['get','type'], 'naval','#FF3D3D', 'energy','#FF9500', '#00BCD4'], 'circle-stroke-opacity': 0.4,
279 }});
280 map.addLayer({ id: 'maritime-label', type: 'symbol', source: 'maritime', minzoom: 4, layout: {
281 'text-field': ['get','name'], 'text-size': 9, 'text-font': ['Open Sans Regular'],
282 'text-offset': [0, 1.8], 'text-max-width': 12, 'text-allow-overlap': false,
283 }, paint: { 'text-color': '#00BCD4', 'text-halo-color': '#000', 'text-halo-width': 1, 'text-opacity': 0.7 }});
284
285 // Maritime chokepoints — pulsing warning diamonds
286 map.addLayer({ id: 'choke-glow', type: 'circle', source: 'maritime-choke', paint: {
287 'circle-radius': ['interpolate',['linear'],['zoom'], 1,10, 5,18, 10,28],
288 'circle-color': '#FF9500', 'circle-opacity': 0.12, 'circle-blur': 1,
289 }});
290 map.addLayer({ id: 'choke-dots', type: 'circle', source: 'maritime-choke', paint: {
291 'circle-radius': ['interpolate',['linear'],['zoom'], 1,4, 5,7, 10,12],
292 'circle-color': ['match', ['get','risk'], 'CRITICAL','#FF1744', 'HIGH','#FF9500', 'ELEVATED','#FFD700', '#00E676'],
293 'circle-opacity': 0.9,
294 'circle-stroke-width': 2, 'circle-stroke-color': '#FF9500', 'circle-stroke-opacity': 0.5,
295 }});
296 map.addLayer({ id: 'choke-label', type: 'symbol', source: 'maritime-choke', minzoom: 3, layout: {
297 'text-field': ['get','name'], 'text-size': 10, 'text-font': ['Open Sans Bold'],
298 'text-offset': [0, 2], 'text-max-width': 14, 'text-allow-overlap': false,
299 }, paint: { 'text-color': '#FF9500', 'text-halo-color': '#000', 'text-halo-width': 1, 'text-opacity': 0.9 }});
300
301 // Live News — broadcast dots
302 map.addLayer({ id: 'news-glow', type: 'circle', source: 'live-news', paint: {
303 'circle-radius': ['interpolate',['linear'],['zoom'], 1,8, 5,14, 10,22],
304 'circle-color': '#FF4081', 'circle-opacity': 0.1, 'circle-blur': 1,
305 }});
306 map.addLayer({ id: 'news-dots', type: 'circle', source: 'live-news', paint: {
307 'circle-radius': ['interpolate',['linear'],['zoom'], 1,4, 5,6, 10,10],
308 'circle-color': '#FF4081', 'circle-opacity': 0.85,
309 'circle-stroke-width': 2, 'circle-stroke-color': '#FF4081', 'circle-stroke-opacity': 0.5,
310 }});
311 map.addLayer({ id: 'news-label', type: 'symbol', source: 'live-news', minzoom: 4, layout: {
312 'text-field': ['get','name'], 'text-size': 9, 'text-font': ['Open Sans Regular'],
313 'text-offset': [0, 1.8], 'text-max-width': 12, 'text-allow-overlap': false,
314 }, paint: { 'text-color': '#FF4081', 'text-halo-color': '#000', 'text-halo-width': 1, 'text-opacity': 0.8 }});
315
316 // SIGINT RSS news - gold markers
317 map.addLayer({ id: 'sigint-news-glow', type: 'circle', source: 'sigint-news', paint: {
318 'circle-radius': ['interpolate',['linear'],['zoom'], 1,6, 5,10, 10,18],
319 'circle-color': '#D4AF37', 'circle-opacity': 0.12, 'circle-blur': 1,
320 }});
321 map.addLayer({ id: 'sigint-news-dots', type: 'circle', source: 'sigint-news', paint: {
322 'circle-radius': ['interpolate',['linear'],['zoom'], 1,3, 5,5, 10,8],
323 'circle-color': '#D4AF37', 'circle-opacity': 0.9,
324 'circle-stroke-width': 1.5, 'circle-stroke-color': '#FFF8DC', 'circle-stroke-opacity': 0.6,
325 }});
326 map.addLayer({ id: 'sigint-news-label', type: 'symbol', source: 'sigint-news', minzoom: 5, layout: {
327 'text-field': ['get','source'], 'text-size': 9, 'text-font': ['Open Sans Regular'],
328 'text-offset': [0, 1.6], 'text-max-width': 10, 'text-allow-overlap': false,
329 }, paint: { 'text-color': '#D4AF37', 'text-halo-color': '#000', 'text-halo-width': 1, 'text-opacity': 0.85 }});
330
331 // ══ IP SWEEP — Neighborhood device visualization ══
332 map.addLayer({ id: 'sweep-connections', type: 'line', source: 'ip-sweep-connections', paint: {
333 'line-color': ['get', 'color'], 'line-width': 1, 'line-opacity': 0.3, 'line-dasharray': [2, 4],
334 }});
335 map.addLayer({ id: 'sweep-pulse-ring', type: 'circle', source: 'ip-sweep-pulse', paint: {
336 'circle-radius': ['interpolate',['linear'],['zoom'], 8,40, 12,80, 16,160],
337 'circle-color': 'transparent', 'circle-opacity': 0.6,
338 'circle-stroke-width': 2, 'circle-stroke-color': '#FF3D3D', 'circle-stroke-opacity': 0.4,
339 }});
340 map.addLayer({ id: 'sweep-device-glow', type: 'circle', source: 'ip-sweep-devices', paint: {
341 'circle-radius': ['interpolate',['linear'],['zoom'], 8,8, 12,16, 16,30],
342 'circle-color': ['get', 'color'], 'circle-opacity': 0.15, 'circle-blur': 1,
343 }});
344 map.addLayer({ id: 'sweep-device-dots', type: 'circle', source: 'ip-sweep-devices', paint: {
345 'circle-radius': ['interpolate',['linear'],['zoom'], 8,3, 12,6, 16,10],
346 'circle-color': ['get', 'color'], 'circle-opacity': 0.95,
347 'circle-stroke-width': 1.5, 'circle-stroke-color': '#FFFFFF', 'circle-stroke-opacity': 0.6,
348 }});
349 map.addLayer({ id: 'sweep-device-labels', type: 'symbol', source: 'ip-sweep-devices', minzoom: 13, layout: {
350 'text-field': ['concat', ['get', 'device_type'], '\n', ['get', 'ip']],
351 'text-size': 9, 'text-font': ['Open Sans Regular'],
352 'text-offset': [0, 2.2], 'text-max-width': 12, 'text-allow-overlap': false,
353 }, paint: {
354 'text-color': ['get', 'color'], 'text-halo-color': '#000', 'text-halo-width': 1.5, 'text-opacity': 0.9,
355 }});
356
357 // Flight layers (WebGL symbol — GPU rendered, handles 50K+ smooth)
358 const flightLayers = [
359 { id: 'fl-commercial', src: 'flights', icon: 'plane-cyan' },
360 { id: 'fl-private', src: 'private-fl', icon: 'plane-green' },
361 { id: 'fl-jets', src: 'jets', icon: 'plane-pink' },
362 { id: 'fl-military', src: 'military', icon: 'plane-red' },
363 ];
364 flightLayers.forEach(l => {
365 map.addLayer({ id: l.id, type: 'symbol', source: l.src, layout: {
366 'icon-image': l.icon, 'icon-size': ['interpolate',['linear'],['zoom'], 1,0.4, 5,0.7, 10,1],
367 'icon-rotate': ['get','heading'], 'icon-rotation-alignment': 'map', 'icon-allow-overlap': true, 'icon-ignore-placement': true,
368 }, paint: { 'icon-opacity': 0.85 }});
369 });
370
371 // Balloons (moving entities)
372 map.addLayer({ id: 'balloon-dots', type: 'circle', source: 'balloons', paint: {
373 'circle-radius': ['interpolate',['linear'],['zoom'], 1,3, 5,5, 10,7],
374 'circle-color': ['get', 'color'],
375 'circle-opacity': 0.8,
376 'circle-stroke-width': 1, 'circle-stroke-color': '#fff', 'circle-stroke-opacity': 0.5,
377 }});
378 map.addLayer({ id: 'balloon-label', type: 'symbol', source: 'balloons', minzoom: 4, layout: {
379 'text-field': ['get','callsign'], 'text-size': 9, 'text-font': ['Open Sans Regular'],
380 'text-offset': [0, 1.2], 'text-max-width': 12, 'text-allow-overlap': false,
381 }, paint: { 'text-color': ['get', 'color'], 'text-halo-color': '#000', 'text-halo-width': 1 }});
382
383 // Radiation (glow based on reading level)
384 map.addLayer({ id: 'rad-glow', type: 'circle', source: 'radiation', paint: {
385 'circle-radius': ['interpolate',['linear'],['zoom'], 1,10, 5,20, 10,40],
386 'circle-color': ['match', ['get','status'], 'DANGER','#FF1744', 'WARNING','#FF9500', '#AB47BC'],
387 'circle-opacity': 0.15, 'circle-blur': 1,
388 }});
389 map.addLayer({ id: 'rad-dots', type: 'circle', source: 'radiation', paint: {
390 'circle-radius': ['interpolate',['linear'],['zoom'], 1,4, 5,6, 10,8],
391 'circle-color': ['match', ['get','status'], 'DANGER','#FF1744', 'WARNING','#FF9500', '#AB47BC'],
392 'circle-opacity': 0.9,
393 'circle-stroke-width': 2, 'circle-stroke-color': ['match', ['get','status'], 'DANGER','#FF1744', 'WARNING','#FF9500', '#AB47BC'], 'circle-stroke-opacity': 0.4,
394 }});
395 map.addLayer({ id: 'rad-label', type: 'symbol', source: 'radiation', minzoom: 5, layout: {
396 'text-field': ['concat', ['to-string', ['get','reading']], ' nSv/h'], 'text-size': 9, 'text-font': ['Open Sans Bold'],
397 'text-offset': [0, 1.5], 'text-allow-overlap': false,
398 }, paint: { 'text-color': ['match', ['get','status'], 'DANGER','#FF1744', 'WARNING','#FF9500', '#AB47BC'], 'text-halo-color': '#000', 'text-halo-width': 1 }});
399
400 // Maritime Ships (moving entities)
401 map.addLayer({ id: 'ship-dots', type: 'circle', source: 'maritime-ships', paint: {
402 'circle-radius': ['interpolate',['linear'],['zoom'], 1,2, 5,4, 10,6],
403 'circle-color': ['match', ['get','type'], 'military','#FF1744', 'tanker','#FF9500', 'cargo','#00BCD4', '#fff'],
404 'circle-opacity': 0.8,
405 }});
406 map.addLayer({ id: 'ship-label', type: 'symbol', source: 'maritime-ships', minzoom: 5, layout: {
407 'text-field': ['get','name'], 'text-size': 9, 'text-font': ['Open Sans Regular'],
408 'text-offset': [0, 1.2], 'text-allow-overlap': false,
409 }, paint: { 'text-color': ['match', ['get','type'], 'military','#FF1744', 'tanker','#FF9500', 'cargo','#00BCD4', '#fff'], 'text-halo-color': '#000', 'text-halo-width': 1 }});
410
411 setMapReady(true);
412 });
413
414 // Events
415 let lastMove = 0;
416 map.on('mousemove', e => {
417 const now = Date.now();
418 if (now - lastMove > 100) {
419 lastMove = now;
420 onMouseCoords?.({ lat: e.lngLat.lat, lng: e.lngLat.lng });
421 }
422 });
423 map.on('contextmenu', e => { e.preventDefault(); onRightClick?.({ lat: e.lngLat.lat, lng: e.lngLat.lng }); });
424 map.on('moveend', () => { const c = map.getCenter(); onViewStateChange?.({ zoom: map.getZoom(), latitude: c.lat }); });
425
426 // ── POPUP HELPER ──
427 const popup = (coords: any, html: string) => {
428 popupRef.current?.remove();
429 popupRef.current = new maplibregl.Popup({ closeButton: true, maxWidth: '420px', offset: 14 }).setLngLat(coords).setHTML(html).addTo(map);
430 };
431 const pStyle = `background:rgba(12,14,26,0.95);backdrop-filter:blur(16px);border-radius:10px;padding:16px;font-family:'JetBrains Mono',monospace;`;
432 const linkStyle = `display:inline-block;margin-top:8px;padding:5px 12px;font-size:10px;letter-spacing:0.12em;text-decoration:none;border-radius:5px;font-family:'JetBrains Mono',monospace;`;
433
434 // ── Flights (with FlightAware + ADS-B Exchange links) ──
435 ['fl-commercial','fl-private','fl-jets','fl-military'].forEach(layer => {
436 map.on('click', layer, e => {
437 if (!e.features?.length) return;
438 const p = e.features[0].properties as any;
439 const coords = (e.features[0].geometry as any).coordinates;
440 const cs = (p.callsign||'').trim();
441 popup(coords, `<div style="${pStyle}border:1px solid rgba(212,175,55,0.3);">
442 <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:10px;">
443 <span style="color:#D4AF37;font-size:16px;font-weight:700;letter-spacing:0.1em;">${cs}</span>
444 <span style="color:#5C5A54;font-size:10px;">${p.icao24||''}</span>
445 </div>
446 <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px;font-size:11px;">
447 <div><span style="color:#5C5A54;font-size:9px;">MODEL</span><br/><span style="color:#E8E6E0;">${p.model||'—'}</span></div>
448 <div><span style="color:#5C5A54;font-size:9px;">ALT</span><br/><span style="color:#00E5FF;">${p.alt?Math.round(p.alt)+'m':'—'}</span></div>
449 <div><span style="color:#5C5A54;font-size:9px;">SPEED</span><br/><span style="color:#E8E6E0;">${p.speed_knots||'—'}kt</span></div>
450 <div><span style="color:#5C5A54;font-size:9px;">HDG</span><br/><span style="color:#E8E6E0;">${Math.round(p.heading||0)}°</span></div>
451 <div><span style="color:#5C5A54;font-size:9px;">REG</span><br/><span style="color:#E8E6E0;">${p.registration||'—'}</span></div>
452 <div><span style="color:#5C5A54;font-size:9px;">POS</span><br/><span style="color:#E8E6E0;">${coords[1].toFixed(2)},${coords[0].toFixed(2)}</span></div>
453 </div>
454 <div style="margin-top:12px;display:flex;gap:6px;flex-wrap:wrap;">
455 <a href="https://www.flightaware.com/live/flight/${cs}" target="_blank" style="${linkStyle}color:#D4AF37;border:1px solid rgba(212,175,55,0.4);background:rgba(212,175,55,0.1);">⚡ FLIGHTAWARE</a>
456 <a href="https://globe.adsbexchange.com/?icao=${p.icao24||''}" target="_blank" style="${linkStyle}color:#00E5FF;border:1px solid rgba(0,229,255,0.4);background:rgba(0,229,255,0.1);">📡 ADS-B</a>
457 <a href="https://www.radarbox.com/data/flights/${cs}" target="_blank" style="${linkStyle}color:#FF69B4;border:1px solid rgba(255,105,180,0.4);background:rgba(255,105,180,0.1);">📍 RADARBOX</a>
458 </div>
459 </div>`);
460 onEntityClick?.(p);
461 });
462 map.on('mouseenter', layer, () => { map.getCanvas().style.cursor = 'pointer'; });
463 map.on('mouseleave', layer, () => { map.getCanvas().style.cursor = ''; });
464 });
465
466 // ── CCTV (opens CameraViewer panel) ──
467 map.on('click', 'cctv-dots', e => {
468 if (!e.features?.length) return;
469 const p = e.features[0].properties as any;
470 const coords = (e.features[0].geometry as any).coordinates;
471 // Emit the camera data so the CameraViewer opens
472 onEntityClick?.({
473 type: 'cctv',
474 id: p.id,
475 name: p.name,
476 city: p.city,
477 country: p.country,
478 source: p.source,
479 feed_url: p.feed_url,
480 stream_url: p.stream_url,
481 stream_type: p.stream_type,
482 external_url: p.external_url,
483 lat: coords[1],
484 lng: coords[0],
485 });
486 // Also fly to the camera
487 map.flyTo({ center: coords, zoom: Math.max(map.getZoom(), 13), duration: 1000 });
488 });
489
490 // ── Earthquakes (with USGS link) ──
491 map.on('click', 'eq-circles', e => {
492 if (!e.features?.length) return;
493 const p = e.features[0].properties as any;
494 const coords = (e.features[0].geometry as any).coordinates;
495 popup(coords, `<div style="${pStyle}border:1px solid rgba(255,149,0,0.3);">
496 <div style="color:#FF9500;font-size:14px;font-weight:700;margin-bottom:4px;">M${p.magnitude} EARTHQUAKE</div>
497 <div style="font-size:9px;color:#E8E6E0;margin-bottom:8px;">${p.place||'Unknown location'}</div>
498 <div style="display:grid;grid-template-columns:1fr 1fr;gap:4px;font-size:9px;">
499 <div><span style="color:#5C5A54;">DEPTH</span><br/><span style="color:#E8E6E0;">${p.depth||'—'}km</span></div>
500 <div><span style="color:#5C5A54;">COORDS</span><br/><span style="color:#E8E6E0;">${coords[1].toFixed(3)}, ${coords[0].toFixed(3)}</span></div>
501 </div>
502 <a href="${p.source === 'NIGGG-BAS' ? 'https://ndc.niggg.bas.bg/' : `https://earthquake.usgs.gov/earthquakes/eventpage/${p.id||''}`}" target="_blank" style="${linkStyle}color:#FF9500;border:1px solid rgba(255,149,0,0.4);background:rgba(255,149,0,0.1);">📊 ${p.source === 'NIGGG-BAS' ? 'NIGGG-BAS' : 'USGS DETAILS'}</a>
503 </div>`);
504 });
505
506 // ── Satellites (with N2YO tracking) ──
507 map.on('click', 'sat-dots', e => {
508 if (!e.features?.length) return;
509 const p = e.features[0].properties as any;
510 const coords = (e.features[0].geometry as any).coordinates;
511 popup(coords, `<div style="${pStyle}border:1px solid rgba(212,175,55,0.3);">
512 <div style="color:#D4AF37;font-size:12px;font-weight:700;letter-spacing:0.1em;margin-bottom:4px;">🛰️ ${p.name}</div>
513 <div style="display:grid;grid-template-columns:1fr 1fr;gap:4px;font-size:9px;margin-bottom:8px;">
514 <div><span style="color:#5C5A54;">MISSION</span><br/><span style="color:${p.color||'#aaa'};">${p.mission||'Unknown'}</span></div>
515 <div><span style="color:#5C5A54;">POS</span><br/><span style="color:#E8E6E0;">${coords[1].toFixed(2)}°, ${coords[0].toFixed(2)}°</span></div>
516 </div>
517 <a href="https://www.n2yo.com/?s=${encodeURIComponent(p.name||'')}" target="_blank" style="${linkStyle}color:#D4AF37;border:1px solid rgba(212,175,55,0.4);background:rgba(212,175,55,0.1);">🔭 TRACK ON N2YO</a>
518 </div>`);
519 });
520
521 // ── Fires (with NASA FIRMS link) ──
522 map.on('click', 'fires-heat', e => {
523 if (!e.features?.length) return;
524 const p = e.features[0].properties as any;
525 const coords = (e.features[0].geometry as any).coordinates;
526 popup(coords, `<div style="${pStyle}border:1px solid rgba(255,107,0,0.3);">
527 <div style="color:#FF6B00;font-size:12px;font-weight:700;margin-bottom:6px;">🔥 ACTIVE FIRE DETECTED</div>
528 <div style="display:grid;grid-template-columns:1fr 1fr;gap:4px;font-size:9px;margin-bottom:8px;">
529 <div><span style="color:#5C5A54;">BRIGHTNESS</span><br/><span style="color:#FF6B00;">${p.brightness||'—'}K</span></div>
530 <div><span style="color:#5C5A54;">COORDS</span><br/><span style="color:#E8E6E0;">${coords[1].toFixed(3)}°, ${coords[0].toFixed(3)}°</span></div>
531 </div>
532 <a href="https://firms.modaps.eosdis.nasa.gov/map/#d:24hrs;l:noaa20-viirs,viirs,modis_a,modis_t;@${coords[0]},${coords[1]},10z" target="_blank" style="${linkStyle}color:#FF6B00;border:1px solid rgba(255,107,0,0.4);background:rgba(255,107,0,0.1);">🛰️ NASA FIRMS MAP</a>
533 </div>`);
534 });
535
536 // ── GDELT Conflicts (with source article) ──
537 map.on('click', 'gdelt-dots', e => {
538 if (!e.features?.length) return;
539 const p = e.features[0].properties as any;
540 const coords = (e.features[0].geometry as any).coordinates;
541 popup(coords, `<div style="${pStyle}border:1px solid rgba(255,61,61,0.3);">
542 <div style="color:#FF3D3D;font-size:12px;font-weight:700;margin-bottom:6px;">⚠️ CONFLICT EVENT</div>
543 <div style="font-size:9px;color:#E8E6E0;margin-bottom:8px;line-height:1.4;">${p.name||'Unclassified incident'}</div>
544 <div style="display:flex;gap:6px;">
545 ${p.url ? `<a href="${p.url}" target="_blank" style="${linkStyle}color:#FF3D3D;border:1px solid rgba(255,61,61,0.4);background:rgba(255,61,61,0.1);">SOURCE</a>` : ''}
546 <a href="https://www.google.com/maps/@${coords[1]},${coords[0]},12z" target="_blank" style="${linkStyle}color:#448AFF;border:1px solid rgba(68,138,255,0.4);background:rgba(68,138,255,0.1);">MAP</a>
547 </div>
548 </div>`);
549 });
550
551 // ── Global Event / Conflict Markers ──
552 map.on('click', 'conflict-icons', e => {
553 if (!e.features?.length) return;
554 const p = e.features[0].properties as any;
555 const coords = (e.features[0].geometry as any).coordinates;
556 const color = p.severity === 'war' ? '#FF1744' : p.severity === 'high' ? '#FF9500' : '#FFD500';
557 popup(coords, `<div style="${pStyle}border:1px solid ${color}40;">
558 <div style="color:${color};font-size:12px;font-weight:700;margin-bottom:6px;">⚠️ ${p.label || 'WARNING EVENT'}</div>
559 <div style="font-size:10px;color:#E8E6E0;margin-bottom:8px;line-height:1.4;">${p.description || 'Global event detected at this location.'}</div>
560 <div style="display:grid;grid-template-columns:1fr 1fr;gap:4px;font-size:9px;margin-bottom:8px;">
561 <div><span style="color:#5C5A54;">SEVERITY</span><br/><span style="color:${color};">${(p.severity||'unknown').toUpperCase()}</span></div>
562 <div><span style="color:#5C5A54;">COORDS</span><br/><span style="color:#E8E6E0;">${coords[1].toFixed(3)}°, ${coords[0].toFixed(3)}°</span></div>
563 </div>
564 </div>`);
565 });
566
567
568 // ── Generic hover for clickables ──
569 ['conflict-icons','cctv-dots','eq-circles','sat-dots','fires-heat','gdelt-dots','weather-dots','infra-dots','maritime-dots','choke-dots','news-dots','sigint-news-dots','balloon-dots','rad-dots','ship-dots','sweep-device-dots'].forEach(layer => {
570 map.on('mouseenter', layer, () => { map.getCanvas().style.cursor = 'pointer'; });
571 map.on('mouseleave', layer, () => { map.getCanvas().style.cursor = ''; });
572 });
573
574 // ── IP Sweep device click ──
575 map.on('click', 'sweep-device-dots', (e: any) => {
576 const p = e.features?.[0]?.properties;
577 if (!p) return;
578 const coords = e.features[0].geometry.coordinates.slice();
579 const ports = JSON.parse(p.ports || '[]');
580 const vulns = JSON.parse(p.vulns || '[]');
581 const hostnames = JSON.parse(p.hostnames || '[]');
582 const riskColors: Record<string, string> = { CRITICAL: '#FF3D3D', HIGH: '#FF6B00', MEDIUM: '#FFD700', LOW: '#76FF03', INFO: '#5C5A54' };
583 popup(coords, `<div style="font-family:monospace;font-size:11px;color:#E8E6E0;">
584 <div style="font-size:13px;font-weight:bold;margin-bottom:6px;color:${p.color};">${p.device_type}</div>
585 <div style="font-size:12px;margin-bottom:8px;color:#fff;">${p.ip}</div>
586 ${hostnames.length > 0 ? `<div style="font-size:9px;color:#8A8880;margin-bottom:6px;">${hostnames.join(', ')}</div>` : ''}
587 <div style="display:grid;grid-template-columns:1fr 1fr;gap:6px;margin-bottom:8px;">
588 <div><span style="color:#5C5A54;">PORTS</span><br/><span style="color:#E8E6E0;">${ports.length}</span></div>
589 <div><span style="color:#5C5A54;">RISK</span><br/><span style="color:${riskColors[p.risk_level] || '#666'};">${p.risk_level}</span></div>
590 </div>
591 <div style="font-size:9px;color:#8A8880;margin-bottom:6px;">Open: ${ports.slice(0, 12).join(', ')}${ports.length > 12 ? ' ...' : ''}</div>
592 ${vulns.length > 0 ? `<div style="font-size:9px;color:#FF3D3D;margin-bottom:6px;">⚠ CVEs: ${vulns.slice(0, 5).join(', ')}${vulns.length > 5 ? ` +${vulns.length - 5} more` : ''}</div>` : ''}
593 </div>`);
594 });
595
596 // ── Balloons / Sondes ──
597 map.on('click', 'balloon-dots', e => {
598 if (!e.features?.length) return;
599 const p = e.features[0].properties as any;
600 const coords = (e.features[0].geometry as any).coordinates;
601 popup(coords, `<div style="${pStyle}border:1px solid ${p.color}40;">
602 <div style="color:${p.color};font-size:12px;font-weight:700;letter-spacing:0.1em;margin-bottom:4px;">🎈 ${p.callsign}</div>
603 <div style="font-size:9px;color:#aaa;margin-bottom:8px;">${p.type.toUpperCase()} / STATUS: ${p.status.toUpperCase()}</div>
604 <div style="display:grid;grid-template-columns:1fr 1fr;gap:4px;font-size:9px;">
605 <div><span style="color:#5C5A54;">ALTITUDE</span><br/><span style="color:#E8E6E0;">${p.altitude} m</span></div>
606 <div><span style="color:#5C5A54;">SPEED</span><br/><span style="color:#E8E6E0;">${Math.round(p.speed)} km/h</span></div>
607 <div><span style="color:#5C5A54;">VERT RATE</span><br/><span style="color:${p.verticalRate > 0 ? '#00E676' : '#FF3D3D'};">${p.verticalRate.toFixed(1)} m/s</span></div>
608 <div><span style="color:#5C5A54;">TEMP</span><br/><span style="color:#E8E6E0;">${p.temperature}°C</span></div>
609 </div>
610 </div>`);
611 });
612
613 // ── Radiation ──
614 map.on('click', 'rad-dots', e => {
615 if (!e.features?.length) return;
616 const p = e.features[0].properties as any;
617 const coords = (e.features[0].geometry as any).coordinates;
618 const color = p.status === 'DANGER' ? '#FF1744' : p.status === 'WARNING' ? '#FF9500' : '#AB47BC';
619 popup(coords, `<div style="${pStyle}border:1px solid ${color}40;">
620 <div style="color:${color};font-size:12px;font-weight:700;margin-bottom:4px;">☢️ ${p.name}</div>
621 <div style="font-size:9px;color:#aaa;margin-bottom:8px;">${p.city}, ${p.country}</div>
622 <div style="display:grid;grid-template-columns:1fr;gap:4px;font-size:11px;">
623 <div><span style="color:#5C5A54;font-size:9px;">READING</span><br/><span style="color:${color};font-weight:bold;">${p.reading} nSv/h</span></div>
624 <div><span style="color:#5C5A54;font-size:9px;">STATUS</span><br/><span style="color:${color};">${p.status}</span></div>
625 <div><span style="color:#5C5A54;font-size:9px;">NETWORK</span><br/><span style="color:#E8E6E0;">${p.network}</span></div>
626 </div>
627 </div>`);
628 });
629
630 // ── Maritime Ships ──
631 map.on('click', 'ship-dots', e => {
632 if (!e.features?.length) return;
633 const p = e.features[0].properties as any;
634 const coords = (e.features[0].geometry as any).coordinates;
635 const color = p.type === 'military' ? '#FF1744' : p.type === 'tanker' ? '#FF9500' : '#00BCD4';
636 popup(coords, `<div style="${pStyle}border:1px solid ${color}40;">
637 <div style="display:flex;justify-content:space-between;margin-bottom:4px;">
638 <span style="color:${color};font-size:12px;font-weight:700;letter-spacing:0.1em;">🚢 ${p.name}</span>
639 <span style="color:#aaa;font-size:9px;">${p.flag}</span>
640 </div>
641 <div style="display:grid;grid-template-columns:1fr 1fr;gap:4px;font-size:9px;">
642 <div><span style="color:#5C5A54;">TYPE</span><br/><span style="color:${color};">${p.type.toUpperCase()}</span></div>
643 <div><span style="color:#5C5A54;">SPEED</span><br/><span style="color:#E8E6E0;">${p.speed} knots</span></div>
644 <div><span style="color:#5C5A54;">HEADING</span><br/><span style="color:#E8E6E0;">${p.heading}°</span></div>
645 <div><span style="color:#5C5A54;">DEST</span><br/><span style="color:#E8E6E0;">${p.destination || 'UNKNOWN'}</span></div>
646 </div>
647 </div>`);
648 });
649
650 // ── Weather Events (NASA EONET) ──
651 map.on('click', 'weather-dots', e => {
652 if (!e.features?.length) return;
653 const p = e.features[0].properties as any;
654 const coords = (e.features[0].geometry as any).coordinates;
655 const iconEmoji = p.icon === 'cyclone' ? '🌀' : p.icon === 'volcano' ? '🌋' : '⚡';
656 popup(coords, `<div style="${pStyle}border:1px solid rgba(224,64,251,0.3);">
657 <div style="color:#E040FB;font-size:14px;font-weight:700;margin-bottom:6px;">${iconEmoji} ${p.type || 'Weather Event'}</div>
658 <div style="font-size:10px;color:#E8E6E0;margin-bottom:8px;line-height:1.4;">${p.title || 'Unknown event'}</div>
659 <div style="display:grid;grid-template-columns:1fr 1fr;gap:4px;font-size:9px;margin-bottom:8px;">
660 <div><span style="color:#5C5A54;">SEVERITY</span><br/><span style="color:${p.severity === 'high' ? '#FF1744' : '#FFD700'};">${(p.severity||'low').toUpperCase()}</span></div>
661 <div><span style="color:#5C5A54;">COORDS</span><br/><span style="color:#E8E6E0;">${coords[1].toFixed(3)}°, ${coords[0].toFixed(3)}°</span></div>
662 </div>
663 <div style="display:flex;gap:6px;">
664 ${p.source ? `<a href="${p.source}" target="_blank" style="${linkStyle}color:#E040FB;border:1px solid rgba(224,64,251,0.4);background:rgba(224,64,251,0.1);">📡 SOURCE</a>` : ''}
665 <a href="https://eonet.gsfc.nasa.gov/api/v3/events/${p.id || ''}" target="_blank" style="${linkStyle}color:#D4AF37;border:1px solid rgba(212,175,55,0.4);background:rgba(212,175,55,0.1);">🛰️ NASA EONET</a>
666 </div>
667 </div>`);
668 });
669
670 // ── Nuclear Infrastructure ──
671 map.on('click', 'infra-dots', e => {
672 if (!e.features?.length) return;
673 const p = e.features[0].properties as any;
674 const coords = (e.features[0].geometry as any).coordinates;
675 const statusColor = p.status === 'Active Conflict Zone' ? '#FF1744' : p.status === 'Operational' ? '#76FF03' : '#757575';
676 popup(coords, `<div style="${pStyle}border:1px solid rgba(118,255,3,0.3);">
677 <div style="color:#76FF03;font-size:14px;font-weight:700;margin-bottom:4px;">☢️ ${p.name || 'Nuclear Facility'}</div>
678 <div style="display:grid;grid-template-columns:1fr 1fr;gap:6px;font-size:9px;margin-bottom:8px;">
679 <div><span style="color:#5C5A54;">STATUS</span><br/><span style="color:${statusColor};">${p.status || '—'}</span></div>
680 <div><span style="color:#5C5A54;">CITY</span><br/><span style="color:#E8E6E0;">${p.city || '—'}, ${p.country || ''}</span></div>
681 <div><span style="color:#5C5A54;">REACTORS</span><br/><span style="color:#76FF03;">${p.reactors || '—'}</span></div>
682 <div><span style="color:#5C5A54;">CAPACITY</span><br/><span style="color:#E8E6E0;">${p.capacityMW ? p.capacityMW.toLocaleString() + ' MW' : '—'}</span></div>
683 <div><span style="color:#5C5A54;">OWNER</span><br/><span style="color:#E8E6E0;">${p.owner || '—'}</span></div>
684 <div><span style="color:#5C5A54;">COORDS</span><br/><span style="color:#E8E6E0;">${coords[1].toFixed(3)}°, ${coords[0].toFixed(3)}°</span></div>
685 </div>
686 <a href="https://www.google.com/maps/@${coords[1]},${coords[0]},14z/data=!3m1!1e3" target="_blank" style="${linkStyle}color:#76FF03;border:1px solid rgba(118,255,3,0.4);background:rgba(118,255,3,0.1);">SATELLITE VIEW</a>
687 </div>`);
688 });
689
690 // ── Maritime Ports & Naval Bases ──
691 map.on('click', 'maritime-dots', e => {
692 const p = e.features?.[0]?.properties;
693 if (!p) return;
694 const coords = (e.features![0].geometry as any).coordinates;
695 const typeColor = p.type === 'naval' ? '#FF3D3D' : p.type === 'energy' ? '#FF9500' : '#00BCD4';
696 const typeLabel = p.type === 'naval' ? 'NAVAL BASE' : p.type === 'energy' ? 'ENERGY PORT' : 'CONTAINER PORT';
697 popup(coords, `<div style="${pStyle}border:1px solid ${typeColor}40;">
698 <div style="color:${typeColor};font-weight:bold;font-size:11px;margin-bottom:4px;">${p.name}</div>
699 <div style="color:#999;font-size:9px;margin-bottom:6px;">${typeLabel} — ${p.country}</div>
700 ${p.volume ? `<div style="font-size:9px;color:#aaa;">Volume: <span style="color:${typeColor};font-weight:bold;">${p.volume}</span></div>` : ''}
701 ${p.fleet ? `<div style="font-size:9px;color:#aaa;">Fleet: <span style="color:${typeColor};font-weight:bold;">${p.fleet}</span></div>` : ''}
702 ${p.rank ? `<div style="font-size:9px;color:#aaa;">Global Rank: <span style="color:${typeColor};font-weight:bold;">#${p.rank}</span></div>` : ''}
703 </div>`);
704 });
705
706 // ── Maritime Chokepoints ──
707 map.on('click', 'choke-dots', e => {
708 const p = e.features?.[0]?.properties;
709 if (!p) return;
710 const coords = (e.features![0].geometry as any).coordinates;
711 const riskCol = p.risk === 'CRITICAL' ? '#FF1744' : p.risk === 'HIGH' ? '#FF9500' : p.risk === 'ELEVATED' ? '#FFD700' : '#00E676';
712 popup(coords, `<div style="${pStyle}border:1px solid ${riskCol}40;">
713 <div style="color:#FF9500;font-weight:bold;font-size:11px;margin-bottom:4px;">${p.name}</div>
714 <div style="font-size:9px;color:#aaa;">Traffic: <span style="color:#fff;">${p.traffic}</span></div>
715 <div style="font-size:9px;color:#aaa;">Risk: <span style="color:${riskCol};font-weight:bold;">${p.risk}</span></div>
716 </div>`);
717 });
718
719 // ── Live News (opens feed viewer) ──
720 map.on('click', 'news-dots', e => {
721 const p = e.features?.[0]?.properties;
722 if (!p) return;
723 onEntityClick?.({
724 type: 'live_news',
725 name: p.name,
726 city: p.city,
727 country: p.country,
728 url: p.url,
729 category: p.category,
730 embed_allowed: p.embed_allowed !== false && p.embed_allowed !== 'false',
731 });
732 });
733
734 return () => { map.remove(); mapRef.current = null; };
735 }, []);
736
737 // Day/Night
738 useEffect(() => {
739 if (!mapReady || !mapRef.current) return;
740 const map = mapRef.current;
741 const update = () => {
742 const src = map.getSource('day-night') as any;
743 if (!src) return;
744 if (!activeLayers.day_night) { src.setData(EMPTY_FC); return; }
745 src.setData({ type: 'FeatureCollection', features: [{ type: 'Feature', geometry: { type: 'Polygon', coordinates: [computeSolarTerminator()] }, properties: {} }] });
746 };
747 update();
748 const iv = setInterval(update, 300000); // 5 min (was 1 min — shadow barely moves)
749 return () => clearInterval(iv);
750 }, [mapReady, activeLayers.day_night]);
751
752 // Helper to set GeoJSON
753 const setGeo = useCallback((source: string, features: any[]) => {
754 const src = mapRef.current?.getSource(source) as any;
755 if (src) src.setData({ type: 'FeatureCollection', features });
756 }, []);
757
758 const setVis = useCallback((ids: string[], visible: boolean) => {
759 const map = mapRef.current;
760 if (!map) return;
761 ids.forEach(id => { if (map.getLayer(id)) map.setLayoutProperty(id, 'visibility', visible ? 'visible' : 'none'); });
762 }, []);
763
764 // Flight data → GeoJSON (GPU rendered)
765 useEffect(() => {
766 if (!mapReady) return;
767 const toFeatures = (arr: any[]) => (arr || []).map((f: any) => ({
768 type: 'Feature' as const, geometry: { type: 'Point' as const, coordinates: [f.lng, f.lat] },
769 properties: { callsign: f.callsign, heading: f.heading || 0, alt: f.alt, model: f.model, speed_knots: f.speed_knots, registration: f.registration, icao24: f.icao24 },
770 }));
771 setGeo('flights', activeLayers.flights ? toFeatures(data.commercial_flights) : []);
772 setGeo('private-fl', activeLayers.private ? toFeatures(data.private_flights) : []);
773 setGeo('jets', activeLayers.jets ? toFeatures(data.private_jets) : []);
774 setGeo('military', activeLayers.military ? toFeatures(data.military_flights) : []);
775 }, [mapReady, data.commercial_flights, data.private_flights, data.private_jets, data.military_flights, activeLayers.flights, activeLayers.private, activeLayers.jets, activeLayers.military]);
776
777 // ── DECOUPLED LAYER RENDERERS (Performance Optimized) ──
778
779 useEffect(() => {
780 if (!mapReady) return;
781 setGeo('earthquakes', activeLayers.earthquakes && data.earthquakes ? data.earthquakes.map((eq: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [eq.lng, eq.lat] }, properties: { magnitude: eq.magnitude, place: eq.place } })) : []);
782 }, [mapReady, data.earthquakes, activeLayers.earthquakes, setGeo]);
783
784 useEffect(() => {
785 if (!mapReady) return;
786 setGeo('satellites', activeLayers.satellites && data.satellites ? data.satellites.map((s: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [s.lng, s.lat] }, properties: { name: s.name, color: s.color, mission: s.mission } })) : []);
787 }, [mapReady, data.satellites, activeLayers.satellites, setGeo]);
788
789 useEffect(() => {
790 if (!mapReady) return;
791 setGeo('gdelt', activeLayers.global_incidents && data.gdelt ? data.gdelt.map((e: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [e.lng, e.lat] }, properties: { name: e.name } })) : []);
792 }, [mapReady, data.gdelt, activeLayers.global_incidents, setGeo]);
793
794 useEffect(() => {
795 if (!mapReady) return;
796 setGeo('gps-jamming', activeLayers.gps_jamming && data.gps_jamming ? data.gps_jamming.map((z: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [z.lng, z.lat] }, properties: { severity: z.severity } })) : []);
797 }, [mapReady, data.gps_jamming, activeLayers.gps_jamming, setGeo]);
798
799 useEffect(() => {
800 if (!mapReady) return;
801 setGeo('cctv', activeLayers.cctv && data.cameras ? data.cameras.map((c: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [c.lng, c.lat] }, properties: { id: c.id, name: c.name, city: c.city, country: c.country, source: c.source, feed_url: c.feed_url, stream_url: c.stream_url, stream_type: c.stream_type, external_url: c.external_url } })) : []);
802 }, [mapReady, data.cameras, activeLayers.cctv, setGeo]);
803
804 useEffect(() => {
805 if (!mapReady) return;
806 setGeo('fires', activeLayers.fires && data.fires ? data.fires.map((f: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [f.lng, f.lat] }, properties: { brightness: f.brightness } })) : []);
807 }, [mapReady, data.fires, activeLayers.fires, setGeo]);
808
809 useEffect(() => {
810 if (!mapReady) return;
811 setGeo('weather', activeLayers.weather && data.weather_events ? data.weather_events.map((w: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [w.lng, w.lat] }, properties: { title: w.title, type: w.type, icon: w.icon, severity: w.severity, source: w.source, id: w.id } })) : []);
812 }, [mapReady, data.weather_events, activeLayers.weather, setGeo]);
813
814 useEffect(() => {
815 if (!mapReady) return;
816 setGeo('infrastructure', activeLayers.infrastructure && data.infrastructure ? data.infrastructure.map((i: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [i.lng, i.lat] }, properties: { name: i.name, city: i.city, country: i.country, status: i.status, reactors: i.reactors, capacityMW: i.capacityMW, owner: i.owner } })) : []);
817 }, [mapReady, data.infrastructure, activeLayers.infrastructure, setGeo]);
818
819 useEffect(() => {
820 if (!mapReady) return;
821 setGeo('maritime', activeLayers.maritime && data.maritime_ports ? data.maritime_ports.map((p: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [p.lng, p.lat] }, properties: { name: p.name, country: p.country, type: p.type, volume: p.volume, fleet: p.fleet, rank: p.rank } })) : []);
822 setGeo('maritime-choke', activeLayers.maritime && data.maritime_chokepoints ? data.maritime_chokepoints.map((c: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [c.lng, c.lat] }, properties: { name: c.name, traffic: c.traffic, risk: c.risk } })) : []);
823 setGeo('maritime-ships', activeLayers.maritime && data.maritime_ships ? data.maritime_ships.map((s: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [s.lng, s.lat] }, properties: { name: s.name, type: s.type, speed: s.speed, heading: s.heading, destination: s.destination, flag: s.flag } })) : []);
824 }, [mapReady, data.maritime_ports, data.maritime_chokepoints, data.maritime_ships, activeLayers.maritime, setGeo]);
825
826 useEffect(() => {
827 if (!mapReady) return;
828 setGeo('balloons', activeLayers.balloons && data.balloons ? data.balloons.map((b: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [b.lng, b.lat] }, properties: { callsign: b.callsign, type: b.type, status: b.status, altitude: b.altitude, speed: b.speed, verticalRate: b.verticalRate, temperature: b.temperature, color: b.color } })) : []);
829 }, [mapReady, data.balloons, activeLayers.balloons, setGeo]);
830
831 useEffect(() => {
832 if (!mapReady) return;
833 setGeo('radiation', activeLayers.radiation && data.radiation ? data.radiation.map((r: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [r.lng, r.lat] }, properties: { name: r.name, city: r.city, country: r.country, reading: r.reading, status: r.status, network: r.network } })) : []);
834 }, [mapReady, data.radiation, activeLayers.radiation, setGeo]);
835
836 useEffect(() => {
837 if (!mapReady) return;
838 setGeo('live-news', activeLayers.live_news && data.live_feeds ? data.live_feeds.map((f: any) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [f.lng, f.lat] }, properties: { name: f.name, city: f.city, country: f.country, url: f.url, category: f.category, embed_allowed: f.embed_allowed !== false } })) : []);
839 }, [mapReady, data.live_feeds, activeLayers.live_news, setGeo]);
840
841 useEffect(() => {
842 if (!mapReady) return;
843 const items = data.news || [];
844 setGeo('sigint-news', activeLayers.news_intel && items.length > 0
845 ? items.filter((n: any) => n.coords?.length === 2).map((n: any) => ({
846 type: 'Feature',
847 geometry: { type: 'Point', coordinates: [n.coords[1], n.coords[0]] },
848 properties: { title: n.title, source: n.source, risk_score: n.risk_score, link: n.link }
849 }))
850 : []);
851 }, [mapReady, data.news, activeLayers.news_intel, setGeo]);
852
853 useEffect(() => {
854 if (!mapReady) return;
855 // ── CONFLICT ZONES — center-point warning markers ──
856 const CONFLICT_ZONES = [
857 { label: 'UKRAINE WAR', severity: 'war', lat: 48.5, lng: 31.2 },
858 { label: 'GAZA CONFLICT', severity: 'war', lat: 31.35, lng: 34.35 },
859 { label: 'LEBANON BORDER', severity: 'high', lat: 33.4, lng: 35.8 },
860 { label: 'SUDAN CIVIL WAR', severity: 'war', lat: 15.0, lng: 30.0 },
861 { label: 'MYANMAR CONFLICT', severity: 'war', lat: 19.5, lng: 96.5 },
862 { label: 'DRC EASTERN CONFLICT', severity: 'war', lat: -1.0, lng: 28.5 },
863 { label: 'YEMEN WAR', severity: 'war', lat: 15.5, lng: 48.0 },
864 { label: 'SYRIA', severity: 'high', lat: 35.0, lng: 38.5 },
865 { label: 'TAIWAN STRAIT', severity: 'elevated', lat: 24.0, lng: 119.5 },
866 { label: 'KOREAN DMZ', severity: 'elevated', lat: 38.3, lng: 127.0 },
867 { label: 'SAHEL INSTABILITY', severity: 'high', lat: 14.0, lng: 5.0 },
868 { label: 'SOMALIA', severity: 'high', lat: 5.0, lng: 46.0 },
869 { label: 'RED SEA THREAT', severity: 'high', lat: 16.0, lng: 40.0 },
870 ];
871 const conflictFeatures = CONFLICT_ZONES.map(z => ({
872 type: 'Feature' as const,
873 geometry: { type: 'Point' as const, coordinates: [z.lng, z.lat] },
874 properties: { label: z.label, severity: z.severity },
875 }));
876 setGeo('conflict-zones', conflictFeatures);
877 }, [mapReady, setGeo]);
878
879
880 // Visibility
881 useEffect(() => {
882 if (!mapReady) return;
883 setVis(['eq-circles','eq-label'], activeLayers.earthquakes);
884 setVis(['sat-dots'], activeLayers.satellites);
885 setVis(['gdelt-dots'], activeLayers.global_incidents);
886 setVis(['jam-fill','jam-label'], activeLayers.gps_jamming);
887 setVis(['day-night-fill'], activeLayers.day_night);
888 setVis(['fl-commercial'], activeLayers.flights);
889 setVis(['fl-private'], activeLayers.private);
890 setVis(['fl-jets'], activeLayers.jets);
891 setVis(['fl-military'], activeLayers.military);
892 setVis(['cctv-glow','cctv-dots','cctv-label'], activeLayers.cctv);
893 setVis(['fires-heat'], activeLayers.fires);
894 setVis(['weather-glow','weather-dots','weather-label'], activeLayers.weather);
895 setVis(['infra-glow','infra-dots','infra-label'], activeLayers.infrastructure);
896 setVis(['maritime-glow','maritime-dots','maritime-label'], activeLayers.maritime);
897 setVis(['choke-glow','choke-dots','choke-label'], activeLayers.maritime);
898 setVis(['ship-dots','ship-label'], activeLayers.maritime);
899 setVis(['news-glow','news-dots','news-label'], activeLayers.live_news);
900 setVis(['sigint-news-glow','sigint-news-dots','sigint-news-label'], activeLayers.news_intel);
901 setVis(['conflict-icons'], activeLayers.conflict_zones !== false);
902
903 setVis(['balloon-dots','balloon-label'], activeLayers.balloons);
904 setVis(['rad-glow','rad-dots','rad-label'], activeLayers.radiation);
905 // Sweep layers always visible when data is present (controlled by useEffect)
906 setVis(['sweep-connections','sweep-pulse-ring','sweep-device-glow','sweep-device-dots','sweep-device-labels'], true);
907 }, [mapReady, activeLayers, setVis]);
908
909 // IP Sweep visualization
910 useEffect(() => {
911 if (!mapReady) return;
912 if (!sweepData?.devices?.length) {
913 setGeo('ip-sweep-devices', []);
914 setGeo('ip-sweep-pulse', []);
915 setGeo('ip-sweep-connections', []);
916 return;
917 }
918
919 const map = mapRef.current;
920 if (!map) return;
921
922 const { center, devices } = sweepData;
923 const centerCoord: [number, number] = [center.lng, center.lat];
924
925 // Switch to globe and fly to the sweep location
926 try {
927 (map as any).setProjection({ type: 'globe' });
928 map.setSky({ 'sky-color': '#0A0A0F', 'sky-horizon-blend': 0.02, 'horizon-color': '#0A0A0F', 'horizon-fog-blend': 0.02 });
929 } catch { /* projection may not be supported */ }
930
931 map.flyTo({ center: centerCoord, zoom: 14, pitch: 50, bearing: -20, duration: 3000, essential: true });
932
933 // Set center pulse
934 setGeo('ip-sweep-pulse', [{
935 type: 'Feature' as const,
936 geometry: { type: 'Point' as const, coordinates: centerCoord },
937 properties: { ip: sweepData.target_ip },
938 }]);
939
940 // Build device features spread in a circle around center
941 const allDeviceFeatures = devices.map((d: any, i: number) => {
942 const angle = (i / devices.length) * Math.PI * 2;
943 const radius = 0.001 + (Math.random() * 0.003);
944 const dLng = centerCoord[0] + Math.cos(angle) * radius * (1 / Math.cos(center.lat * Math.PI / 180));
945 const dLat = centerCoord[1] + Math.sin(angle) * radius;
946 return {
947 type: 'Feature' as const,
948 geometry: { type: 'Point' as const, coordinates: [dLng, dLat] },
949 properties: {
950 ip: d.ip, device_type: d.device_type, device_icon: d.device_icon,
951 color: d.device_color, risk_level: d.risk_level,
952 ports: JSON.stringify(d.ports), hostnames: JSON.stringify(d.hostnames),
953 vulns: JSON.stringify(d.vulns), cpes: JSON.stringify(d.cpes), tags: JSON.stringify(d.tags),
954 },
955 };
956 });
957
958 // Connection lines from center to each device
959 const connectionFeatures = allDeviceFeatures.map((f: any) => ({
960 type: 'Feature' as const,
961 geometry: { type: 'LineString' as const, coordinates: [centerCoord, f.geometry.coordinates] },
962 properties: { color: f.properties.color },
963 }));
964
965 // Stagger the appearance after 3s flyTo completes
966 const timer = setTimeout(() => {
967 setGeo('ip-sweep-connections', connectionFeatures);
968 const batchSize = 5;
969 const batches = Math.ceil(allDeviceFeatures.length / batchSize);
970 for (let b = 0; b < batches; b++) {
971 setTimeout(() => {
972 setGeo('ip-sweep-devices', allDeviceFeatures.slice(0, (b + 1) * batchSize));
973 }, b * 100);
974 }
975 }, 3000);
976
977 return () => clearTimeout(timer);
978 }, [mapReady, sweepData, setGeo]);
979
980 // Fly-to
981 useEffect(() => {
982 if (!mapReady || !mapRef.current || !flyToLocation) return;
983 mapRef.current.flyTo({ center: [flyToLocation.lng, flyToLocation.lat], zoom: 8, duration: 2000 });
984 }, [mapReady, flyToLocation]);
985
986 // Dynamic projection switching (lightweight — no terrain DEM)
987 useEffect(() => {
988 if (!mapReady || !mapRef.current) return;
989 const map = mapRef.current;
990 try {
991 (map as any).setProjection({ type: projection });
992 if (projection === 'globe') {
993 map.easeTo({ pitch: 20, duration: 1200 });
994 try {
995 (map as any).setSky({
996 'sky-color': '#04040A',
997 'sky-horizon-blend': 0.5,
998 'horizon-color': '#0a0a1a',
999 'horizon-fog-blend': 0.3,
1000 'fog-color': '#04040A',
1001 'fog-ground-blend': 0.9,
1002 });
1003 } catch (e) { console.warn('[OSIRIS] Suppressed error:', e instanceof Error ? e.message : e); }
1004 } else {
1005 map.easeTo({ pitch: 0, duration: 800 });
1006 }
1007 } catch (e) {
1008 console.warn('Projection switch failed:', e);
1009 }
1010 }, [mapReady, projection]);
1011
1012 // Satellite / Dark style switching
1013 useEffect(() => {
1014 if (!mapReady || !mapRef.current) return;
1015 if (mapStyle === prevStyleRef.current) return;
1016 prevStyleRef.current = mapStyle;
1017 const map = mapRef.current;
1018
1019 try {
1020 if (mapStyle !== 'dark') {
1021 // Add satellite raster tiles
1022 if (!map.getSource('satellite-tiles')) {
1023 map.addSource('satellite-tiles', {
1024 type: 'raster',
1025 tiles: ['https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'],
1026 tileSize: 256,
1027 maxzoom: 18,
1028 });
1029 map.addLayer({ id: 'satellite-layer', type: 'raster', source: 'satellite-tiles', paint: { 'raster-opacity': 0.85 } }, 'day-night-fill');
1030 } else {
1031 map.setLayoutProperty('satellite-layer', 'visibility', 'visible');
1032 }
1033 } else {
1034 if (map.getLayer('satellite-layer')) {
1035 map.setLayoutProperty('satellite-layer', 'visibility', 'none');
1036 }
1037 }
1038 } catch (e) {
1039 console.warn('Style switch failed:', e);
1040 }
1041 }, [mapReady, mapStyle]);
1042
1043 return <div ref={containerRef} className="absolute inset-0 w-full h-full" />;
1044}
1045
1046export default memo(OsirisMap);