|
|
@@ -49,13 +49,13 @@ pub mod tile_source;
|
|
49
|
49
|
pub mod url_template;
|
|
50
|
50
|
pub mod vertex_attrib;
|
|
51
|
51
|
|
|
52
|
|
-use coord::ScreenCoord;
|
|
|
52
|
+use coord::{LatLonDeg, ScreenCoord};
|
|
53
|
53
|
use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalPosition};
|
|
54
|
54
|
use glutin::{ControlFlow, ElementState, Event, GlContext, MouseButton, MouseScrollDelta, VirtualKeyCode, WindowEvent};
|
|
55
|
55
|
use map_view_gl::MapViewGl;
|
|
56
|
56
|
use path_layer::PathElement;
|
|
57
|
57
|
use search::MatchItem;
|
|
58
|
|
-use std::collections::hash_set::HashSet;
|
|
|
58
|
+use std::collections::{HashMap, HashSet};
|
|
59
|
59
|
use std::error::Error;
|
|
60
|
60
|
use std::sync::mpsc;
|
|
61
|
61
|
use std::time::{Duration, Instant};
|
|
|
@@ -90,20 +90,55 @@ struct InputState {
|
|
90
|
90
|
dpi_factor: f64,
|
|
91
|
91
|
}
|
|
92
|
92
|
|
|
|
93
|
+struct QueryState {
|
|
|
94
|
+ way_nodes: HashMap<i64, LatLonDeg>,
|
|
|
95
|
+ incomplete_ways: Vec<Vec<i64>>,
|
|
|
96
|
+}
|
|
|
97
|
+
|
|
93
|
98
|
fn handle_event(
|
|
94
|
99
|
event: &Event,
|
|
95
|
100
|
map: &mut MapViewGl,
|
|
96
|
101
|
input_state: &mut InputState,
|
|
|
102
|
+ query_state: &mut QueryState,
|
|
97
|
103
|
sources: &mut TileSources,
|
|
98
|
104
|
marker_rx: &mpsc::Receiver<HashSet<MatchItem>>,
|
|
99
|
105
|
) -> Action {
|
|
100
|
106
|
trace!("{:?}", event);
|
|
101
|
107
|
match *event {
|
|
102
|
108
|
Event::Awakened => {
|
|
|
109
|
+ let mut check_ways = false;
|
|
103
|
110
|
for item in marker_rx.try_iter().flat_map(|c| c.into_iter()) {
|
|
104
|
111
|
match item {
|
|
105
|
112
|
MatchItem::Node{pos, ..} => map.add_marker(pos.into()),
|
|
106
|
|
- MatchItem::Way{pos, ..} => map.add_path_element(PathElement::MoveTo(pos.into())),
|
|
|
113
|
+ MatchItem::WayNode{id, pos} => {
|
|
|
114
|
+ query_state.way_nodes.insert(id, pos);
|
|
|
115
|
+ check_ways = true;
|
|
|
116
|
+ }
|
|
|
117
|
+ MatchItem::Way{nodes, ..} => {
|
|
|
118
|
+ query_state.incomplete_ways.push(nodes);
|
|
|
119
|
+ check_ways = true;
|
|
|
120
|
+ },
|
|
|
121
|
+ }
|
|
|
122
|
+ }
|
|
|
123
|
+ if check_ways {
|
|
|
124
|
+ let mut complete_ways = vec![];
|
|
|
125
|
+ 'outer: for (way_index, way) in query_state.incomplete_ways.iter().enumerate() {
|
|
|
126
|
+ for node_id in way {
|
|
|
127
|
+ if !query_state.way_nodes.contains_key(&node_id) {
|
|
|
128
|
+ continue 'outer;
|
|
|
129
|
+ }
|
|
|
130
|
+ }
|
|
|
131
|
+ complete_ways.push(way_index);
|
|
|
132
|
+ // all nodes present
|
|
|
133
|
+ if !way.is_empty() {
|
|
|
134
|
+ map.add_path_element(PathElement::MoveTo((*query_state.way_nodes.get(&way[0]).unwrap()).into()));
|
|
|
135
|
+ for node_id in way.iter().skip(1) {
|
|
|
136
|
+ map.add_path_element(PathElement::LineTo((*query_state.way_nodes.get(node_id).unwrap()).into()));
|
|
|
137
|
+ }
|
|
|
138
|
+ }
|
|
|
139
|
+ }
|
|
|
140
|
+ for way_index in complete_ways.into_iter().rev() {
|
|
|
141
|
+ query_state.incomplete_ways.swap_remove(way_index);
|
|
107
|
142
|
}
|
|
108
|
143
|
}
|
|
109
|
144
|
Action::Redraw
|
|
|
@@ -312,6 +347,11 @@ fn run() -> Result<(), Box<Error>> {
|
|
312
|
347
|
dpi_factor: window.get_hidpi_factor(),
|
|
313
|
348
|
};
|
|
314
|
349
|
|
|
|
350
|
+ let mut query_state = QueryState {
|
|
|
351
|
+ way_nodes: HashMap::new(),
|
|
|
352
|
+ incomplete_ways: vec![],
|
|
|
353
|
+ };
|
|
|
354
|
+
|
|
315
|
355
|
let mut map = {
|
|
316
|
356
|
let proxy = events_loop.create_proxy();
|
|
317
|
357
|
|
|
|
@@ -370,7 +410,7 @@ fn run() -> Result<(), Box<Error>> {
|
|
370
|
410
|
let mut action = Action::Nothing;
|
|
371
|
411
|
|
|
372
|
412
|
events_loop.run_forever(|event| {
|
|
373
|
|
- let a = handle_event(&event, &mut map, &mut input_state, &mut sources, &marker_rx);
|
|
|
413
|
+ let a = handle_event(&event, &mut map, &mut input_state, &mut query_state, &mut sources, &marker_rx);
|
|
374
|
414
|
action.combine_with(a);
|
|
375
|
415
|
ControlFlow::Break
|
|
376
|
416
|
});
|
|
|
@@ -380,7 +420,7 @@ fn run() -> Result<(), Box<Error>> {
|
|
380
|
420
|
}
|
|
381
|
421
|
|
|
382
|
422
|
events_loop.poll_events(|event| {
|
|
383
|
|
- let a = handle_event(&event, &mut map, &mut input_state, &mut sources, &marker_rx);
|
|
|
423
|
+ let a = handle_event(&event, &mut map, &mut input_state, &mut query_state, &mut sources, &marker_rx);
|
|
384
|
424
|
action.combine_with(a);
|
|
385
|
425
|
if action == Action::Close {
|
|
386
|
426
|
return;
|
|
|
@@ -398,7 +438,7 @@ fn run() -> Result<(), Box<Error>> {
|
|
398
|
438
|
std::thread::sleep(dur);
|
|
399
|
439
|
|
|
400
|
440
|
events_loop.poll_events(|event| {
|
|
401
|
|
- let a = handle_event(&event, &mut map, &mut input_state, &mut sources, &marker_rx);
|
|
|
441
|
+ let a = handle_event(&event, &mut map, &mut input_state, &mut query_state, &mut sources, &marker_rx);
|
|
402
|
442
|
action.combine_with(a);
|
|
403
|
443
|
if action == Action::Close {
|
|
404
|
444
|
return;
|