allow constructing LatLng/LatLngBounds objects from TileIDs

This commit is contained in:
Konstantin Käfer
2015-06-08 16:12:01 -04:00
parent 5e661f7617
commit f85889dc75
4 changed files with 89 additions and 0 deletions

19
src/mbgl/util/geo.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include <mbgl/util/geo.hpp>
#include <mbgl/map/tile_id.hpp>
#include <cmath>
namespace mbgl {
LatLng::LatLng(const TileID& id) {
latitude = id.x / std::pow(2.0, id.z) * 360.0 - 180;
const double n = M_PI - 2.0 * M_PI * id.y / std::pow(2.0, id.z);
longitude = 180.0 / M_PI * std::atan(0.5 * (std::exp(n) - std::exp(-n)));
}
LatLngBounds::LatLngBounds(const TileID& id)
: sw(TileID{ id.z, id.x, id.y + 1, id.sourceZ }),
ne(TileID{ id.z, id.x + 1, id.y, id.sourceZ }) {
}
} // end namespace mbgl