Real-time dashboard for monitoring global news, markets, and geopolitical events
TypeScript
Add weather alerts to map
Reggief0d075ef6f4a
diff --git a/index.html b/index.htmlindex 44663e9..d105dde 100644--- a/index.html+++ b/index.html@@ -83,9 +83,10 @@<div class="panel-header"><span class="panel-title">Global Activity Monitor</span><span class="panel-count" id="mapLegend">- <span style="color: var(--green);">● Low</span>- <span style="color: var(--yellow); margin-left: 0.5rem;">● Elevated</span>- <span style="color: var(--red); margin-left: 0.5rem;">● High</span>+ <span style="color: #00ff88;">● Low</span>+ <span style="color: #ffcc00; margin-left: 0.5rem;">● Elevated</span>+ <span style="color: #ff4444; margin-left: 0.5rem;">● High</span>+ <span style="color: #ff6600; margin-left: 0.5rem;">▲ Weather</span></span></div><div class="panel-content" id="mapPanel" style="max-height: none; height: 550px; overflow: hidden; background: #0a1a14; position: relative;">@@ -156,8 +157,14 @@50% { r: 6; opacity: 0.4; }100% { r: 3; opacity: 0.9; }}+ @keyframes weatherPulse {+ 0% { opacity: 0.9; }+ 50% { opacity: 0.5; }+ 100% { opacity: 0.9; }+ }.hotspot-pulse { animation: pulse 2s ease-in-out infinite; }.hotspot-hit { cursor: pointer; }+ .weather-alert { animation: weatherPulse 1.5s ease-in-out infinite; }`;document.head.appendChild(style);@@ -205,6 +212,108 @@});}});++ // Fetch and render weather alerts (US - NWS API)+ try {+ const weatherRes = await fetch('https://api.weather.gov/alerts/active?status=actual&severity=Extreme,Severe');+ const weatherData = await weatherRes.json();++ // Weather severity colors+ const weatherColors = {+ 'Extreme': '#ff0000',+ 'Severe': '#ff6600',+ 'Moderate': '#ffaa00',+ 'Minor': '#ffcc00'+ };++ // US state centroids for positioning alerts+ const stateCentroids = {+ 'AL': [32.7, -86.7], 'AK': [64.0, -153.0], 'AZ': [34.2, -111.6], 'AR': [34.8, -92.4],+ 'CA': [37.2, -119.4], 'CO': [39.0, -105.5], 'CT': [41.6, -72.7], 'DE': [39.0, -75.5],+ 'FL': [28.6, -82.4], 'GA': [32.6, -83.4], 'HI': [20.8, -156.3], 'ID': [44.4, -114.6],+ 'IL': [40.0, -89.2], 'IN': [39.9, -86.3], 'IA': [42.0, -93.5], 'KS': [38.5, -98.4],+ 'KY': [37.5, -85.3], 'LA': [31.0, -92.0], 'ME': [45.4, -69.2], 'MD': [39.0, -76.8],+ 'MA': [42.2, -71.5], 'MI': [44.3, -85.4], 'MN': [46.3, -94.3], 'MS': [32.7, -89.7],+ 'MO': [38.3, -92.4], 'MT': [47.0, -109.6], 'NE': [41.5, -99.8], 'NV': [39.3, -116.6],+ 'NH': [43.7, -71.6], 'NJ': [40.1, -74.7], 'NM': [34.4, -106.1], 'NY': [42.9, -75.5],+ 'NC': [35.5, -79.4], 'ND': [47.4, -100.3], 'OH': [40.4, -82.8], 'OK': [35.6, -97.5],+ 'OR': [43.9, -120.6], 'PA': [40.9, -77.8], 'RI': [41.7, -71.5], 'SC': [33.9, -80.9],+ 'SD': [44.4, -100.2], 'TN': [35.9, -86.4], 'TX': [31.5, -99.4], 'UT': [39.3, -111.7],+ 'VT': [44.0, -72.7], 'VA': [37.5, -78.8], 'WA': [47.4, -120.5], 'WV': [38.9, -80.5],+ 'WI': [44.6, -89.7], 'WY': [43.0, -107.5], 'DC': [38.9, -77.0], 'PR': [18.2, -66.4]+ };++ // Group alerts by state to avoid clutter+ const alertsByState = {};+ weatherData.features?.forEach(alert => {+ const props = alert.properties;+ const state = props.areaDesc?.match(/,\s*([A-Z]{2})(?:\s|$|;)/)?.[1] ||+ props.senderName?.match(/([A-Z]{2})$/)?.[1];+ if (state && stateCentroids[state]) {+ if (!alertsByState[state] ||+ (props.severity === 'Extreme' && alertsByState[state].severity !== 'Extreme')) {+ alertsByState[state] = {+ state,+ severity: props.severity,+ event: props.event,+ headline: props.headline,+ description: props.description?.substring(0, 200) + '...',+ count: (alertsByState[state]?.count || 0) + 1+ };+ } else {+ alertsByState[state].count++;+ }+ }+ });++ // Draw weather alerts as triangles+ Object.values(alertsByState).forEach(alert => {+ const coords = stateCentroids[alert.state];+ if (!coords) return;+ const [x, y] = projection([coords[1], coords[0]]);+ const color = weatherColors[alert.severity] || '#ffaa00';++ if (x && y) {+ // Triangle warning symbol+ const size = 6;+ const triangle = `M${x},${y-size} L${x+size},${y+size/2} L${x-size},${y+size/2} Z`;++ svg.append('path')+ .attr('d', triangle)+ .attr('fill', color)+ .attr('stroke', '#000')+ .attr('stroke-width', 0.5)+ .attr('class', 'weather-alert');++ // Hit area for tooltip+ svg.append('circle')+ .attr('cx', x).attr('cy', y).attr('r', 10)+ .attr('fill', 'transparent')+ .attr('class', 'hotspot-hit')+ .on('mouseenter', function(event) {+ const rect = mapPanel.getBoundingClientRect();+ const countText = alert.count > 1 ? ` (+${alert.count - 1} more)` : '';+ tooltip.innerHTML = `<strong style="color:${color}">⚠ ${alert.event}</strong>${countText}<br>${alert.headline || alert.state}`;+ tooltip.style.display = 'block';+ tooltip.style.left = (event.clientX - rect.left + 15) + 'px';+ tooltip.style.top = (event.clientY - rect.top - 10) + 'px';+ })+ .on('mousemove', function(event) {+ const rect = mapPanel.getBoundingClientRect();+ tooltip.style.left = (event.clientX - rect.left + 15) + 'px';+ tooltip.style.top = (event.clientY - rect.top - 10) + 'px';+ })+ .on('mouseleave', function() {+ tooltip.style.display = 'none';+ });+ }+ });++ console.log(`Loaded ${Object.keys(alertsByState).length} weather alert regions`);+ } catch(weatherErr) {+ console.log('Weather alerts unavailable:', weatherErr.message);+ }+} catch(e) {console.error('Map error:', e);}