|
|
@@ -1,7 +1,7 @@
|
|
1
|
1
|
use atmos_layer::AtmosLayer;
|
|
2
|
2
|
use context::Context;
|
|
3
|
3
|
use coord::{MapCoord, ScreenCoord};
|
|
4
|
|
-use map_view::MapView;
|
|
|
4
|
+use map_view::{MapView, MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL};
|
|
5
|
5
|
use marker_layer::MarkerLayer;
|
|
6
|
6
|
use mercator_tile_layer::MercatorTileLayer;
|
|
7
|
7
|
use mercator_view::MercatorView;
|
|
|
@@ -15,9 +15,6 @@ use tile_cache::TileCache;
|
|
15
|
15
|
use tile_source::TileSource;
|
|
16
|
16
|
|
|
17
|
17
|
|
|
18
|
|
-const MIN_ZOOM_LEVEL: f64 = 0.0;
|
|
19
|
|
-const MAX_ZOOM_LEVEL: f64 = 22.0;
|
|
20
|
|
-
|
|
21
|
18
|
#[derive(Debug)]
|
|
22
|
19
|
pub struct MapViewGl {
|
|
23
|
20
|
map_view: MapView,
|
|
|
@@ -57,16 +54,12 @@ impl MapViewGl {
|
|
57
|
54
|
{
|
|
58
|
55
|
let tile_size = 256;
|
|
59
|
56
|
|
|
60
|
|
- let mut map_view = MercatorView::initial_map_view(
|
|
|
57
|
+ let map_view = MercatorView::initial_map_view(
|
|
61
|
58
|
f64::from(initial_size.0),
|
|
62
|
59
|
f64::from(initial_size.1),
|
|
63
|
60
|
tile_size,
|
|
64
|
61
|
);
|
|
65
|
62
|
|
|
66
|
|
- if map_view.zoom < MIN_ZOOM_LEVEL {
|
|
67
|
|
- map_view.zoom = MIN_ZOOM_LEVEL;
|
|
68
|
|
- }
|
|
69
|
|
-
|
|
70
|
63
|
let atlas_size = {
|
|
71
|
64
|
let default_size = 2048;
|
|
72
|
65
|
let max_size = cx.max_texture_size() as u32;
|
|
|
@@ -242,27 +235,12 @@ impl MapViewGl {
|
|
242
|
235
|
}
|
|
243
|
236
|
}
|
|
244
|
237
|
|
|
245
|
|
- pub fn step_zoom(&mut self, steps: i32, step_size: f64) {
|
|
246
|
|
- let new_zoom = {
|
|
247
|
|
- let z = (self.map_view.zoom + f64::from(steps) * step_size) / step_size;
|
|
248
|
|
- if steps > 0 {
|
|
249
|
|
- z.ceil() * step_size
|
|
250
|
|
- } else {
|
|
251
|
|
- z.floor() * step_size
|
|
252
|
|
- }
|
|
253
|
|
- }.max(MIN_ZOOM_LEVEL).min(MAX_ZOOM_LEVEL);
|
|
254
|
|
-
|
|
255
|
|
- self.map_view.set_zoom(new_zoom);
|
|
|
238
|
+ pub fn zoom(&mut self, zoom_delta: f64) {
|
|
|
239
|
+ self.map_view.zoom(zoom_delta);
|
|
256
|
240
|
}
|
|
257
|
241
|
|
|
258
|
|
- pub fn zoom(&mut self, zoom_delta: f64) {
|
|
259
|
|
- if self.map_view.zoom + zoom_delta < MIN_ZOOM_LEVEL {
|
|
260
|
|
- self.map_view.set_zoom(MIN_ZOOM_LEVEL);
|
|
261
|
|
- } else if self.map_view.zoom + zoom_delta > MAX_ZOOM_LEVEL {
|
|
262
|
|
- self.map_view.set_zoom(MAX_ZOOM_LEVEL);
|
|
263
|
|
- } else {
|
|
264
|
|
- self.map_view.zoom(zoom_delta);
|
|
265
|
|
- }
|
|
|
242
|
+ pub fn step_zoom(&mut self, steps: i32, step_size: f64) {
|
|
|
243
|
+ self.map_view.step_zoom(steps, step_size);
|
|
266
|
244
|
}
|
|
267
|
245
|
|
|
268
|
246
|
pub fn zoom_at(&mut self, pos: ScreenCoord, zoom_delta: f64) {
|
|
|
@@ -278,8 +256,13 @@ impl MapViewGl {
|
|
278
|
256
|
self.map_view.center.normalize_xy();
|
|
279
|
257
|
},
|
|
280
|
258
|
Projection::Orthografic => {
|
|
281
|
|
- //TODO ensure new zoom level in between min/max zoom level
|
|
282
|
|
- OrthograficView::zoom_at(&mut self.map_view, pos, zoom_delta);
|
|
|
259
|
+ if self.map_view.zoom + zoom_delta < MIN_ZOOM_LEVEL {
|
|
|
260
|
+ OrthograficView::set_zoom_at(&mut self.map_view, pos, MIN_ZOOM_LEVEL);
|
|
|
261
|
+ } else if self.map_view.zoom + zoom_delta > MAX_ZOOM_LEVEL {
|
|
|
262
|
+ OrthograficView::set_zoom_at(&mut self.map_view, pos, MAX_ZOOM_LEVEL);
|
|
|
263
|
+ } else {
|
|
|
264
|
+ OrthograficView::zoom_at(&mut self.map_view, pos, zoom_delta);
|
|
|
265
|
+ }
|
|
283
|
266
|
},
|
|
284
|
267
|
}
|
|
285
|
268
|
}
|
|
|
@@ -299,7 +282,9 @@ impl MapViewGl {
|
|
299
|
282
|
pub fn restore_session(&mut self, session: &Session) {
|
|
300
|
283
|
self.map_view.center = session.view_center;
|
|
301
|
284
|
self.map_view.center.normalize_xy();
|
|
302
|
|
- self.map_view.zoom = MIN_ZOOM_LEVEL.max(MAX_ZOOM_LEVEL.min(session.zoom));
|
|
|
285
|
+ self.map_view.zoom = session.zoom
|
|
|
286
|
+ .max(MIN_ZOOM_LEVEL)
|
|
|
287
|
+ .min(MAX_ZOOM_LEVEL);
|
|
303
|
288
|
self.projection = session.projection;
|
|
304
|
289
|
}
|
|
305
|
290
|
|