diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-01-15 15:13:16 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-01-18 16:54:58 -0800 |
commit | 47b69100f984bfc9e2e69cb7fa731c57d220d7dc (patch) | |
tree | fee8f72c06d55eb0954a058f62c1d893865376a8 /src | |
parent | bf87eaa7b8aa049358559a96f290603e13ac736b (diff) | |
download | qtlocation-mapboxgl-47b69100f984bfc9e2e69cb7fa731c57d220d7dc.tar.gz |
[core, ios, osx, android, glfw] Flipped origin of Map::latLngForPixel(), Map::pixelForLatLng()
Map and Transform methods assume an origin at the top-left corner of the view, like iOS, Android, and GLFW but unlike OS X. Transform is responsible for flipping coordinates between the top-left origin of Map and the bottom-left origin of TransformState.
Fixes #3574.
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/map.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/map/transform.cpp | 14 | ||||
-rw-r--r-- | src/mbgl/map/transform.hpp | 4 |
3 files changed, 26 insertions, 4 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index b0cc49968c..e710ca4c14 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -259,12 +259,13 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const Ed // Calculate the bounds of the possibly rotated shape with respect to the viewport. PrecisionPoint nePixel = {-INFINITY, -INFINITY}; PrecisionPoint swPixel = {INFINITY, INFINITY}; + double viewportHeight = getHeight(); for (LatLng latLng : latLngs) { PrecisionPoint pixel = pixelForLatLng(latLng); swPixel.x = std::min(swPixel.x, pixel.x); nePixel.x = std::max(nePixel.x, pixel.x); - swPixel.y = std::min(swPixel.y, pixel.y); - nePixel.y = std::max(nePixel.y, pixel.y); + swPixel.y = std::min(swPixel.y, viewportHeight - pixel.y); + nePixel.y = std::max(nePixel.y, viewportHeight - pixel.y); } double width = nePixel.x - swPixel.x; double height = nePixel.y - swPixel.y; @@ -289,6 +290,9 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const Ed (paddedNEPixel.x + paddedSWPixel.x) / 2, (paddedNEPixel.y + paddedSWPixel.y) / 2, }; + + // CameraOptions origin is at the top-left corner. + centerPixel.y = viewportHeight - centerPixel.y; options.center = latLngForPixel(centerPixel); options.zoom = zoom; @@ -397,11 +401,11 @@ LatLng Map::latLngForProjectedMeters(const ProjectedMeters& projectedMeters) con } PrecisionPoint Map::pixelForLatLng(const LatLng& latLng) const { - return transform->getState().latLngToPoint(latLng); + return transform->latLngToPoint(latLng); } LatLng Map::latLngForPixel(const PrecisionPoint& pixel) const { - return transform->getState().pointToLatLng(pixel); + return transform->pointToLatLng(pixel); } #pragma mark - Annotations diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 69af657ecd..1363e2abd5 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -641,3 +641,17 @@ void Transform::cancelTransitions() { void Transform::setGestureInProgress(bool inProgress) { state.gestureInProgress = inProgress; } + +#pragma mark Conversion and projection + +PrecisionPoint Transform::latLngToPoint(const LatLng& latLng) const { + PrecisionPoint point = state.latLngToPoint(latLng); + point.y = state.height - point.y; + return point; +} + +LatLng Transform::pointToLatLng(const PrecisionPoint& point) const { + PrecisionPoint flippedPoint = point; + flippedPoint.y = state.height - flippedPoint.y; + return state.pointToLatLng(flippedPoint); +} diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index cb3378a532..bef6c6c87e 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -123,6 +123,10 @@ public: bool isRotating() const { return state.isRotating(); } bool isScaling() const { return state.isScaling(); } bool isPanning() const { return state.isPanning(); } + + // Conversion and projection + PrecisionPoint latLngToPoint(const LatLng&) const; + LatLng pointToLatLng(const PrecisionPoint&) const; private: void unwrapLatLng(LatLng&); |