summaryrefslogtreecommitdiff
path: root/src/mbgl/util/geo.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-10-14 18:08:02 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-10-20 13:54:19 -0700
commitc5b95032a5cb9d3c7c39a7a74656f33de1c68d6e (patch)
tree6c73190d5f86b40c55e810bc244d30766051acdc /src/mbgl/util/geo.cpp
parent597b2b48511b68c7a6494386b414da479c436bd7 (diff)
downloadqtlocation-mapboxgl-c5b95032a5cb9d3c7c39a7a74656f33de1c68d6e.tar.gz
[core] Annotation refactor
Diffstat (limited to 'src/mbgl/util/geo.cpp')
-rw-r--r--src/mbgl/util/geo.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/mbgl/util/geo.cpp b/src/mbgl/util/geo.cpp
index 21a591cb43..035eb2d20a 100644
--- a/src/mbgl/util/geo.cpp
+++ b/src/mbgl/util/geo.cpp
@@ -1,4 +1,5 @@
#include <mbgl/util/geo.hpp>
+#include <mbgl/util/constants.hpp>
#include <mbgl/map/tile_id.hpp>
#include <cmath>
@@ -11,6 +12,17 @@ LatLng::LatLng(const TileID& id) {
latitude = 180.0 / M_PI * std::atan(0.5 * (std::exp(n) - std::exp(-n)));
}
+vec2<double> LatLng::project() const {
+ // Clamp to the latitude limits of Mercator.
+ const double constrainedLatitude = ::fmin(::fmax(latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX);
+
+ // Project a coordinate into unit space in a square map.
+ const double sine = std::sin(constrainedLatitude * M_PI / 180.0);
+ const double x = longitude / 360.0 + 0.5;
+ const double y = 0.5 - 0.25 * std::log((1.0 + sine) / (1.0 - sine)) / M_PI;
+ return { x, y };
+}
+
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 }) {