Skip to content

Commit 7cd779a

Browse files
committed
tile: pixel size calculation functions. Don't expose the fixed tilesize
1 parent 328d80d commit 7cd779a

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

include/infra/tile.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
namespace inf {
1717

18-
constexpr const uint16_t TILE_SIZE = 256;
19-
2018
// An XYZ web mercator tile
2119
class Tile
2220
{
@@ -189,26 +187,8 @@ class Tile
189187
int32_t _z = 0;
190188
};
191189

192-
// returns the 0 based index of the tile in the given extent
193-
// tiles are row major, 0 is the top left tile
194-
inline std::optional<uint32_t> tile_index(const Tile& tile, const inf::GeoMetadata& meta) noexcept
195-
{
196-
std::optional<uint32_t> result;
197-
198-
auto upperLeft = crs::lat_lon_to_web_mercator(tile.center());
199-
200-
if (meta.is_on_map(upperLeft)) {
201-
const auto tilesPerRow = inf::truncate<uint32_t>(meta.cols / TILE_SIZE);
202-
203-
auto cell = meta.convert_point_to_cell(upperLeft);
204-
cell.r /= TILE_SIZE;
205-
cell.c /= TILE_SIZE;
206-
result = cell.r * tilesPerRow + cell.c;
207-
}
208-
209-
return result;
210-
}
211-
212190
GeoMetadata create_xyz_tile_aligned_extent(const inf::GeoMetadata& extent);
191+
double pixel_size_at_zoom_level(uint32_t zoomLevel) noexcept;
192+
uint32_t zoom_level_for_pixel_size(double pixelSize, bool preferHigher) noexcept;
213193

214194
}

tile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
namespace inf {
88

9-
#ifdef INFRA_GDAL_ENABLED
10-
static double pixel_size_at_zoom_level(uint32_t zoomLevel) noexcept
9+
constexpr const uint16_t TILE_SIZE = 256;
10+
11+
double pixel_size_at_zoom_level(uint32_t zoomLevel) noexcept
1112
{
1213
const auto tilesPerRow = std::pow(2, zoomLevel);
1314
const auto metersPerTile = constants::EARTH_CIRCUMFERENCE_M / tilesPerRow;
1415

1516
return metersPerTile / TILE_SIZE;
1617
}
1718

18-
static uint32_t zoom_level_for_pixel_size(double pixelSize, bool preferHigher) noexcept
19+
uint32_t zoom_level_for_pixel_size(double pixelSize, bool preferHigher) noexcept
1920
{
2021
uint32_t zoomLevel = 20;
2122
while (zoomLevel > 0) {
@@ -33,7 +34,6 @@ static uint32_t zoom_level_for_pixel_size(double pixelSize, bool preferHigher) n
3334

3435
return zoomLevel;
3536
}
36-
#endif
3737

3838
GeoMetadata create_xyz_tile_aligned_extent(const inf::GeoMetadata& extent)
3939
{

0 commit comments

Comments
 (0)