summaryrefslogtreecommitdiff
path: root/src/mbgl/map/transform_state.cpp
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-07 18:07:23 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-10 03:36:45 +0200
commit026b6d4c01a3d96af9629cc1790373137ecab950 (patch)
treec63cdb8429c793c3abfa8bc92c68c8fb848d7c54 /src/mbgl/map/transform_state.cpp
parent808bf7004a4360a4cc7095f97c235c92d3679f8b (diff)
downloadqtlocation-mapboxgl-026b6d4c01a3d96af9629cc1790373137ecab950.tar.gz
[core] Coordinate wrapping fixes
- Make returning LatLngs unwrapped by default. - PointAnnotation and ShapeAnnotation are always wrapped so they can be selected via intersection from the visible tile boundaries. - Fixes LatLng::wrap() calculation. - Fixes LatLng::unwrapForShortestPath() calculation. The new unwrapForShortestPath algorithm unwraps the start coordinate either forwards or backwards depending on the end coordinate value, so we can always cross the antimeridian when needed and still obtain a wrapped end coordinate in the end. Fixes #4214.
Diffstat (limited to 'src/mbgl/map/transform_state.cpp')
-rw-r--r--src/mbgl/map/transform_state.cpp31
1 files changed, 2 insertions, 29 deletions
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 006a8d5d3a..a23ee71f99 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -89,38 +89,11 @@ ConstrainMode TransformState::getConstrainMode() const {
#pragma mark - Position
LatLng TransformState::getLatLng(LatLng::WrapMode wrapMode) const {
- LatLng ll {
+ return {
util::RAD2DEG * (2 * std::atan(std::exp(y / Cc)) - 0.5 * M_PI),
-x / Bc,
wrapMode
};
-
- if (wrapMode == LatLng::Unwrapped) return ll;
-
- // adjust for date line
- double w = worldSize() / 2;
- double x_ = x;
- if (x_ > w) {
- while (x_ > w) {
- x_ -= w;
- if (ll.longitude < 0) {
- ll.longitude += util::LONGITUDE_MAX;
- } else if (ll.longitude > 0) {
- ll.longitude -= util::LONGITUDE_MAX;
- }
- }
- } else if (x_ < -w) {
- while (x_ < -w) {
- x_ += w;
- if (ll.longitude < 0) {
- ll.longitude -= util::LONGITUDE_MAX;
- } else if (ll.longitude > 0) {
- ll.longitude -= util::LONGITUDE_MAX;
- }
- }
- }
-
- return ll;
}
double TransformState::pixel_x() const {
@@ -350,7 +323,7 @@ void TransformState::moveLatLng(const LatLng& latLng, const ScreenCoordinate& an
auto centerCoord = latLngToTileCoord(getLatLng(LatLng::Unwrapped));
auto latLngCoord = latLngToTileCoord(latLng);
- auto anchorCoord = latLngToTileCoord(screenCoordinateToLatLng(anchor, LatLng::Unwrapped));
+ auto anchorCoord = latLngToTileCoord(screenCoordinateToLatLng(anchor));
setLatLngZoom(tileCoordToLatLng(centerCoord + latLngCoord - anchorCoord), getZoom());
}