summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-06-08 16:12:01 -0400
committerKonstantin Käfer <mail@kkaefer.com>2015-06-08 16:13:37 -0400
commitf85889dc75a96b022bedbbfc15be6fc246ae5c6d (patch)
tree3191057129e72a2620fc5051ff2644fc2f627108 /src
parent5e661f76176dd95d65d9e1d2478342971e7fd91d (diff)
downloadqtlocation-mapboxgl-f85889dc75a96b022bedbbfc15be6fc246ae5c6d.tar.gz
allow constructing LatLng/LatLngBounds objects from TileIDs
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/util/geo.cpp19
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