Johannes Hofmann пре 7 година
родитељ
комит
fc394f3d20
4 измењених фајлова са 40 додато и 19 уклоњено
  1. 24
    7
      src/coord.rs
  2. 6
    6
      src/main.rs
  3. 9
    5
      src/search.rs
  4. 1
    1
      src/tile_layer.rs

+ 24
- 7
src/coord.rs Прегледај датотеку

@@ -1,6 +1,20 @@
1 1
 use std::f64::consts::PI;
2 2
 use tile_source::TileSourceId;
3 3
 
4
+
5
+/// A position in latitude, longitude.
6
+#[derive(Copy, Debug, PartialEq, Clone)]
7
+pub struct LatLon {
8
+    pub lat: f64,
9
+    pub lon: f64,
10
+}
11
+
12
+impl LatLon {
13
+    pub fn new(lat: f64, lon: f64) -> Self {
14
+        LatLon { lat, lon }
15
+    }
16
+}
17
+
4 18
 /// A position in map coordinates.
5 19
 /// Valid values for x and y lie in the interval [0.0, 1.0].
6 20
 #[derive(Copy, Debug, PartialEq, Clone)]
@@ -9,16 +23,19 @@ pub struct MapCoord {
9 23
     pub y: f64,
10 24
 }
11 25
 
12
-impl MapCoord {
13
-    pub fn new(x: f64, y: f64) -> MapCoord {
26
+impl From<LatLon> for MapCoord
27
+{
28
+    fn from(pos: LatLon) -> MapCoord {
29
+        let x = pos.lon * (1.0 / 360.0) + 0.5;
30
+        let pi_lat = pos.lat * (PI / 180.0);
31
+        let y = f64::ln(f64::tan(pi_lat) + 1.0 / f64::cos(pi_lat)) * (-0.5 / PI) + 0.5;
32
+
14 33
         MapCoord { x, y }
15 34
     }
35
+}
16 36
 
17
-    pub fn from_latlon(latitude: f64, longitude: f64) -> MapCoord {
18
-        let x = longitude * (1.0 / 360.0) + 0.5;
19
-        let pi_lat = latitude * (PI / 180.0);
20
-        let y = f64::ln(f64::tan(pi_lat) + 1.0 / f64::cos(pi_lat)) * (-0.5 / PI) + 0.5;
21
-
37
+impl MapCoord {
38
+    pub fn new(x: f64, y: f64) -> MapCoord {
22 39
         MapCoord { x, y }
23 40
     }
24 41
 

+ 6
- 6
src/main.rs Прегледај датотеку

@@ -36,7 +36,7 @@ pub mod tile_source;
36 36
 pub mod url_template;
37 37
 pub mod vertex_attrib;
38 38
 
39
-use coord::ScreenCoord;
39
+use coord::{LatLon, ScreenCoord};
40 40
 use glutin::{ControlFlow, ElementState, Event, GlContext, MouseButton, MouseScrollDelta, VirtualKeyCode, WindowEvent};
41 41
 use map_view_gl::MapViewGl;
42 42
 use std::error::Error;
@@ -76,12 +76,12 @@ fn handle_event(
76 76
     map: &mut MapViewGl,
77 77
     input_state: &mut InputState,
78 78
     sources: &mut TileSources,
79
-    marker_rx: &mpsc::Receiver<(f64, f64)>,
79
+    marker_rx: &mpsc::Receiver<LatLon>,
80 80
 ) -> Action {
81 81
     match *event {
82 82
         Event::Awakened => {
83
-            for (lat, lon) in marker_rx.try_iter() {
84
-                map.add_marker(coord::MapCoord::from_latlon(lat, lon));
83
+            for pos in marker_rx.try_iter() {
84
+                map.add_marker(pos.into());
85 85
             }
86 86
             Action::Redraw
87 87
         },
@@ -250,8 +250,8 @@ fn run() -> Result<(), Box<Error>> {
250 250
         search::search_pbf(
251 251
             path,
252 252
             pattern,
253
-            move |lat, lon| {
254
-                if marker_tx.send((lat, lon)).is_err() {
253
+            move |latlon| {
254
+                if marker_tx.send(latlon).is_err() {
255 255
                     return search::ControlFlow::Break;
256 256
                 }
257 257
                 proxy.wakeup().into()

+ 9
- 5
src/search.rs Прегледај датотеку

@@ -2,6 +2,8 @@ use osmpbf::{Element, ElementReader};
2 2
 use regex::Regex;
3 3
 use std::path::{Path, PathBuf};
4 4
 use std::thread;
5
+use coord::LatLon;
6
+
5 7
 
6 8
 #[derive(Debug, Eq, PartialEq)]
7 9
 pub enum ControlFlow {
@@ -26,7 +28,7 @@ pub fn search_pbf<P, F>(
26 28
     update_func: F,
27 29
 ) -> Result<thread::JoinHandle<()>, String>
28 30
 where P: AsRef<Path>,
29
-      F: Fn(f64, f64) -> ControlFlow + Send + 'static,
31
+      F: Fn(LatLon) -> ControlFlow + Send + 'static,
30 32
 {
31 33
     let pathbuf = PathBuf::from(pbf_path.as_ref());
32 34
     let re = Regex::new(search_pattern)
@@ -40,17 +42,19 @@ where P: AsRef<Path>,
40 42
                 Element::Node(node) => {
41 43
                     for (_key, val) in node.tags() {
42 44
                         if re.is_match(val) {
43
-                            if update_func(node.lat(), node.lon()) == ControlFlow::Break {
45
+                            let pos = LatLon::new(node.lat(), node.lon());
46
+                            if update_func(pos) == ControlFlow::Break {
44 47
                                 return;
45 48
                             }
46 49
                             break;
47 50
                         }
48 51
                     }
49 52
                 },
50
-                Element::DenseNode(dnode) => {
51
-                    for (_key, val) in dnode.tags() {
53
+                Element::DenseNode(node) => {
54
+                    for (_key, val) in node.tags() {
52 55
                         if re.is_match(val) {
53
-                            if update_func(dnode.lat(), dnode.lon()) == ControlFlow::Break {
56
+                            let pos = LatLon::new(node.lat(), node.lon());
57
+                            if update_func(pos) == ControlFlow::Break {
54 58
                                 return;
55 59
                             }
56 60
                             break;

+ 1
- 1
src/tile_layer.rs Прегледај датотеку

@@ -83,7 +83,7 @@ impl TileLayer {
83 83
             program,
84 84
             buffer,
85 85
             cache: TileCache::new(update_func, use_network),
86
-            atlas: TileAtlas::new(cx, atlas_tex, 256, use_async),
86
+            atlas: TileAtlas::new(cx, atlas_tex, tile_size, use_async),
87 87
         }
88 88
     }
89 89