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