13 stable releases

2.0.5 Jun 12, 2025
2.0.4 May 23, 2025
2.0.0 Mar 14, 2023
1.4.1 Aug 4, 2022
0.1.0 Dec 3, 2021

#698 in Algorithms

Download history 2/week @ 2025-05-14 518/week @ 2025-05-21 8/week @ 2025-05-28 147/week @ 2025-06-11 7/week @ 2025-06-18 14/week @ 2025-06-25

168 downloads per month

MIT/Apache

42KB
737 lines

Tools for taking screenshots of the ADS-B Exchange map.

use adsbx_screenshot::{AdsbxBrowser, AdsbxBrowserOptions, HistoryOptions, KmlType};
use chrono::prelude::*;
use std::path::PathBuf;
use tempfile::tempdir;

// Create a temporary directory for downloads in the example
let temp_dir = tempdir()?;
let download_dir = temp_dir.path().to_path_buf();

let config = AdsbxBrowserOptions {
    regs: vec!["N822LA".to_string()],
    // Use NaiveDate for EntireDay
    history: Some(HistoryOptions::EntireDay(Utc.with_ymd_and_hms(2021, 12, 3, 0, 0, 0).unwrap().date_naive())),
    zoom: 13.0,
    delete_ads: true,
    show_track_labels: true,
    hide_infoblock: false,
    request_screenshot: true, // Explicitly request screenshot
    request_kml: Some(KmlType::Baro), // Request KML with Barometric altitude
    download_dir: download_dir.clone(), // Specify download directory for KML
    ..Default::default()
};

let mut browser = AdsbxBrowser::new((1920, 1080))?;
let output = browser.get_output(&config)?;

// Save the screenshot if it was generated
if let Some(screenshot) = output.screenshot {
    let screenshot_path = download_dir.join("screenshot.png");
    let mut file = std::fs::File::create(&screenshot_path)?;
    std::io::Write::write_all(&mut file, &screenshot.data)?;
    println!("Saved {}", screenshot_path.display());
}

// Save the KML data if it was generated
if let Some(kml) = output.kml {
    let filename = format!("track_{}", kml.filename); // Prepend prefix
    let kml_path = download_dir.join(&filename);
    // File is already read by get_output, re-save for demonstration
    let mut file = std::fs::File::create(&kml_path)?;
    std::io::Write::write_all(&mut file, kml.data.as_bytes())?;
    println!("Saved {}", kml_path.display());
    // Clean up the re-saved KML file
    std::fs::remove_file(&kml_path)?;
}

Dependencies

~24–37MB
~679K SLoC