| 1 | /** |
| 2 | * Balkans-focused data sources for OSIRIS. |
| 3 | * NIGGG-BAS (seismic), GDACS (EU civil protection), BG news feeds. |
| 4 | */ |
| 5 | |
| 6 | export const BALKANS_BBOX = { |
| 7 | minLat: 39.5, |
| 8 | maxLat: 46.5, |
| 9 | minLng: 19.5, |
| 10 | maxLng: 30.5, |
| 11 | }; |
| 12 | |
| 13 | export const BULGARIA_BBOX = { |
| 14 | minLat: 41.2, |
| 15 | maxLat: 44.5, |
| 16 | minLng: 22.0, |
| 17 | maxLng: 29.0, |
| 18 | }; |
| 19 | |
| 20 | export const DEFAULT_MAP_CENTER: [number, number] = [25.484, 42.698]; // Sofia - Balkans startup view |
| 21 | export const DEFAULT_MAP_ZOOM = 6.5; |
| 22 | |
| 23 | export function inBbox( |
| 24 | lat: number, |
| 25 | lng: number, |
| 26 | bbox: { minLat: number; maxLat: number; minLng: number; maxLng: number } = BALKANS_BBOX, |
| 27 | ): boolean { |
| 28 | return lat >= bbox.minLat && lat <= bbox.maxLat && lng >= bbox.minLng && lng <= bbox.maxLng; |
| 29 | } |
| 30 | |
| 31 | export interface NigggEarthquake { |
| 32 | id: string; |
| 33 | lat: number; |
| 34 | lng: number; |
| 35 | depth: number; |
| 36 | magnitude: number; |
| 37 | place: string; |
| 38 | time: number; |
| 39 | url: string; |
| 40 | source: 'NIGGG-BAS'; |
| 41 | } |
| 42 | |
| 43 | export function parseNigggXml(xml: string): NigggEarthquake[] { |
| 44 | const events: NigggEarthquake[] = []; |
| 45 | const markerRegex = /<marker\b([^>]*)\/>/gi; |
| 46 | let match: RegExpExecArray | null; |
| 47 | |
| 48 | while ((match = markerRegex.exec(xml)) !== null) { |
| 49 | const attrs = match[1]; |
| 50 | const get = (name: string) => { |
| 51 | const m = attrs.match(new RegExp(`${name}="([^"]*)"`)); |
| 52 | return m?.[1] ?? ''; |
| 53 | }; |
| 54 | |
| 55 | const lat = parseFloat(get('lat')); |
| 56 | const lng = parseFloat(get('lng')); |
| 57 | const mag = parseFloat(get('mag') || get('magnitude') || '0'); |
| 58 | const depth = parseFloat(get('depth') || '0'); |
| 59 | const time = get('time') || get('date') || ''; |
| 60 | const place = get('title') || get('place') || 'Bulgaria region'; |
| 61 | const id = get('id') || `niggg-${Date.now()}-${Math.random()}`; |
| 62 | |
| 63 | if (isNaN(lat) || isNaN(lng)) continue; |
| 64 | |
| 65 | events.push({ |
| 66 | id, |
| 67 | lat, |
| 68 | lng, |
| 69 | depth, |
| 70 | magnitude: mag, |
| 71 | place, |
| 72 | time: time ? new Date(time).getTime() : Date.now(), |
| 73 | url: 'https://ndc.niggg.bas.bg/', |
| 74 | source: 'NIGGG-BAS', |
| 75 | }); |
| 76 | } |
| 77 | |
| 78 | return events; |
| 79 | } |
| 80 | |
| 81 | export const BG_NEWS_FEEDS = [ |
| 82 | { name: 'Dnevnik', url: 'https://www.dnevnik.bg/rss/' }, |
| 83 | { name: 'Actualno', url: 'https://www.actualno.com/rss/actualno.xml' }, |
| 84 | { name: 'Mediapool', url: 'https://www.mediapool.bg/rss/' }, |
| 85 | { name: 'BBCEurope', url: 'https://feeds.bbci.co.uk/news/world/europe/rss.xml' }, |
| 86 | ]; |