Crate adsbx_screenshot

Crate adsbx_screenshot 

Source
Expand description

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)?;
}

Structs§

AdsbxBrowser
Type wrapping a headless Chrome browser for accessing ADS-B Exchange maps.
AdsbxBrowserOptions
Options for configuring the ADS-B Exchange front-end.
AdsbxOutput
Holds the requested output(s) from the browser interaction.
Coordinates
Latitude, longitude pair.
KmlData
Holds downloaded KML data.
Screenshot
Holds screenshot data.

Enums§

Error
The adsbx_browser error type.
HistoryOptions
History options.
KmlType
The type of KML altitude data to request.