mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +03:00
Show some OSM key/values for roads in the new viewer
This commit is contained in:
parent
ecabf2436f
commit
8339c893eb
@ -1,16 +1,18 @@
|
||||
use map_model::osm;
|
||||
use widgetry::{
|
||||
lctrl, Btn, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, State, TextExt,
|
||||
VerticalAlignment, Widget,
|
||||
};
|
||||
|
||||
use crate::app::App;
|
||||
use crate::common::{Navigator, CityPicker};
|
||||
use crate::common::{CityPicker, Navigator};
|
||||
use crate::game::{PopupMsg, Transition};
|
||||
use crate::helpers::nice_map_name;
|
||||
use crate::helpers::{nice_map_name, open_browser, ID};
|
||||
use crate::options::OptionsPanel;
|
||||
|
||||
pub struct Viewer {
|
||||
top_panel: Panel,
|
||||
object_fixed: bool,
|
||||
}
|
||||
|
||||
impl Viewer {
|
||||
@ -42,18 +44,95 @@ impl Viewer {
|
||||
),
|
||||
Btn::plaintext("About").build_def(ctx, None),
|
||||
]),
|
||||
Widget::horiz_separator(ctx, 0.3),
|
||||
"Zoom in and select something to begin"
|
||||
.draw_text(ctx)
|
||||
.named("tags"),
|
||||
]))
|
||||
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
|
||||
.aligned(HorizontalAlignment::Right, VerticalAlignment::Top)
|
||||
.exact_size_percent(35, 80)
|
||||
.build(ctx),
|
||||
object_fixed: false,
|
||||
})
|
||||
}
|
||||
|
||||
fn update_tags(&mut self, ctx: &mut EventCtx, app: &App) {
|
||||
let mut col = Vec::new();
|
||||
match app.primary.current_selection {
|
||||
Some(ID::Lane(l)) => {
|
||||
if self.object_fixed {
|
||||
col.push("Click something else to examine it".draw_text(ctx));
|
||||
} else {
|
||||
col.push("Click to examine".draw_text(ctx));
|
||||
}
|
||||
|
||||
let r = app.primary.map.get_parent(l);
|
||||
col.push(
|
||||
Btn::text_bg2(format!("Open OSM way {}", r.orig_id.osm_way_id.0)).build(
|
||||
ctx,
|
||||
format!("open {}", r.orig_id.osm_way_id),
|
||||
None,
|
||||
),
|
||||
);
|
||||
|
||||
let tags = &r.osm_tags;
|
||||
for (k, v) in tags.inner() {
|
||||
if k.starts_with("abst:") {
|
||||
continue;
|
||||
}
|
||||
if tags.contains_key(osm::INFERRED_PARKING)
|
||||
&& (k == osm::PARKING_RIGHT
|
||||
|| k == osm::PARKING_LEFT
|
||||
|| k == osm::PARKING_BOTH)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if tags.contains_key(osm::INFERRED_SIDEWALKS) && k == osm::SIDEWALK {
|
||||
continue;
|
||||
}
|
||||
if self.object_fixed {
|
||||
col.push(Widget::row(vec![
|
||||
Line(k).draw(ctx),
|
||||
Line(v).draw(ctx).align_right(),
|
||||
]));
|
||||
} else {
|
||||
col.push(Widget::row(vec![
|
||||
Line(k).secondary().draw(ctx),
|
||||
Line(v).secondary().draw(ctx).align_right(),
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
col.push("Zoom in and select something to begin".draw_text(ctx));
|
||||
}
|
||||
};
|
||||
self.top_panel
|
||||
.replace(ctx, "tags", Widget::col(col).named("tags"));
|
||||
}
|
||||
}
|
||||
|
||||
impl State<App> for Viewer {
|
||||
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
|
||||
ctx.canvas_movement();
|
||||
if ctx.redo_mouseover() {
|
||||
let old_id = app.primary.current_selection.clone();
|
||||
app.recalculate_current_selection(ctx);
|
||||
|
||||
if !self.object_fixed && old_id != app.primary.current_selection {
|
||||
self.update_tags(ctx, app);
|
||||
}
|
||||
}
|
||||
if self.object_fixed {
|
||||
if ctx.canvas.get_cursor_in_map_space().is_some() && ctx.normal_left_click() {
|
||||
self.object_fixed = false;
|
||||
self.update_tags(ctx, app);
|
||||
}
|
||||
} else {
|
||||
if ctx.canvas.get_cursor_in_map_space().is_some() && ctx.normal_left_click() {
|
||||
self.object_fixed = true;
|
||||
self.update_tags(ctx, app);
|
||||
}
|
||||
}
|
||||
|
||||
match self.top_panel.event(ctx) {
|
||||
@ -94,7 +173,13 @@ impl State<App> for Viewer {
|
||||
],
|
||||
));
|
||||
}
|
||||
_ => unreachable!(),
|
||||
x => {
|
||||
if let Some(url) = x.strip_prefix("open ") {
|
||||
open_browser(url.to_string());
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user