diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-06-08 16:12:01 -0400 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-06-08 16:13:37 -0400 |
commit | f85889dc75a96b022bedbbfc15be6fc246ae5c6d (patch) | |
tree | 3191057129e72a2620fc5051ff2644fc2f627108 /src/mbgl/util | |
parent | 5e661f76176dd95d65d9e1d2478342971e7fd91d (diff) | |
download | qtlocation-mapboxgl-f85889dc75a96b022bedbbfc15be6fc246ae5c6d.tar.gz |
allow constructing LatLng/LatLngBounds objects from TileIDs
Diffstat (limited to 'src/mbgl/util')
-rw-r--r-- | src/mbgl/util/geo.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/mbgl/util/geo.cpp b/src/mbgl/util/geo.cpp new file mode 100644 index 0000000000..b08b10d1e6 --- /dev/null +++ b/src/mbgl/util/geo.cpp @@ -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 |