@@ -22,35 +22,34 @@ RasterOverviews::RasterOverviews(UniqueRasterPointer input_raster, int min_zoom,
22
22
// Guesses (numerically) maximal zoom level from a raster resolution
23
23
int RasterOverviews::guess_max_zoom_level (double resolution)
24
24
{
25
- // pixel_size_z0 is a magic number that is number of meters per pixel on zoom level 0, given tile size is 256 pixels.
26
- // This number is approximate and does not account for latitude, i.e. uses pixel size on equator.
27
- // The formula is: earth circumference * 2 * pi / 256
28
- // "Real" number can be off up to 30% depending on the latitude. More details here: https://msdn.microsoft.com/en-us/library/aa940990.aspx
29
- const double pixel_size_z0 = 156543.04 ;
25
+ // pixel_size_z0 is a magic number that is number of meters per pixel on zoom level 0, given tile size is 256 pixels.
26
+ // This number is approximate and does not account for latitude, i.e. uses pixel size on equator.
27
+ // The formula is: earth circumference * 2 * pi / 256
28
+ // "Real" number can be off up to 30% depending on the latitude. More details here: https://msdn.microsoft.com/en-us/library/aa940990.aspx
29
+ const double pixel_size_z0 = 156543.04 ;
30
30
return static_cast <int >(round (log2 (pixel_size_z0 / resolution)));
31
31
}
32
32
33
33
// Guesses (numerically) minimal zoom level from a raster resolution and it's size
34
34
int RasterOverviews::guess_min_zoom_level (int max_zoom_level)
35
35
{
36
- // This constant is an arbitrary number representing some minimal size to which the raster can be downsized when 'zooming out' a map.
37
- // Math is simple:
38
- // 2**max_zoom = raster_size; 2**min_zoom = 128
39
- // Solve it in regards to min_zoom and there you have it.
40
- const int MINIMAL_RASTER_SIZE = 128 ;
36
+ // This constant is an arbitrary number representing some minimal size to which the raster can be downsized when 'zooming out' a map.
37
+ // Math is simple:
38
+ // 2**max_zoom = raster_size; 2**min_zoom = 128
39
+ // Solve it in regards to min_zoom and there you have it.
40
+ const int MINIMAL_RASTER_SIZE = 128 ;
41
41
const double quotient = MINIMAL_RASTER_SIZE * (1 << max_zoom_level);
42
42
43
43
int raster_width = m_base_raster->get_width ();
44
44
int raster_height = m_base_raster->get_height ();
45
45
46
- TNTN_LOG_DEBUG (" guess_min_zoom_level: raster_width: {}, raster_height: {}" ,
47
- raster_width,
48
- raster_height);
46
+ TNTN_LOG_DEBUG (
47
+ " guess_min_zoom_level: raster_width: {}, raster_height: {}" , raster_width, raster_height);
49
48
50
49
int zoom_x = static_cast <int >(floor (log2 (quotient / raster_width)));
51
50
int zoom_y = static_cast <int >(floor (log2 (quotient / raster_height)));
52
51
53
- // Cap the resulting value so it won't go below 0 and we wouldn't end up with negative zoom levels
52
+ // Cap the resulting value so it won't go below 0 and we wouldn't end up with negative zoom levels
54
53
return std::max (0 , std::min (zoom_x, zoom_y));
55
54
}
56
55
@@ -60,12 +59,21 @@ void RasterOverviews::compute_zoom_levels()
60
59
m_estimated_min_zoom = guess_min_zoom_level (m_estimated_max_zoom);
61
60
62
61
m_min_zoom = std::max (m_min_zoom, m_estimated_min_zoom);
63
- m_max_zoom = std::min (std::max (0 , m_max_zoom), m_estimated_max_zoom);
62
+
63
+ if (m_max_zoom < 0 || m_max_zoom > m_estimated_max_zoom)
64
+ {
65
+ m_max_zoom = m_estimated_max_zoom;
66
+ }
64
67
65
68
if (m_max_zoom < m_min_zoom)
66
69
{
67
70
std::swap (m_min_zoom, m_max_zoom);
68
71
}
72
+
73
+ TNTN_LOG_INFO (
74
+ " After checking with data, tiles will be generated in a range between {} and {}" ,
75
+ m_min_zoom,
76
+ m_max_zoom);
69
77
}
70
78
71
79
bool RasterOverviews::next (RasterOverview& overview)
@@ -88,11 +96,12 @@ bool RasterOverviews::next(RasterOverview& overview)
88
96
overview.resolution = output_raster->get_cell_size ();
89
97
overview.raster = std::move (output_raster);
90
98
91
- TNTN_LOG_DEBUG (" Generated next overview at zoom {}, window size {}, min zoom level {}, max zoom level {}" ,
92
- m_current_zoom + 1 ,
93
- window_size,
94
- m_min_zoom,
95
- m_max_zoom);
99
+ TNTN_LOG_DEBUG (
100
+ " Generated next overview at zoom {}, window size {}, min zoom level {}, max zoom level {}" ,
101
+ m_current_zoom + 1 ,
102
+ window_size,
103
+ m_min_zoom,
104
+ m_max_zoom);
96
105
97
106
return true ;
98
107
}
0 commit comments