# Live Flights - 3 Countries Feature

## 🌏 Overview

Multi-region live flight tracking untuk **Jakarta (Indonesia)**, **Dili (Timor-Leste)**, dan **Darwin (Australia)**.

Perfect untuk demo menunjukkan teknologi flight tracking across multiple countries dalam ASEAN region.

---

## 🚀 Akses

```
http://localhost:8888/bdr/anatl/live-flights-3countries.php
```

---

## 📊 3 Regions

### 1. 🇮🇩 Jakarta, Indonesia
- **Airport:** CGK (Soekarno-Hatta International)
- **Coordinates:** -6.1256, 106.6590
- **Coverage:** ~220km radius
- **Sample Flights:** 5
  - GA101 (Garuda Indonesia)
  - SQ112 (Singapore Airlines)
  - LA202 (LATAM)
  - MH001 (Malaysia Airlines)
  - QF008 (Qantas)

### 2. 🇹🇱 Dili, Timor-Leste
- **Airport:** DIL (Nicolau Lobato International)
- **Coordinates:** -8.5211, 125.0329
- **Coverage:** ~220km radius
- **Sample Flights:** 4
  - GA102 (Garuda Indonesia)
  - TT001 (Timor Airlines)
  - QF042 (Qantas)
  - JT601 (Batik Air)

### 3. 🇦🇺 Darwin, Australia
- **Airport:** DRW (Darwin International)
- **Coordinates:** -12.4634, 130.8456
- **Coverage:** ~220km radius
- **Sample Flights:** 5
  - QF001 (Qantas)
  - VH456 (Virgin Australia)
  - TNZ805 (Air New Zealand)
  - JQ750 (Jetstar)
  - SYD223 (Sydney bound)

---

## 🎯 Fitur

### Tab Navigation
- Click tab untuk switch antara Jakarta, Dili, Darwin
- Lihat flight count di setiap tab
- Automatic data refresh

### Statistics Display
```
✈️ Total Flights        - Jumlah aircraft terdeteksi
📊 Avg Altitude        - Rata-rata ketinggian (feet)
⚡ Avg Velocity        - Rata-rata kecepatan (m/s)
🛫 Flying              - Jumlah aircraft yang sedang terbang
```

### Detailed Flight Data
| Column | Description |
|--------|-------------|
| **Flight** | Callsign pesawat (e.g., GA101) |
| **Country** | Negara asal |
| **Lat/Lon** | Koordinat geografis |
| **Altitude** | Ketinggian dalam feet |
| **Velocity** | Kecepatan dalam m/s |
| **Track** | Heading/arah dalam degrees |
| **V/Rate** | Vertical rate (climbing/descending) |
| **Status** | Flying atau Ground |

---

## 📂 Files

### Main Files
- **`live-flights-3countries.php`** - Main page dengan tab navigation
- **`includes/sample-flights-multi.php`** - Sample data untuk 3 negara
- **`includes/opensky-api.php`** - OpenSky API wrapper (shared)

### Navigation
- Header updated dengan link "🌏 Live Flights 3"
- Link ke single region view (Jakarta)

---

## 🎨 UI Features

### Tab Navigation
```html
[🇮🇩 Jakarta (5)]  [🇹🇱 Dili (4)]  [🇦🇺 Darwin (5)]
```

### Color Coding
- **Jakarta:** Red (#FF0000) - ASEAN Hub
- **Dili:** Gold (#FFD700) - Timor-Leste
- **Darwin:** Blue (#0066CC) - Australia

### Statistics Cards
Real-time metrics:
- Total flights detected
- Average altitude
- Average velocity
- Number of flying aircraft

---

## 💻 Technical Implementation

### How It Works

```
1. User click tab (Jakarta/Dili/Darwin)
2. Page loads with ?tab=region parameter
3. System tries OpenSky API first
4. If no data → Use sample data
5. Display flights in table
6. Show statistics
```

### Data Flow

```
GET /live-flights-3countries.php?tab=jakarta

OpenSky API Request:
├─ Get flights in Jakarta bounds
├─ Get flights in Dili bounds
└─ Get flights in Darwin bounds

Fallback to Sample Data:
├─ getSampleFlightsJakarta()
├─ getSampleFlightsDili()
└─ getSampleFlightsDarwin()

Display Results:
├─ Render tab navigation
├─ Show selected region data
├─ Calculate statistics
└─ Render flights table
```

---

## 🔧 Customization

### Add Another Region

Edit `live-flights-3countries.php`:

```php
$regions = [
    'singapore' => [
        'name' => 'Singapore',
        'airport' => 'SIN (Changi)',
        'lat' => 1.3521,
        'lon' => 103.8198,
        'emoji' => '🇸🇬',
        'color' => '#FF0000',
    ],
    // ... more regions
];
```

Create sample data function in `sample-flights-multi.php`:

```php
function getSampleFlightsSingapore() {
    return [
        // flight data...
    ];
}
```

### Change Sample Flight Data

Edit `includes/sample-flights-multi.php` to modify:
- Callsigns
- Altitudes
- Velocities
- Coordinates

---

## 📈 Demo Use Cases

### Scenario 1: Show Flight Density Difference
```
Jakarta: 5 flights → Busiest hub
Dili:    4 flights → Medium traffic
Darwin:  5 flights → Equal traffic
```

### Scenario 2: Live Tracking Across Countries
```
Click tabs untuk lihat real-time tracking
Explain coverage di setiap region
Show aircraft moving between countries
```

### Scenario 3: Compare Flight Altitudes
```
Statistics card menunjukkan altitude differences
Jakarta: Lower average (regional flights)
Darwin: Higher average (international flights)
```

---

## ✅ Testing Checklist

- [x] All 3 regions show sample data
- [x] Tab switching works smoothly
- [x] Statistics update when tab changes
- [x] Flight count accurate per region
- [x] Responsive on mobile
- [x] Colors differentiate regions
- [x] Fallback to sample data works

---

## 🎓 For Classroom Demo

**Perfect untuk menunjukkan:**

1. **Multi-region tracking system**
   - Simulated real-time data
   - 14 total flights across 3 countries
   - Live statistics

2. **Data visualization**
   - Tab-based navigation
   - Flight tables with detailed info
   - Statistics cards

3. **Technology stack**
   - OpenSky Network API integration
   - Fallback to sample data
   - Responsive design

4. **Real-world application**
   - Airport traffic monitoring
   - Flight tracking system
   - Multi-country coordination

---

## 🚀 Production Enhancements

### Possible Improvements

1. **Real-time Updates (WebSocket)**
   ```js
   ws = new WebSocket('wss://opensky-network.org/socket.io');
   ws.onmessage = updateFlights;
   ```

2. **Map Integration**
   - Show flights on Leaflet/Mapbox
   - Interactive zoom per region
   - Draw flight paths

3. **Advanced Filtering**
   - Filter by airline
   - Filter by altitude range
   - Filter by velocity range

4. **Historical Data**
   - Compare with past hours
   - Peak traffic analysis
   - Route patterns

5. **Export Functionality**
   - CSV export
   - PDF reports
   - JSON API

---

**Multi-country live flight tracking siap untuk demo! 🌏✈️**
