42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
use std::collections::HashMap;
|
|
|
|
// Store railway ways for deferred insertion (after relation processing for colors)
|
|
pub struct RailwayWay {
|
|
pub id: i64,
|
|
pub tags: HashMap<String, String>,
|
|
pub points: Vec<u8>, // Serialized line blob
|
|
pub first_lat: f64,
|
|
pub first_lon: f64,
|
|
}
|
|
|
|
pub struct RailwayStore {
|
|
ways: HashMap<i64, RailwayWay>, // way_id -> railway data
|
|
way_colors: HashMap<i64, String>, // way_id -> colour from route relation
|
|
}
|
|
|
|
impl RailwayStore {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
ways: HashMap::new(),
|
|
way_colors: HashMap::new(),
|
|
}
|
|
}
|
|
|
|
pub fn insert_way(&mut self, id: i64, tags: HashMap<String, String>, points: Vec<u8>, first_lat: f64, first_lon: f64) {
|
|
self.ways.insert(id, RailwayWay { id, tags, points, first_lat, first_lon });
|
|
}
|
|
|
|
pub fn set_color(&mut self, way_id: i64, color: String) {
|
|
// Only set if not already set (first route relation wins)
|
|
self.way_colors.entry(way_id).or_insert(color);
|
|
}
|
|
|
|
pub fn get_color(&self, way_id: i64) -> Option<&String> {
|
|
self.way_colors.get(&way_id)
|
|
}
|
|
|
|
pub fn into_data(self) -> (HashMap<i64, RailwayWay>, HashMap<i64, String>) {
|
|
(self.ways, self.way_colors)
|
|
}
|
|
}
|