Browse Source

Handle different image file formats

Johannes Hofmann 8 years ago
parent
commit
895c8b1232
5 changed files with 19 additions and 3 deletions
  1. 1
    0
      deltamap.toml
  2. 2
    0
      src/config.rs
  3. 11
    1
      src/main.rs
  4. 1
    1
      src/tile_loader.rs
  5. 4
    1
      src/tile_source.rs

+ 1
- 0
deltamap.toml View File

3
 [sources.OSM]
3
 [sources.OSM]
4
 max_zoom = 19
4
 max_zoom = 19
5
 url_template = "http://a.tile.openstreetmap.org/{z}/{x}/{y}.png"
5
 url_template = "http://a.tile.openstreetmap.org/{z}/{x}/{y}.png"
6
+extension = "png"

+ 2
- 0
src/config.rs View File

16
 struct Source {
16
 struct Source {
17
     max_zoom: u32,
17
     max_zoom: u32,
18
     url_template: String,
18
     url_template: String,
19
+    extension: String,
19
 }
20
 }
20
 
21
 
21
 impl Config {
22
 impl Config {
47
                     id as u32,
48
                     id as u32,
48
                     source.url_template.clone(),
49
                     source.url_template.clone(),
49
                     path,
50
                     path,
51
+                    source.extension.clone(),
50
                     source.max_zoom,
52
                     source.max_zoom,
51
                 ),
53
                 ),
52
             ));
54
             ));

+ 11
- 1
src/main.rs View File

170
     let mut sources = TileSources::new(config.tile_sources()).unwrap();
170
     let mut sources = TileSources::new(config.tile_sources()).unwrap();
171
 
171
 
172
     let mut window = glutin::WindowBuilder::new().build().unwrap();
172
     let mut window = glutin::WindowBuilder::new().build().unwrap();
173
-    window.set_title("DeltaMap");
173
+    window.set_title(&("DeltaMap - ".to_string() + sources.current_name()));
174
     window.set_window_resize_callback(Some(resize_callback as fn(u32, u32)));
174
     window.set_window_resize_callback(Some(resize_callback as fn(u32, u32)));
175
     let _ = unsafe { window.make_current() };
175
     let _ = unsafe { window.make_current() };
176
 
176
 
194
 
194
 
195
     'outer: for event in window.wait_events() {
195
     'outer: for event in window.wait_events() {
196
         let mut start_loop = Instant::now();
196
         let mut start_loop = Instant::now();
197
+        let start_source_id = sources.current().id();
197
 
198
 
198
         let mut redraw = false;
199
         let mut redraw = false;
199
 
200
 
247
             let diff = start_loop.elapsed();
248
             let diff = start_loop.elapsed();
248
             println!("EVENT LOOP SECS {}", diff.as_secs() as f64 + f64::from(diff.subsec_nanos()) * 1e-9);
249
             println!("EVENT LOOP SECS {}", diff.as_secs() as f64 + f64::from(diff.subsec_nanos()) * 1e-9);
249
         }
250
         }
251
+
252
+        // set window title
253
+        if sources.current().id() != start_source_id {
254
+            window.set_title(&("DeltaMap - ".to_string() + sources.current_name()));
255
+        }
250
     }
256
     }
251
 }
257
 }
252
 
258
 
271
         &self.sources[self.current_index].1
277
         &self.sources[self.current_index].1
272
     }
278
     }
273
 
279
 
280
+    pub fn current_name(&self) -> &str {
281
+        &self.sources[self.current_index].0
282
+    }
283
+
274
     pub fn switch_to_next(&mut self) {
284
     pub fn switch_to_next(&mut self) {
275
         self.current_index = (self.current_index + 1) % self.sources.len();
285
         self.current_index = (self.current_index + 1) % self.sources.len();
276
     }
286
     }

+ 1
- 1
src/tile_loader.rs View File

48
     {
48
     {
49
         let mut client_opt = None;
49
         let mut client_opt = None;
50
         while let Ok((tile, url, path, write_to_file)) = request_rx.recv() {
50
         while let Ok((tile, url, path, write_to_file)) = request_rx.recv() {
51
-            println!("work {:?}", tile);
51
+            println!("work {:?} {:?}", tile, path);
52
             match image::open(&path) {
52
             match image::open(&path) {
53
                 Ok(img) => {
53
                 Ok(img) => {
54
                     result_tx.send((tile, Some(img))).unwrap();
54
                     result_tx.send((tile, Some(img))).unwrap();

+ 4
- 1
src/tile_source.rs View File

7
     id: u32,
7
     id: u32,
8
     url_template: String,
8
     url_template: String,
9
     directory: PathBuf,
9
     directory: PathBuf,
10
+    extension: String,
10
     max_zoom: u32,
11
     max_zoom: u32,
11
 }
12
 }
12
 
13
 
20
         id: u32,
21
         id: u32,
21
         url_template: S,
22
         url_template: S,
22
         directory: P,
23
         directory: P,
24
+        extension: String,
23
         max_zoom: u32,
25
         max_zoom: u32,
24
     ) -> Self {
26
     ) -> Self {
25
         TileSource {
27
         TileSource {
26
             id: id,
28
             id: id,
27
             url_template: url_template.into(),
29
             url_template: url_template.into(),
28
             directory: directory.into(),
30
             directory: directory.into(),
31
+            extension: extension,
29
             max_zoom: max_zoom,
32
             max_zoom: max_zoom,
30
         }
33
         }
31
     }
34
     }
40
         let mut path = PathBuf::from(&self.directory);
43
         let mut path = PathBuf::from(&self.directory);
41
         path.push(tile_coord.zoom.to_string());
44
         path.push(tile_coord.zoom.to_string());
42
         path.push(tile_coord.x.to_string());
45
         path.push(tile_coord.x.to_string());
43
-        path.push(tile_coord.y.to_string() + ".png");
46
+        path.push(tile_coord.y.to_string() + "." + &self.extension);
44
 
47
 
45
         path
48
         path
46
     }
49
     }