diff options
Diffstat (limited to 'platform/default/mbgl/storage/offline.cpp')
-rw-r--r-- | platform/default/mbgl/storage/offline.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/platform/default/mbgl/storage/offline.cpp b/platform/default/mbgl/storage/offline.cpp index 7670790be9..ab878a2d55 100644 --- a/platform/default/mbgl/storage/offline.cpp +++ b/platform/default/mbgl/storage/offline.cpp @@ -136,4 +136,26 @@ int64_t OfflineRegion::getID() const { return id; } +// Taken from https://github.com/mapbox/sphericalmercator#xyzbbox-zoom-tms_style-srs +// Computes the projected tiles for the lower left and upper right points of the bounds +// and uses that to compute the tile cover count +// +uint64_t OfflineRegion::getTileCount(const LatLngBounds& bounds, uint8_t zoom, uint16_t tileSize_) const { + + auto sw = Projection::project(bounds.southwest().wrapped(), zoom, tileSize_); + auto ne = Projection::project(bounds.northeast().wrapped(), zoom, tileSize_); + + auto x1 = floor(sw.x/ tileSize_); + auto x2 = floor((ne.x - 1) / tileSize_); + auto y1 = floor(sw.y/ tileSize_); + auto y2 = floor((ne.y - 1) / tileSize_); + + auto minX = ::fmax(std::min(x1, x2), 0); + auto maxX = std::max(x1, x2); + auto minY = (std::pow(2, zoom) - 1) - std::max(y1, y2); + auto maxY = (std::pow(2, zoom) - 1) - ::fmax(std::min(y1, y2), 0); + + return (maxX - minX + 1) * (maxY - minY + 1); + } + } // namespace mbgl |