mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
Experiment with a dedicated OSM viewer, to debut at Connect 2020. For
now, this is still embedded in A/B Street, to take advantage of everything that already exists. But later, the idea is to split it into a separate crate, sharing lots of code.
This commit is contained in:
parent
9dbb156058
commit
ecabf2436f
@ -6,7 +6,7 @@ use widgetry::{
|
||||
};
|
||||
|
||||
use crate::app::App;
|
||||
use crate::common::{navigate, Warping};
|
||||
use crate::common::{Navigator, Warping};
|
||||
use crate::game::Transition;
|
||||
use crate::layer::PickLayer;
|
||||
|
||||
@ -177,7 +177,7 @@ impl Minimap {
|
||||
self.set_zoom(ctx, app, 3);
|
||||
}
|
||||
x if x == "search" => {
|
||||
return Some(Transition::Push(navigate::Navigator::new(ctx, app)));
|
||||
return Some(Transition::Push(Navigator::new(ctx, app)));
|
||||
}
|
||||
x if x == "zoom out fully" => {
|
||||
return Some(Transition::Push(Warping::new(
|
||||
|
@ -11,6 +11,7 @@ pub use self::colors::{ColorDiscrete, ColorLegend, ColorNetwork, ColorScale, Div
|
||||
pub use self::heatmap::{make_heatmap, HeatmapOptions};
|
||||
pub use self::isochrone::IsochroneViewer;
|
||||
pub use self::minimap::Minimap;
|
||||
pub use self::navigate::Navigator;
|
||||
pub use self::warp::Warping;
|
||||
use crate::app::App;
|
||||
use crate::game::Transition;
|
||||
|
@ -13,6 +13,7 @@ use crate::helpers::nice_map_name;
|
||||
mod destinations;
|
||||
mod kml;
|
||||
pub mod mapping;
|
||||
pub mod osm_viewer;
|
||||
mod polygon;
|
||||
mod scenario;
|
||||
mod story;
|
||||
|
108
game/src/devtools/osm_viewer.rs
Normal file
108
game/src/devtools/osm_viewer.rs
Normal file
@ -0,0 +1,108 @@
|
||||
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::game::{PopupMsg, Transition};
|
||||
use crate::helpers::nice_map_name;
|
||||
use crate::options::OptionsPanel;
|
||||
|
||||
pub struct Viewer {
|
||||
top_panel: Panel,
|
||||
}
|
||||
|
||||
impl Viewer {
|
||||
pub fn new(ctx: &mut EventCtx, app: &mut App) -> Box<dyn State<App>> {
|
||||
app.primary.current_selection = None;
|
||||
|
||||
Box::new(Viewer {
|
||||
top_panel: Panel::new(Widget::col(vec![
|
||||
Widget::row(vec![
|
||||
Line("OpenStreetMap viewer").small_heading().draw(ctx),
|
||||
Btn::plaintext("X")
|
||||
.build(ctx, "close", Key::Escape)
|
||||
.align_right(),
|
||||
]),
|
||||
Widget::row(vec![
|
||||
"Change map:".draw_text(ctx),
|
||||
Btn::pop_up(ctx, Some(nice_map_name(app.primary.map.get_name()))).build(
|
||||
ctx,
|
||||
"change map",
|
||||
lctrl(Key::L),
|
||||
),
|
||||
]),
|
||||
Widget::row(vec![
|
||||
Btn::svg_def("system/assets/tools/settings.svg").build(ctx, "settings", None),
|
||||
Btn::svg_def("system/assets/tools/search.svg").build(
|
||||
ctx,
|
||||
"search",
|
||||
lctrl(Key::F),
|
||||
),
|
||||
Btn::plaintext("About").build_def(ctx, None),
|
||||
]),
|
||||
]))
|
||||
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
|
||||
.build(ctx),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl State<App> for Viewer {
|
||||
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
|
||||
ctx.canvas_movement();
|
||||
if ctx.redo_mouseover() {
|
||||
app.recalculate_current_selection(ctx);
|
||||
}
|
||||
|
||||
match self.top_panel.event(ctx) {
|
||||
Outcome::Clicked(x) => match x.as_ref() {
|
||||
"close" => {
|
||||
return Transition::Pop;
|
||||
}
|
||||
"change map" => {
|
||||
return Transition::Push(CityPicker::new(
|
||||
ctx,
|
||||
app,
|
||||
Box::new(|ctx, app| {
|
||||
Transition::Multi(vec![
|
||||
Transition::Pop,
|
||||
Transition::Replace(Viewer::new(ctx, app)),
|
||||
])
|
||||
}),
|
||||
));
|
||||
}
|
||||
"settings" => {
|
||||
return Transition::Push(OptionsPanel::new(ctx, app));
|
||||
}
|
||||
"search" => {
|
||||
return Transition::Push(Navigator::new(ctx, app));
|
||||
}
|
||||
"About" => {
|
||||
return Transition::Push(PopupMsg::new(
|
||||
ctx,
|
||||
"About this OSM viewer",
|
||||
vec![
|
||||
"If you have an idea about what this viewer should do, get in touch \
|
||||
at abstreet.org!",
|
||||
"",
|
||||
"Note major liberties have been taken with inferring where sidewalks \
|
||||
and crosswalks exist.",
|
||||
"Separate footpaths, bicycle trails, tram lines, etc are not imported \
|
||||
yet.",
|
||||
],
|
||||
));
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Transition::Keep
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, _: &App) {
|
||||
self.top_panel.draw(g);
|
||||
}
|
||||
}
|
@ -140,6 +140,7 @@ impl MainMenu {
|
||||
txt
|
||||
})
|
||||
.build_def(ctx, Key::P),
|
||||
Btn::text_bg2("OpenStreetMap viewer").build_def(ctx, Key::V),
|
||||
Btn::text_bg2("Contribute parking data to OpenStreetMap")
|
||||
.tooltip({
|
||||
let mut txt =
|
||||
@ -211,6 +212,9 @@ impl State<App> for MainMenu {
|
||||
"Community Proposals" => {
|
||||
return Transition::Push(Proposals::new(ctx, app, None));
|
||||
}
|
||||
"OpenStreetMap viewer" => {
|
||||
return Transition::Push(crate::devtools::osm_viewer::Viewer::new(ctx, app));
|
||||
}
|
||||
"Contribute parking data to OpenStreetMap" => {
|
||||
return Transition::Push(crate::devtools::mapping::ParkingMapper::new(
|
||||
ctx, app,
|
||||
|
Loading…
Reference in New Issue
Block a user