summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-11 02:38:48 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-11 12:34:21 +0200
commitf73beb5913403327914c5a9261c2ba5c8ce19f70 (patch)
tree79546cf02aa151756c6d96e9820974ff7e1ddec9
parent4bcc24d5aff1a9f323f9810abb01669d0e38f078 (diff)
downloadqtlocation-mapboxgl-f73beb5913403327914c5a9261c2ba5c8ce19f70.tar.gz
[core] Fix screen coordinates when crossing the antimeridian (#2)
Added missing case. Really fixes #4155 this time.
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/mbgl/map/transform.cpp2
-rw-r--r--test/map/transform.cpp16
3 files changed, 18 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cb3dbd76e0..58a2fbd095 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -52,7 +52,7 @@ Known issues:
## iOS master
- Offline packs can now be downloaded to allow users to view specific regions of the map offline. A new MGLOfflineStorage class provides APIs for managing MGLOfflinePacks. ([#4221](https://github.com/mapbox/mapbox-gl-native/pull/4221))
-- Fixed screen coordinates for LatLng coordinates accross the antimeridian. ([#4215](https://github.com/mapbox/mapbox-gl-native/issues/4155))
+- Fixed screen coordinates for LatLng coordinates accross the antimeridian. ([#4155](https://github.com/mapbox/mapbox-gl-native/issues/4155))
- Fixed a bounce-back effect when panning the map. ([#4214](https://github.com/mapbox/mapbox-gl-native/pull/4214))
- An icon laid out along a line no longer appears if it would extend past the end of the line. Some one-way arrows no longer point the wrong way. ([#3839](https://github.com/mapbox/mapbox-gl-native/pull/3839))
- Reduce slanted segments in dashed lines near corners. ([#3914](https://github.com/mapbox/mapbox-gl-native/pull/3914))
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index d3cd30a627..a63c25faed 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -667,7 +667,7 @@ ScreenCoordinate Transform::latLngToScreenCoordinate(const LatLng& latLng) const
// to the center side.
double longitude = latLng.longitude;
const double centerLng = getLatLng().longitude;
- if (centerLng - latLng.longitude > util::LONGITUDE_MAX) {
+ if (std::abs(centerLng - latLng.longitude) > std::abs(util::LONGITUDE_MAX)) {
if (centerLng > 0 && latLng.longitude < 0) {
longitude += util::DEGREES_MAX;
} else if (centerLng < 0 && latLng.longitude > 0) {
diff --git a/test/map/transform.cpp b/test/map/transform.cpp
index 6b9e960fe6..b7cf6e0a2c 100644
--- a/test/map/transform.cpp
+++ b/test/map/transform.cpp
@@ -318,4 +318,20 @@ TEST(Transform, Antimeridian) {
ScreenCoordinate pixelSFForwards = transform.latLngToScreenCoordinate(coordinateSanFrancisco);
ASSERT_DOUBLE_EQ(pixelSFBackwards.x, pixelSFForwards.x);
ASSERT_DOUBLE_EQ(pixelSFBackwards.y, pixelSFForwards.y);
+
+ const LatLng coordinateWaikiri{ -16.9310, 179.9787 };
+ transform.setLatLngZoom(coordinateWaikiri, 10);
+ ScreenCoordinate pixelWaikiri = transform.latLngToScreenCoordinate(coordinateWaikiri);
+ ASSERT_DOUBLE_EQ(500.00000000007759, pixelWaikiri.x);
+ ASSERT_DOUBLE_EQ(500, pixelWaikiri.y);
+
+ transform.setLatLng({ coordinateWaikiri.latitude, 180.0213 });
+ ScreenCoordinate pixelWaikiriForwards = transform.latLngToScreenCoordinate(coordinateWaikiri);
+ ASSERT_DOUBLE_EQ(437.95953728819512, pixelWaikiriForwards.x);
+ ASSERT_DOUBLE_EQ(pixelWaikiri.y, pixelWaikiriForwards.y);
+
+ transform.setLatLng({ coordinateWaikiri.latitude, -179.9787 });
+ ScreenCoordinate pixelWaikiriBackwards = transform.latLngToScreenCoordinate(coordinateWaikiri);
+ ASSERT_DOUBLE_EQ(pixelWaikiriForwards.x, pixelWaikiriBackwards.x);
+ ASSERT_DOUBLE_EQ(pixelWaikiriForwards.y, pixelWaikiriBackwards.y);
}