summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-10 03:24:47 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-10 14:00:42 +0200
commit1a4b8f3e2f76fd55abccf09b6a07bc1035aa89a8 (patch)
tree440bede80048296775051c900af2a349c7614973 /src
parent7dde622db130a15865262ce45b87a4ec28313981 (diff)
downloadqtlocation-mapboxgl-1a4b8f3e2f76fd55abccf09b6a07bc1035aa89a8.tar.gz
[core] Fix screen coordinates when crossing the antimeridian
If the center and point coordinates are not in the same side of the antimeridian, we need to unwrap the point longitude to make sure it can still be seen from the visible side of the antimeridian that is opposite to the center side. Fixes #4155.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/transform.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 45386b9dc8..d3cd30a627 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -660,7 +660,21 @@ void Transform::setGestureInProgress(bool inProgress) {
ScreenCoordinate Transform::latLngToScreenCoordinate(const LatLng& latLng) const {
if (!latLng) return {};
- ScreenCoordinate point = state.latLngToScreenCoordinate(latLng);
+
+ // If the center and point coordinates are not in the same side of the
+ // antimeridian, we need to unwrap the point longitude to make sure it can
+ // still be seen from the visible side of the antimeridian that is opposite
+ // to the center side.
+ double longitude = latLng.longitude;
+ const double centerLng = getLatLng().longitude;
+ if (centerLng - latLng.longitude > util::LONGITUDE_MAX) {
+ if (centerLng > 0 && latLng.longitude < 0) {
+ longitude += util::DEGREES_MAX;
+ } else if (centerLng < 0 && latLng.longitude > 0) {
+ longitude -= util::DEGREES_MAX;
+ }
+ }
+ ScreenCoordinate point = state.latLngToScreenCoordinate({ latLng.latitude, longitude });
point.y = state.height - point.y;
return point;
}