summaryrefslogtreecommitdiff
path: root/include/mbgl/util/projection.hpp
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-09-01 16:33:35 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-09-08 17:38:42 -0700
commit50fd9175109e01c5286d3363df21aeba6e89087b (patch)
tree2f3dfada2896159f3eef64aa3f02ac231742d8a7 /include/mbgl/util/projection.hpp
parentaa4dff1095e8f5e8ad584f5f7dcab3e61d8cf8ee (diff)
downloadqtlocation-mapboxgl-50fd9175109e01c5286d3363df21aeba6e89087b.tar.gz
Fast tileCount with help from @mapbox/sphericalmercator module
Diffstat (limited to 'include/mbgl/util/projection.hpp')
-rw-r--r--include/mbgl/util/projection.hpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/include/mbgl/util/projection.hpp b/include/mbgl/util/projection.hpp
index 3cc1146513..f64502c5bc 100644
--- a/include/mbgl/util/projection.hpp
+++ b/include/mbgl/util/projection.hpp
@@ -75,10 +75,7 @@ public:
}
static Point<double> project(const LatLng& latLng, double scale) {
- return Point<double> {
- util::LONGITUDE_MAX + latLng.longitude(),
- util::LONGITUDE_MAX - util::RAD2DEG * std::log(std::tan(M_PI / 4 + latLng.latitude() * M_PI / util::DEGREES_MAX))
- } * worldSize(scale) / util::DEGREES_MAX;
+ return project_(latLng, worldSize(scale));
}
static LatLng unproject(const Point<double>& p, double scale, LatLng::WrapMode wrapMode = LatLng::Unwrapped) {
@@ -89,6 +86,23 @@ public:
wrapMode
};
}
+
+ // Project lat, lon to point in a zoom-dependent world size
+ static Point<double> project(const LatLng& point, uint8_t zoom, uint16_t tileSize) {
+ const double t2z = tileSize * std::pow(2, zoom);
+ Point<double> pt = project_(point, t2z);
+ // Flip y coordinate
+ auto x = std::round(std::min(pt.x, t2z));
+ auto y = std::round(std::min(t2z - pt.y, t2z));
+ return { x, y };
+ }
+private:
+ static Point<double> project_(const LatLng& latLng, double worldSize) {
+ return Point<double> {
+ util::LONGITUDE_MAX + latLng.longitude(),
+ util::LONGITUDE_MAX - util::RAD2DEG * std::log(std::tan(M_PI / 4 + latLng.latitude() * M_PI / util::DEGREES_MAX))
+ } * worldSize / util::DEGREES_MAX;
+ }
};
} // namespace mbgl