#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![allow(rustdoc::missing_crate_level_docs)]
use eframe::egui;
use egui_map_view::{Map, config::OpenStreetMapConfig};
fn main() -> eframe::Result {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([800.0, 600.0]),
..Default::default()
};
eframe::run_native(
"My map test",
options,
Box::new(|_cc| Ok(Box::<MyApp>::default())),
)
}
struct MyApp {
map: Map,
}
impl Default for MyApp {
fn default() -> Self {
Self {
map: Map::new(OpenStreetMapConfig::default()),
}
}
}
impl eframe::App for MyApp {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show_inside(ui, |ui| {
ui.heading("EXAMPLE");
ui.label(self.map.center.lon.to_string());
ui.label(self.map.center.lat.to_string());
ui.label(self.map.zoom.to_string());
ui.horizontal(|ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.label("right to map");
if ui.add_sized(ui.available_size(), &mut self.map).clicked() {
if let Some(pos) = self.map.mouse_pos {
println!("{},{}", pos.lon, pos.lat);
}
}
});
});
ui.label("below map will eat whats left from the horizontal layout");
});
}
}