use egui_map::map::Map;
use egui_map::map::objects::{ MapPoint, MapSegment, RawPoint};
use std::collections::HashMap;
fn main() -> eframe::Result<()> {
let mut points = HashMap::new();
for (id, name, x, y) in [
(1, "Alpha", 0.0, 0.0),
(2, "Beta", 100.0, 50.0),
(3, "Gamma", 50.0, -80.0),
] {
let mut point = MapPoint::new(id, RawPoint::new(x, y));
point.set_name(name.to_string());
points.insert(id, point);
}
for (line_id, endpoints) in [("1-2", [1, 2]), ("1-3", [1, 3])] {
for id in endpoints {
points
.get_mut(&id)
.unwrap()
.connections
.push(line_id.to_string());
}
}
let mut map = Map::new();
map.add_hashmap_points(points);
let seg1 = MapSegment::new(
std::rc::Rc::from("1-2"),
RawPoint::new(0.0, 0.0),
RawPoint::new(100.0, 50.0),
);
let seg2 = MapSegment::new(
std::rc::Rc::from("1-3"),
RawPoint::new(0.0, 0.0),
RawPoint::new(50.0, -80.0),
);
map.add_lines(vec![seg1, seg2]);
eframe::run_ui_native(
"egui-map: basic",
eframe::NativeOptions::default(),
move |ui, _frame| {
ui.add(&mut map);
},
)
}