summaryrefslogtreecommitdiff
path: root/src/mbgl/util/tile_coordinate.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/util/tile_coordinate.hpp')
-rw-r--r--src/mbgl/util/tile_coordinate.hpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/mbgl/util/tile_coordinate.hpp b/src/mbgl/util/tile_coordinate.hpp
new file mode 100644
index 0000000000..9962c35b18
--- /dev/null
+++ b/src/mbgl/util/tile_coordinate.hpp
@@ -0,0 +1,39 @@
+#ifndef MBGL_UTIL_TILE_COORDINATE
+#define MBGL_UTIL_TILE_COORDINATE
+
+#include <mbgl/style/types.hpp>
+#include <mbgl/map/transform_state.hpp>
+
+
+namespace mbgl {
+
+class TransformState;
+
+// Has floating point x/y coordinates.
+// Used for computing the tiles that need to be visible in the viewport.
+class TileCoordinate {
+public:
+ double x, y, z;
+
+ static TileCoordinate fromLatLng(const TransformState& state, double zoom, const LatLng& latLng) {
+ const double scale = std::pow(2, zoom - state.getZoom());
+ return {
+ state.lngX(latLng.longitude) * scale / util::tileSize,
+ state.latY(latLng.latitude) * scale / util::tileSize,
+ zoom
+ };
+ }
+
+ static TileCoordinate fromScreenCoordinate(const TransformState& state, double zoom, const ScreenCoordinate& point) {
+ return fromLatLng(state, zoom, state.screenCoordinateToLatLng(point));
+ }
+
+ TileCoordinate zoomTo(double zoom) const {
+ double scale = std::pow(2, zoom - z);
+ return { x * scale, y * scale, zoom };
+ }
+};
+
+} // namespace mbgl
+
+#endif