|
|
@@ -10,6 +10,7 @@ extern crate lazy_static;
|
|
10
|
10
|
extern crate linked_hash_map;
|
|
11
|
11
|
#[macro_use]
|
|
12
|
12
|
extern crate log;
|
|
|
13
|
+extern crate osmpbf;
|
|
13
|
14
|
extern crate regex;
|
|
14
|
15
|
extern crate reqwest;
|
|
15
|
16
|
extern crate toml;
|
|
|
@@ -35,7 +36,11 @@ pub mod vertex_attrib;
|
|
35
|
36
|
use coord::ScreenCoord;
|
|
36
|
37
|
use glutin::{ControlFlow, ElementState, Event, GlContext, MouseButton, MouseScrollDelta, VirtualKeyCode, WindowEvent};
|
|
37
|
38
|
use map_view_gl::MapViewGl;
|
|
|
39
|
+use regex::Regex;
|
|
38
|
40
|
use std::error::Error;
|
|
|
41
|
+use std::path::PathBuf;
|
|
|
42
|
+use std::sync::mpsc;
|
|
|
43
|
+use std::thread;
|
|
39
|
44
|
use std::time::{Duration, Instant};
|
|
40
|
45
|
use tile_source::TileSource;
|
|
41
|
46
|
|
|
|
@@ -66,9 +71,20 @@ struct InputState {
|
|
66
|
71
|
mouse_pressed: bool,
|
|
67
|
72
|
}
|
|
68
|
73
|
|
|
69
|
|
-fn handle_event(event: &Event, map: &mut MapViewGl, input_state: &mut InputState, sources: &mut TileSources) -> Action {
|
|
|
74
|
+fn handle_event(
|
|
|
75
|
+ event: &Event,
|
|
|
76
|
+ map: &mut MapViewGl,
|
|
|
77
|
+ input_state: &mut InputState,
|
|
|
78
|
+ sources: &mut TileSources,
|
|
|
79
|
+ marker_rx: &mpsc::Receiver<(f64, f64)>,
|
|
|
80
|
+) -> Action {
|
|
70
|
81
|
match *event {
|
|
71
|
|
- Event::Awakened => Action::Redraw,
|
|
|
82
|
+ Event::Awakened => {
|
|
|
83
|
+ for (lat, lon) in marker_rx.try_iter() {
|
|
|
84
|
+ map.add_marker(coord::MapCoord::from_latlon(lat, lon));
|
|
|
85
|
+ }
|
|
|
86
|
+ Action::Redraw
|
|
|
87
|
+ },
|
|
72
|
88
|
Event::WindowEvent{ref event, ..} => match *event {
|
|
73
|
89
|
WindowEvent::CloseRequested => Action::Close,
|
|
74
|
90
|
WindowEvent::MouseInput { state: ElementState::Pressed, button: MouseButton::Left, .. } => {
|
|
|
@@ -227,6 +243,33 @@ fn run() -> Result<(), Box<Error>> {
|
|
227
|
243
|
mouse_pressed: false,
|
|
228
|
244
|
};
|
|
229
|
245
|
|
|
|
246
|
+ let (marker_tx, marker_rx) = mpsc::channel();
|
|
|
247
|
+ if let (Some(path), Some(pattern)) = (config.pbf_path(), config.search_pattern()) {
|
|
|
248
|
+ let pathbuf = PathBuf::from(path);
|
|
|
249
|
+ let re = Regex::new(pattern).unwrap();
|
|
|
250
|
+ let proxy = events_loop.create_proxy();
|
|
|
251
|
+
|
|
|
252
|
+ thread::spawn(move|| {
|
|
|
253
|
+ let reader = osmpbf::ElementReader::from_path(&pathbuf).unwrap();
|
|
|
254
|
+
|
|
|
255
|
+ // Increment the counter by one for each way.
|
|
|
256
|
+ reader.for_each(|element| {
|
|
|
257
|
+ match element {
|
|
|
258
|
+ osmpbf::Element::Node(_) => {},
|
|
|
259
|
+ osmpbf::Element::DenseNode(dnode) => {
|
|
|
260
|
+ for (_key, val) in dnode.tags() {
|
|
|
261
|
+ if re.is_match(val) {
|
|
|
262
|
+ marker_tx.send((dnode.lat(), dnode.lon())).unwrap();
|
|
|
263
|
+ proxy.wakeup().unwrap();
|
|
|
264
|
+ }
|
|
|
265
|
+ }
|
|
|
266
|
+ },
|
|
|
267
|
+ _ => {},
|
|
|
268
|
+ }
|
|
|
269
|
+ }).unwrap();
|
|
|
270
|
+ });
|
|
|
271
|
+ }
|
|
|
272
|
+
|
|
230
|
273
|
let duration_per_frame = Duration::from_millis((1000.0 / config.fps() - 0.5).max(0.0).floor() as u64);
|
|
231
|
274
|
info!("milliseconds per frame: {}", dur_to_sec(duration_per_frame) * 1000.0);
|
|
232
|
275
|
|
|
|
@@ -240,7 +283,7 @@ fn run() -> Result<(), Box<Error>> {
|
|
240
|
283
|
let mut action = Action::Nothing;
|
|
241
|
284
|
|
|
242
|
285
|
events_loop.run_forever(|event| {
|
|
243
|
|
- let a = handle_event(&event, &mut map, &mut input_state, &mut sources);
|
|
|
286
|
+ let a = handle_event(&event, &mut map, &mut input_state, &mut sources, &marker_rx);
|
|
244
|
287
|
action.combine_with(a);
|
|
245
|
288
|
ControlFlow::Break
|
|
246
|
289
|
});
|
|
|
@@ -250,7 +293,7 @@ fn run() -> Result<(), Box<Error>> {
|
|
250
|
293
|
}
|
|
251
|
294
|
|
|
252
|
295
|
events_loop.poll_events(|event| {
|
|
253
|
|
- let a = handle_event(&event, &mut map, &mut input_state, &mut sources);
|
|
|
296
|
+ let a = handle_event(&event, &mut map, &mut input_state, &mut sources, &marker_rx);
|
|
254
|
297
|
action.combine_with(a);
|
|
255
|
298
|
if action == Action::Close {
|
|
256
|
299
|
return;
|
|
|
@@ -268,7 +311,7 @@ fn run() -> Result<(), Box<Error>> {
|
|
268
|
311
|
std::thread::sleep(dur);
|
|
269
|
312
|
|
|
270
|
313
|
events_loop.poll_events(|event| {
|
|
271
|
|
- let a = handle_event(&event, &mut map, &mut input_state, &mut sources);
|
|
|
314
|
+ let a = handle_event(&event, &mut map, &mut input_state, &mut sources, &marker_rx);
|
|
272
|
315
|
action.combine_with(a);
|
|
273
|
316
|
if action == Action::Close {
|
|
274
|
317
|
return;
|