1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use coord::MapCoord;
/// A view of a map with a rectangular viewport and a zoom.
#[derive(Clone, Debug)]
pub struct MapView {
/// Width of the viewport.
pub width: f64,
/// Height of the viewport.
pub height: f64,
/// Size of each square tile in the same unit as the viewport dimensions (usually pixels).
pub tile_size: u32,
/// The `MapCoord` that corresponds to the center of the viewport.
pub center: MapCoord,
/// The zoom value. The zoom factor is given by 2.0.powf(zoom);
pub zoom: f64,
/// Tiles only exist for integer zoom values. The tile zoom value that is used for rendering
/// is computed by the `tile_zoom` method. Increasing `tile_zoom_offset` increases the number
/// of visible tiles for a given zoom value.
pub tile_zoom_offset: f64,
}
impl MapView {
/// Constructs a new `MapView`.
pub fn new(width: f64, height: f64, tile_size: u32, center: MapCoord, zoom: f64) -> MapView {
MapView {
width,
height,
tile_size,
center,
zoom,
tile_zoom_offset: 0.0,
}
}
/// Returns the tile zoom offset.
pub fn tile_zoom_offset(map_view: &MapView) -> f64 {
map_view.tile_zoom_offset
}
/// Set the tile zoom offset.
pub fn set_tile_zoom_offset(&mut self, offset: f64) {
self.tile_zoom_offset = offset;
}
/// Set the viewport size.
pub fn set_size(&mut self, width: f64, height: f64) {
self.width = width;
self.height = height;
}
/// Set the zoom value.
pub fn set_zoom(&mut self, zoom: f64) {
self.zoom = zoom;
}
/// Change zoom value by `zoom_delta`.
pub fn zoom(&mut self, zoom_delta: f64) {
self.zoom += zoom_delta;
}
}