2025-08-24 14:04:17 +02:00
|
|
|
// Aircraft marker and data management module
|
|
|
|
|
export class AircraftManager {
|
2025-08-31 19:43:58 +02:00
|
|
|
constructor(map, callsignManager = null) {
|
2025-08-24 14:04:17 +02:00
|
|
|
this.map = map;
|
2025-08-31 19:43:58 +02:00
|
|
|
this.callsignManager = callsignManager;
|
2025-08-24 14:04:17 +02:00
|
|
|
this.aircraftData = new Map();
|
|
|
|
|
this.aircraftMarkers = new Map();
|
|
|
|
|
this.aircraftTrails = new Map();
|
|
|
|
|
this.showTrails = false;
|
|
|
|
|
|
|
|
|
|
// Debug: Track marker lifecycle
|
|
|
|
|
this.markerCreateCount = 0;
|
|
|
|
|
this.markerUpdateCount = 0;
|
|
|
|
|
this.markerRemoveCount = 0;
|
|
|
|
|
|
2025-08-24 15:29:43 +02:00
|
|
|
// SVG icon cache
|
|
|
|
|
this.iconCache = new Map();
|
|
|
|
|
this.loadIcons();
|
|
|
|
|
|
2025-08-24 16:24:46 +02:00
|
|
|
// Selected aircraft trail tracking
|
|
|
|
|
this.selectedAircraftCallback = null;
|
|
|
|
|
|
2025-08-24 14:04:17 +02:00
|
|
|
// Map event listeners removed - let Leaflet handle positioning naturally
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-24 15:29:43 +02:00
|
|
|
async loadIcons() {
|
|
|
|
|
const iconTypes = ['commercial', 'helicopter', 'military', 'cargo', 'ga', 'ground'];
|
|
|
|
|
|
|
|
|
|
for (const type of iconTypes) {
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`/static/icons/${type}.svg`);
|
|
|
|
|
const svgText = await response.text();
|
|
|
|
|
this.iconCache.set(type, svgText);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.warn(`Failed to load icon for ${type}:`, error);
|
|
|
|
|
// Fallback to inline SVG if needed
|
|
|
|
|
this.iconCache.set(type, this.createFallbackIcon(type));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createFallbackIcon(type) {
|
|
|
|
|
// Fallback inline SVG if file loading fails
|
|
|
|
|
const color = 'currentColor';
|
|
|
|
|
let path = '';
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 'helicopter':
|
|
|
|
|
path = `<circle cx="0" cy="0" r="10" fill="none" stroke="${color}" stroke-width="1" opacity="0.3"/>
|
|
|
|
|
<path d="M0,-8 L-6,6 L-1,6 L0,8 L1,6 L6,6 Z" fill="${color}"/>
|
|
|
|
|
<path d="M0,-6 L0,-10" stroke="${color}" stroke-width="2"/>
|
|
|
|
|
<path d="M0,6 L0,8" stroke="${color}" stroke-width="2"/>`;
|
|
|
|
|
break;
|
|
|
|
|
case 'military':
|
|
|
|
|
path = `<path d="M0,-12 L-4,2 L-8,8 L-2,6 L0,12 L2,6 L8,8 L4,2 Z" fill="${color}"/>`;
|
|
|
|
|
break;
|
|
|
|
|
case 'cargo':
|
|
|
|
|
path = `<path d="M0,-12 L-10,8 L-3,8 L0,12 L3,8 L10,8 Z" fill="${color}"/>
|
|
|
|
|
<rect x="-2" y="-6" width="4" height="8" fill="${color}"/>`;
|
|
|
|
|
break;
|
|
|
|
|
case 'ga':
|
|
|
|
|
path = `<path d="M0,-10 L-5,6 L-1,6 L0,10 L1,6 L5,6 Z" fill="${color}"/>`;
|
|
|
|
|
break;
|
|
|
|
|
case 'ground':
|
|
|
|
|
path = `<rect x="-6" y="-4" width="12" height="8" fill="${color}" rx="2"/>
|
|
|
|
|
<circle cx="-3" cy="2" r="2" fill="#333"/>
|
|
|
|
|
<circle cx="3" cy="2" r="2" fill="#333"/>`;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
path = `<path d="M0,-12 L-8,8 L-2,8 L0,12 L2,8 L8,8 Z" fill="${color}"/>`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
|
|
|
|
<g transform="translate(16,16)">
|
|
|
|
|
${path}
|
|
|
|
|
</g>
|
|
|
|
|
</svg>`;
|
|
|
|
|
}
|
2025-08-24 14:04:17 +02:00
|
|
|
|
|
|
|
|
updateAircraftData(data) {
|
|
|
|
|
if (data.aircraft) {
|
2025-08-25 10:14:03 +02:00
|
|
|
// Track which aircraft are new or have position changes for debugging
|
|
|
|
|
let newCount = 0;
|
|
|
|
|
let updatedCount = 0;
|
|
|
|
|
let positionChanges = 0;
|
|
|
|
|
|
|
|
|
|
// Clear old data and update with new data
|
|
|
|
|
const previousData = new Map(this.aircraftData);
|
2025-08-24 14:04:17 +02:00
|
|
|
this.aircraftData.clear();
|
2025-08-25 10:14:03 +02:00
|
|
|
|
2025-08-24 14:04:17 +02:00
|
|
|
for (const [icao, aircraft] of Object.entries(data.aircraft)) {
|
2025-08-25 10:14:03 +02:00
|
|
|
const previousAircraft = previousData.get(icao);
|
|
|
|
|
|
|
|
|
|
if (!previousAircraft) {
|
|
|
|
|
newCount++;
|
|
|
|
|
} else {
|
|
|
|
|
updatedCount++;
|
|
|
|
|
|
|
|
|
|
// Check for position changes
|
|
|
|
|
if (previousAircraft.Latitude !== aircraft.Latitude ||
|
|
|
|
|
previousAircraft.Longitude !== aircraft.Longitude ||
|
|
|
|
|
previousAircraft.Track !== aircraft.Track ||
|
|
|
|
|
previousAircraft.Altitude !== aircraft.Altitude) {
|
|
|
|
|
positionChanges++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-24 14:04:17 +02:00
|
|
|
this.aircraftData.set(icao, aircraft);
|
|
|
|
|
}
|
2025-08-25 10:14:03 +02:00
|
|
|
|
|
|
|
|
// Debug logging for track propagation issues
|
|
|
|
|
if (newCount > 0 || positionChanges > 0) {
|
|
|
|
|
console.debug(`Aircraft update: ${newCount} new, ${updatedCount} updated, ${positionChanges} position changes`);
|
|
|
|
|
}
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateMarkers() {
|
|
|
|
|
if (!this.map) {
|
2025-08-25 10:14:03 +02:00
|
|
|
console.debug("Map not available for updateMarkers");
|
2025-08-24 14:04:17 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clear stale aircraft markers
|
|
|
|
|
const currentICAOs = new Set(this.aircraftData.keys());
|
|
|
|
|
for (const [icao, marker] of this.aircraftMarkers) {
|
|
|
|
|
if (!currentICAOs.has(icao)) {
|
|
|
|
|
this.map.removeLayer(marker);
|
|
|
|
|
this.aircraftMarkers.delete(icao);
|
2025-08-24 16:24:46 +02:00
|
|
|
|
|
|
|
|
// Remove trail if it exists
|
|
|
|
|
if (this.aircraftTrails.has(icao)) {
|
|
|
|
|
const trail = this.aircraftTrails.get(icao);
|
|
|
|
|
if (trail.polyline) {
|
|
|
|
|
this.map.removeLayer(trail.polyline);
|
|
|
|
|
}
|
|
|
|
|
this.aircraftTrails.delete(icao);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Notify if this was the selected aircraft
|
|
|
|
|
if (this.selectedAircraftCallback && this.selectedAircraftCallback(icao)) {
|
|
|
|
|
// Aircraft was selected and disappeared - could notify main app
|
|
|
|
|
// For now, the callback will return false automatically since selectedAircraft will be cleared
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-24 14:04:17 +02:00
|
|
|
this.markerRemoveCount++;
|
2025-08-25 10:14:03 +02:00
|
|
|
console.debug(`Removed stale aircraft marker: ${icao}`);
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-25 10:14:03 +02:00
|
|
|
// Update aircraft markers - process ALL aircraft, not just those with valid coordinates yet
|
|
|
|
|
// Let updateAircraftMarker handle coordinate validation
|
2025-08-24 14:04:17 +02:00
|
|
|
for (const [icao, aircraft] of this.aircraftData) {
|
2025-08-25 10:14:03 +02:00
|
|
|
// More comprehensive coordinate check
|
|
|
|
|
const hasCoords = aircraft.Latitude != null && aircraft.Longitude != null &&
|
|
|
|
|
aircraft.Latitude !== 0 && aircraft.Longitude !== 0;
|
2025-08-24 14:04:17 +02:00
|
|
|
const validLat = aircraft.Latitude >= -90 && aircraft.Latitude <= 90;
|
|
|
|
|
const validLng = aircraft.Longitude >= -180 && aircraft.Longitude <= 180;
|
|
|
|
|
|
|
|
|
|
if (hasCoords && validLat && validLng) {
|
|
|
|
|
this.updateAircraftMarker(icao, aircraft);
|
2025-08-25 10:14:03 +02:00
|
|
|
} else if (hasCoords) {
|
|
|
|
|
// Log invalid coordinates for debugging
|
|
|
|
|
console.debug(`Invalid coordinates for ${icao}: lat=${aircraft.Latitude}, lng=${aircraft.Longitude}`);
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
2025-08-25 10:14:03 +02:00
|
|
|
// If no coordinates, we still want to process for other updates (trails, etc.)
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
2025-08-25 10:14:03 +02:00
|
|
|
|
|
|
|
|
console.debug(`Markers update complete: ${this.aircraftMarkers.size} active markers, ${this.aircraftData.size} aircraft`);
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateAircraftMarker(icao, aircraft) {
|
|
|
|
|
const pos = [aircraft.Latitude, aircraft.Longitude];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check for invalid coordinates - proper geographic bounds
|
|
|
|
|
const isValidLat = pos[0] >= -90 && pos[0] <= 90;
|
|
|
|
|
const isValidLng = pos[1] >= -180 && pos[1] <= 180;
|
|
|
|
|
|
|
|
|
|
if (!isValidLat || !isValidLng || isNaN(pos[0]) || isNaN(pos[1])) {
|
|
|
|
|
console.error(`🚨 Invalid coordinates for ${icao}: [${pos[0]}, ${pos[1]}] (lat must be -90 to +90, lng must be -180 to +180)`);
|
|
|
|
|
return; // Don't create/update marker with invalid coordinates
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.aircraftMarkers.has(icao)) {
|
|
|
|
|
// Update existing marker - KISS approach
|
|
|
|
|
const marker = this.aircraftMarkers.get(icao);
|
|
|
|
|
|
2025-08-25 10:14:03 +02:00
|
|
|
// Always update position - don't try to be too smart about detecting changes
|
2025-08-24 14:40:36 +02:00
|
|
|
const oldPos = marker.getLatLng();
|
2025-08-25 10:14:03 +02:00
|
|
|
const positionChanged = Math.abs(oldPos.lat - pos[0]) > 0.0001 || Math.abs(oldPos.lng - pos[1]) > 0.0001;
|
|
|
|
|
|
|
|
|
|
// ALWAYS update position regardless of change detection to ensure propagation
|
2025-08-24 14:04:17 +02:00
|
|
|
marker.setLatLng(pos);
|
|
|
|
|
|
2025-08-25 10:14:03 +02:00
|
|
|
if (positionChanged) {
|
|
|
|
|
// Debug significant position updates
|
|
|
|
|
console.debug(`Position change for ${icao}: [${pos[0].toFixed(4)}, ${pos[1].toFixed(4)}] (was [${oldPos.lat.toFixed(4)}, ${oldPos.lng.toFixed(4)}])`);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-24 15:29:43 +02:00
|
|
|
// Check if icon needs to be updated (track rotation, aircraft type, or ground status changes)
|
|
|
|
|
const currentRotation = marker._currentRotation || 0;
|
|
|
|
|
const currentType = marker._currentType || null;
|
|
|
|
|
const currentOnGround = marker._currentOnGround || false;
|
|
|
|
|
|
|
|
|
|
const newType = this.getAircraftIconType(aircraft);
|
2025-08-25 10:14:03 +02:00
|
|
|
// Fix rotation change detection - handle undefined/null tracks properly
|
|
|
|
|
const newTrack = aircraft.Track || 0;
|
|
|
|
|
const rotationChanged = aircraft.Track !== undefined && aircraft.Track !== null &&
|
|
|
|
|
Math.abs(currentRotation - newTrack) > 10; // Increased threshold
|
2025-08-24 15:29:43 +02:00
|
|
|
const typeChanged = currentType !== newType;
|
|
|
|
|
const groundStatusChanged = currentOnGround !== aircraft.OnGround;
|
|
|
|
|
|
2025-08-25 10:14:03 +02:00
|
|
|
// Update icon if anything changed, OR if this is a new track value and we didn't have one before
|
|
|
|
|
const firstTrackUpdate = currentRotation === 0 && aircraft.Track !== undefined && aircraft.Track !== null && aircraft.Track !== 0;
|
|
|
|
|
|
|
|
|
|
if (rotationChanged || typeChanged || groundStatusChanged || firstTrackUpdate) {
|
2025-08-24 15:29:43 +02:00
|
|
|
marker.setIcon(this.createAircraftIcon(aircraft));
|
2025-08-25 10:14:03 +02:00
|
|
|
marker._currentRotation = newTrack;
|
2025-08-24 15:29:43 +02:00
|
|
|
marker._currentType = newType;
|
|
|
|
|
marker._currentOnGround = aircraft.OnGround || false;
|
2025-08-25 10:14:03 +02:00
|
|
|
|
|
|
|
|
if (rotationChanged || firstTrackUpdate) {
|
|
|
|
|
console.debug(`Updated track for ${icao}: ${aircraft.Track}° (was ${currentRotation}°)`);
|
|
|
|
|
}
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle popup exactly like Leaflet expects
|
|
|
|
|
if (marker.isPopupOpen()) {
|
|
|
|
|
marker.setPopupContent(this.createPopupContent(aircraft));
|
2025-08-31 19:43:58 +02:00
|
|
|
// Enhance callsign display for updated popup
|
|
|
|
|
const popupElement = marker.getPopup().getElement();
|
|
|
|
|
if (popupElement) {
|
|
|
|
|
this.enhanceCallsignDisplay(popupElement);
|
|
|
|
|
}
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.markerUpdateCount++;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// Create new marker
|
|
|
|
|
const icon = this.createAircraftIcon(aircraft);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const marker = L.marker(pos, {
|
2025-08-24 15:18:51 +02:00
|
|
|
icon: icon
|
2025-08-24 14:04:17 +02:00
|
|
|
}).addTo(this.map);
|
|
|
|
|
|
2025-08-24 15:29:43 +02:00
|
|
|
// Store current properties for future update comparisons
|
2025-08-24 15:18:51 +02:00
|
|
|
marker._currentRotation = aircraft.Track || 0;
|
2025-08-24 15:29:43 +02:00
|
|
|
marker._currentType = this.getAircraftIconType(aircraft);
|
|
|
|
|
marker._currentOnGround = aircraft.OnGround || false;
|
2025-08-24 15:18:51 +02:00
|
|
|
|
2025-08-24 14:04:17 +02:00
|
|
|
marker.bindPopup(this.createPopupContent(aircraft), {
|
|
|
|
|
maxWidth: 450,
|
|
|
|
|
className: 'aircraft-popup'
|
|
|
|
|
});
|
2025-08-31 19:43:58 +02:00
|
|
|
|
|
|
|
|
// Enhance callsign display when popup opens
|
|
|
|
|
marker.on('popupopen', (e) => {
|
|
|
|
|
const popupElement = e.popup.getElement();
|
|
|
|
|
if (popupElement) {
|
|
|
|
|
this.enhanceCallsignDisplay(popupElement);
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-08-24 14:04:17 +02:00
|
|
|
|
|
|
|
|
this.aircraftMarkers.set(icao, marker);
|
|
|
|
|
this.markerCreateCount++;
|
|
|
|
|
|
|
|
|
|
// Force immediate visibility
|
|
|
|
|
if (marker._icon) {
|
|
|
|
|
marker._icon.style.display = 'block';
|
|
|
|
|
marker._icon.style.opacity = '1';
|
|
|
|
|
marker._icon.style.visibility = 'visible';
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(`Failed to create marker for ${icao}:`, error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-24 16:24:46 +02:00
|
|
|
// Update trails - check both global trails and individual selected aircraft
|
|
|
|
|
if (this.showTrails || this.isSelectedAircraftTrailEnabled(icao)) {
|
2025-08-24 15:18:51 +02:00
|
|
|
this.updateAircraftTrail(icao, aircraft);
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createAircraftIcon(aircraft) {
|
2025-08-24 15:09:54 +02:00
|
|
|
const iconType = this.getAircraftIconType(aircraft);
|
2025-08-24 20:16:25 +02:00
|
|
|
const color = this.getAircraftColor(iconType, aircraft);
|
2025-08-24 14:04:17 +02:00
|
|
|
const size = aircraft.OnGround ? 12 : 16;
|
2025-08-24 15:18:51 +02:00
|
|
|
const rotation = aircraft.Track || 0;
|
2025-08-24 14:04:17 +02:00
|
|
|
|
2025-08-24 15:29:43 +02:00
|
|
|
// Get SVG template from cache
|
|
|
|
|
let svgTemplate = this.iconCache.get(iconType) || this.iconCache.get('commercial');
|
2025-08-24 14:53:24 +02:00
|
|
|
|
2025-08-24 15:29:43 +02:00
|
|
|
if (!svgTemplate) {
|
|
|
|
|
// Ultimate fallback - create a simple circle
|
|
|
|
|
svgTemplate = `<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
|
|
|
|
<g transform="translate(16,16)">
|
|
|
|
|
<circle cx="0" cy="0" r="8" fill="currentColor"/>
|
|
|
|
|
</g>
|
|
|
|
|
</svg>`;
|
2025-08-24 14:53:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-24 15:29:43 +02:00
|
|
|
// Apply color and rotation to the SVG
|
|
|
|
|
let svg = svgTemplate
|
|
|
|
|
.replace(/currentColor/g, color)
|
|
|
|
|
.replace(/width="32"/, `width="${size * 2}"`)
|
|
|
|
|
.replace(/height="32"/, `height="${size * 2}"`);
|
|
|
|
|
|
|
|
|
|
// Add rotation to the transform
|
|
|
|
|
if (rotation !== 0) {
|
|
|
|
|
svg = svg.replace(/transform="translate\(16,16\)"/, `transform="translate(16,16) rotate(${rotation})"`);
|
|
|
|
|
}
|
2025-08-24 14:04:17 +02:00
|
|
|
|
|
|
|
|
return L.divIcon({
|
|
|
|
|
html: svg,
|
|
|
|
|
iconSize: [size * 2, size * 2],
|
|
|
|
|
iconAnchor: [size, size],
|
|
|
|
|
className: 'aircraft-marker'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getAircraftType(aircraft) {
|
2025-08-24 15:09:54 +02:00
|
|
|
// For display purposes, return the actual ADS-B category
|
|
|
|
|
// This is used in the popup display
|
|
|
|
|
if (aircraft.OnGround) return 'On Ground';
|
|
|
|
|
if (aircraft.Category) return aircraft.Category;
|
|
|
|
|
return 'Unknown';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getAircraftIconType(aircraft) {
|
|
|
|
|
// For icon selection, we still need basic categories
|
|
|
|
|
// This determines which SVG shape to use
|
2025-08-24 14:04:17 +02:00
|
|
|
if (aircraft.OnGround) return 'ground';
|
2025-08-24 14:53:24 +02:00
|
|
|
|
2025-08-24 14:04:17 +02:00
|
|
|
if (aircraft.Category) {
|
|
|
|
|
const cat = aircraft.Category.toLowerCase();
|
2025-08-24 14:53:24 +02:00
|
|
|
|
2025-08-24 15:09:54 +02:00
|
|
|
// Map to basic icon types for visual representation
|
|
|
|
|
if (cat.includes('helicopter') || cat.includes('rotorcraft')) return 'helicopter';
|
2025-08-24 14:53:24 +02:00
|
|
|
if (cat.includes('military') || cat.includes('fighter') || cat.includes('bomber')) return 'military';
|
2025-08-24 15:09:54 +02:00
|
|
|
if (cat.includes('cargo') || cat.includes('heavy') || cat.includes('super')) return 'cargo';
|
|
|
|
|
if (cat.includes('light') || cat.includes('glider') || cat.includes('ultralight')) return 'ga';
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
2025-08-24 14:53:24 +02:00
|
|
|
|
2025-08-24 15:09:54 +02:00
|
|
|
// Default commercial icon for everything else
|
2025-08-24 14:04:17 +02:00
|
|
|
return 'commercial';
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-24 20:16:25 +02:00
|
|
|
getAircraftColor(type, aircraft) {
|
|
|
|
|
// Special colors for specific types
|
|
|
|
|
if (type === 'military') return '#ff4444';
|
|
|
|
|
if (type === 'helicopter') return '#ff00ff';
|
|
|
|
|
if (type === 'ground') return '#888888';
|
|
|
|
|
if (type === 'ga') return '#ffff00';
|
|
|
|
|
|
|
|
|
|
// For commercial and cargo types, use weight-based colors
|
|
|
|
|
if (aircraft && aircraft.Category) {
|
|
|
|
|
const cat = aircraft.Category.toLowerCase();
|
|
|
|
|
|
|
|
|
|
// Check for specific weight ranges in the category string
|
|
|
|
|
// Light aircraft (< 7000kg) - Sky blue
|
2025-08-24 20:24:48 +02:00
|
|
|
if (cat.includes('light')) {
|
2025-08-24 20:16:25 +02:00
|
|
|
return '#00bfff';
|
|
|
|
|
}
|
|
|
|
|
// Medium aircraft (7000-34000kg) - Green
|
2025-08-24 20:24:48 +02:00
|
|
|
if (cat.includes('medium')) {
|
2025-08-24 20:16:25 +02:00
|
|
|
return '#00ff88';
|
|
|
|
|
}
|
2025-08-24 20:28:27 +02:00
|
|
|
// High Vortex Large - Red-orange (special wake turbulence category)
|
|
|
|
|
if (cat.includes('high vortex')) {
|
|
|
|
|
return '#ff4500';
|
|
|
|
|
}
|
2025-08-24 20:16:25 +02:00
|
|
|
// Large aircraft (34000-136000kg) - Orange
|
2025-08-24 20:28:27 +02:00
|
|
|
if (cat.includes('large')) {
|
2025-08-24 20:16:25 +02:00
|
|
|
return '#ff8c00';
|
|
|
|
|
}
|
|
|
|
|
// Heavy aircraft (> 136000kg) - Red
|
2025-08-24 20:24:48 +02:00
|
|
|
if (cat.includes('heavy') || cat.includes('super')) {
|
2025-08-24 20:16:25 +02:00
|
|
|
return '#ff0000';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Default to green for unknown commercial aircraft
|
|
|
|
|
return '#00ff88';
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-08-24 15:18:51 +02:00
|
|
|
updateAircraftTrail(icao, aircraft) {
|
|
|
|
|
// Use server-provided position history
|
|
|
|
|
if (!aircraft.position_history || aircraft.position_history.length < 2) {
|
|
|
|
|
// No trail data available or not enough points
|
|
|
|
|
if (this.aircraftTrails.has(icao)) {
|
|
|
|
|
const trail = this.aircraftTrails.get(icao);
|
|
|
|
|
if (trail.polyline) {
|
|
|
|
|
this.map.removeLayer(trail.polyline);
|
|
|
|
|
}
|
|
|
|
|
this.aircraftTrails.delete(icao);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-24 15:18:51 +02:00
|
|
|
// Convert position history to Leaflet format
|
|
|
|
|
const trailPoints = aircraft.position_history.map(point => [point.lat, point.lon]);
|
2025-08-24 14:04:17 +02:00
|
|
|
|
2025-08-24 15:18:51 +02:00
|
|
|
// Get or create trail object
|
|
|
|
|
if (!this.aircraftTrails.has(icao)) {
|
|
|
|
|
this.aircraftTrails.set(icao, {});
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
2025-08-24 15:18:51 +02:00
|
|
|
const trail = this.aircraftTrails.get(icao);
|
2025-08-24 14:04:17 +02:00
|
|
|
|
2025-08-24 15:18:51 +02:00
|
|
|
// Remove old polyline if it exists
|
|
|
|
|
if (trail.polyline) {
|
|
|
|
|
this.map.removeLayer(trail.polyline);
|
|
|
|
|
}
|
2025-08-24 14:04:17 +02:00
|
|
|
|
2025-08-24 15:18:51 +02:00
|
|
|
// Create gradient effect - newer points are brighter
|
|
|
|
|
const segments = [];
|
|
|
|
|
for (let i = 1; i < trailPoints.length; i++) {
|
|
|
|
|
const opacity = 0.2 + (0.6 * (i / trailPoints.length)); // Fade from 0.2 to 0.8
|
|
|
|
|
const segment = L.polyline([trailPoints[i-1], trailPoints[i]], {
|
|
|
|
|
color: '#00d4ff',
|
|
|
|
|
weight: 2,
|
|
|
|
|
opacity: opacity
|
|
|
|
|
});
|
|
|
|
|
segments.push(segment);
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
2025-08-24 15:18:51 +02:00
|
|
|
|
|
|
|
|
// Create a feature group for all segments
|
|
|
|
|
trail.polyline = L.featureGroup(segments).addTo(this.map);
|
2025-08-24 14:04:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createPopupContent(aircraft) {
|
|
|
|
|
const type = this.getAircraftType(aircraft);
|
2025-08-24 16:24:46 +02:00
|
|
|
const country = aircraft.country || 'Unknown';
|
|
|
|
|
const flag = aircraft.flag || '🏳️';
|
2025-08-24 14:04:17 +02:00
|
|
|
|
|
|
|
|
const altitude = aircraft.Altitude || aircraft.BaroAltitude || 0;
|
|
|
|
|
const altitudeM = altitude ? Math.round(altitude * 0.3048) : 0;
|
|
|
|
|
const speedKmh = aircraft.GroundSpeed ? Math.round(aircraft.GroundSpeed * 1.852) : 0;
|
|
|
|
|
const distance = this.calculateDistance(aircraft);
|
|
|
|
|
const distanceKm = distance ? (distance * 1.852).toFixed(1) : 'N/A';
|
|
|
|
|
|
|
|
|
|
return `
|
|
|
|
|
<div class="aircraft-popup">
|
|
|
|
|
<div class="popup-header">
|
|
|
|
|
<div class="flight-info">
|
|
|
|
|
<span class="icao-flag">${flag}</span>
|
|
|
|
|
<span class="flight-id">${aircraft.ICAO24 || 'N/A'}</span>
|
2025-08-31 19:43:58 +02:00
|
|
|
${aircraft.Callsign ? `→ <span class="callsign-loading" data-callsign="${aircraft.Callsign}"><span class="callsign">${aircraft.Callsign}</span></span>` : ''}
|
2025-08-24 14:04:17 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="popup-details">
|
|
|
|
|
<div class="detail-row">
|
|
|
|
|
<strong>Country:</strong> ${country}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="detail-row">
|
2025-08-24 15:09:54 +02:00
|
|
|
<strong>Type:</strong> ${type}
|
2025-08-24 14:04:17 +02:00
|
|
|
</div>
|
2025-08-24 19:28:12 +02:00
|
|
|
${aircraft.TransponderCapability ? `
|
|
|
|
|
<div class="detail-row">
|
|
|
|
|
<strong>Transponder:</strong> ${aircraft.TransponderCapability}
|
|
|
|
|
</div>` : ''}
|
2025-08-24 19:31:46 +02:00
|
|
|
${aircraft.SignalQuality ? `
|
|
|
|
|
<div class="detail-row">
|
|
|
|
|
<strong>Signal Quality:</strong> ${aircraft.SignalQuality}
|
|
|
|
|
</div>` : ''}
|
2025-08-24 14:04:17 +02:00
|
|
|
|
|
|
|
|
<div class="detail-grid">
|
|
|
|
|
<div class="detail-item">
|
|
|
|
|
<div class="label">Altitude:</div>
|
2025-08-24 15:03:33 +02:00
|
|
|
<div class="value${!altitude ? ' no-data' : ''}">${altitude ? `${altitude} ft | ${altitudeM} m` : 'N/A'}</div>
|
2025-08-24 14:04:17 +02:00
|
|
|
</div>
|
|
|
|
|
<div class="detail-item">
|
|
|
|
|
<div class="label">Squawk:</div>
|
2025-08-24 15:03:33 +02:00
|
|
|
<div class="value${!aircraft.Squawk ? ' no-data' : ''}">${aircraft.Squawk || 'N/A'}</div>
|
2025-08-24 14:04:17 +02:00
|
|
|
</div>
|
|
|
|
|
<div class="detail-item">
|
|
|
|
|
<div class="label">Speed:</div>
|
2025-08-24 15:03:33 +02:00
|
|
|
<div class="value${!aircraft.GroundSpeed ? ' no-data' : ''}">${aircraft.GroundSpeed !== undefined && aircraft.GroundSpeed !== null ? `${aircraft.GroundSpeed} kt | ${speedKmh} km/h` : 'N/A'}</div>
|
2025-08-24 14:04:17 +02:00
|
|
|
</div>
|
|
|
|
|
<div class="detail-item">
|
|
|
|
|
<div class="label">Track:</div>
|
2025-08-24 15:03:33 +02:00
|
|
|
<div class="value${aircraft.Track === undefined || aircraft.Track === null ? ' no-data' : ''}">${aircraft.Track !== undefined && aircraft.Track !== null ? `${aircraft.Track}°` : 'N/A'}</div>
|
2025-08-24 14:04:17 +02:00
|
|
|
</div>
|
|
|
|
|
<div class="detail-item">
|
|
|
|
|
<div class="label">V/Rate:</div>
|
2025-08-24 15:03:33 +02:00
|
|
|
<div class="value${!aircraft.VerticalRate ? ' no-data' : ''}">${aircraft.VerticalRate ? `${aircraft.VerticalRate} ft/min` : 'N/A'}</div>
|
2025-08-24 14:04:17 +02:00
|
|
|
</div>
|
|
|
|
|
<div class="detail-item">
|
|
|
|
|
<div class="label">Distance:</div>
|
2025-08-24 15:03:33 +02:00
|
|
|
<div class="value${distance ? '' : ' no-data'}">${distanceKm !== 'N/A' ? `${distanceKm} km` : 'N/A'}</div>
|
2025-08-24 14:04:17 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="detail-row">
|
|
|
|
|
<strong>Position:</strong> ${aircraft.Latitude?.toFixed(4)}°, ${aircraft.Longitude?.toFixed(4)}°
|
|
|
|
|
</div>
|
|
|
|
|
<div class="detail-row">
|
|
|
|
|
<strong>Messages:</strong> ${aircraft.TotalMessages || 0}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="detail-row">
|
|
|
|
|
<strong>Age:</strong> ${aircraft.Age ? aircraft.Age.toFixed(1) : '0'}s
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
calculateDistance(aircraft) {
|
|
|
|
|
if (!aircraft.Latitude || !aircraft.Longitude) return null;
|
|
|
|
|
|
|
|
|
|
// Use closest source as reference point
|
|
|
|
|
let minDistance = Infinity;
|
|
|
|
|
for (const [id, srcData] of Object.entries(aircraft.sources || {})) {
|
|
|
|
|
if (srcData.distance && srcData.distance < minDistance) {
|
|
|
|
|
minDistance = srcData.distance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return minDistance === Infinity ? null : minDistance;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-31 19:43:58 +02:00
|
|
|
// Enhance callsign display in popup after it's created
|
|
|
|
|
async enhanceCallsignDisplay(popupElement) {
|
|
|
|
|
if (!this.callsignManager) return;
|
|
|
|
|
|
|
|
|
|
const callsignElements = popupElement.querySelectorAll('.callsign-loading');
|
|
|
|
|
|
|
|
|
|
for (const element of callsignElements) {
|
|
|
|
|
const callsign = element.dataset.callsign;
|
|
|
|
|
if (!callsign) continue;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const callsignInfo = await this.callsignManager.getCallsignInfo(callsign);
|
|
|
|
|
const richDisplay = this.callsignManager.generateCallsignDisplay(callsignInfo, callsign);
|
|
|
|
|
element.innerHTML = richDisplay;
|
|
|
|
|
element.classList.remove('callsign-loading');
|
|
|
|
|
element.classList.add('callsign-enhanced');
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.warn(`Failed to enhance callsign display for ${callsign}:`, error);
|
|
|
|
|
// Keep the simple display on error
|
|
|
|
|
element.classList.remove('callsign-loading');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-24 14:04:17 +02:00
|
|
|
|
|
|
|
|
toggleTrails() {
|
|
|
|
|
this.showTrails = !this.showTrails;
|
|
|
|
|
|
|
|
|
|
if (!this.showTrails) {
|
|
|
|
|
// Clear all trails
|
|
|
|
|
this.aircraftTrails.forEach((trail, icao) => {
|
|
|
|
|
if (trail.polyline) {
|
|
|
|
|
this.map.removeLayer(trail.polyline);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.aircraftTrails.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.showTrails;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-24 16:24:46 +02:00
|
|
|
showAircraftTrail(icao) {
|
|
|
|
|
const aircraft = this.aircraftData.get(icao);
|
|
|
|
|
if (aircraft && aircraft.position_history && aircraft.position_history.length >= 2) {
|
|
|
|
|
this.updateAircraftTrail(icao, aircraft);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hideAircraftTrail(icao) {
|
|
|
|
|
if (this.aircraftTrails.has(icao)) {
|
|
|
|
|
const trail = this.aircraftTrails.get(icao);
|
|
|
|
|
if (trail.polyline) {
|
|
|
|
|
this.map.removeLayer(trail.polyline);
|
|
|
|
|
}
|
|
|
|
|
this.aircraftTrails.delete(icao);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSelectedAircraftCallback(callback) {
|
|
|
|
|
this.selectedAircraftCallback = callback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isSelectedAircraftTrailEnabled(icao) {
|
|
|
|
|
return this.selectedAircraftCallback && this.selectedAircraftCallback(icao);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
centerMapOnAircraft(includeSourcesCallback = null) {
|
2025-08-24 14:04:17 +02:00
|
|
|
const validAircraft = Array.from(this.aircraftData.values())
|
|
|
|
|
.filter(a => a.Latitude && a.Longitude);
|
|
|
|
|
|
2025-08-24 16:24:46 +02:00
|
|
|
const allPoints = [];
|
|
|
|
|
|
|
|
|
|
// Add aircraft positions
|
|
|
|
|
validAircraft.forEach(a => {
|
|
|
|
|
allPoints.push([a.Latitude, a.Longitude]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Add source positions if callback provided
|
|
|
|
|
if (includeSourcesCallback && typeof includeSourcesCallback === 'function') {
|
|
|
|
|
const sourcePositions = includeSourcesCallback();
|
|
|
|
|
allPoints.push(...sourcePositions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (allPoints.length === 0) return;
|
2025-08-24 14:04:17 +02:00
|
|
|
|
2025-08-24 16:24:46 +02:00
|
|
|
if (allPoints.length === 1) {
|
|
|
|
|
// Center on single point
|
|
|
|
|
this.map.setView(allPoints[0], 12);
|
2025-08-24 14:04:17 +02:00
|
|
|
} else {
|
2025-08-24 16:24:46 +02:00
|
|
|
// Fit bounds to all points (aircraft + sources)
|
|
|
|
|
const bounds = L.latLngBounds(allPoints);
|
2025-08-24 14:04:17 +02:00
|
|
|
this.map.fitBounds(bounds.pad(0.1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|