Skip to content

Commit

Permalink
[core] Always return wrapped coordinates
Browse files Browse the repository at this point in the history
This fixes an issue in both iOS and Android when e.g. adding a marker on
both sides of the dateline border in Taveuni island, the marker in one
of the sides would have an out-of-bounds longitude.
  • Loading branch information
brunoabinader committed Mar 14, 2016
1 parent 7a509b0 commit fc0a0ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,5 +662,5 @@ LatLng Transform::screenCoordinateToLatLng(const ScreenCoordinate& point) const

ScreenCoordinate flippedPoint = point;
flippedPoint.y = state.height - flippedPoint.y;
return state.screenCoordinateToLatLng(flippedPoint);
return state.screenCoordinateToLatLng(flippedPoint).wrapped();
}
6 changes: 6 additions & 0 deletions test/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,17 @@ TEST(Transform, Antimeridian) {
ScreenCoordinate pixelWaikiriForwards = transform.latLngToScreenCoordinate(coordinateWaikiri);
ASSERT_DOUBLE_EQ(437.95953728819512, pixelWaikiriForwards.x);
ASSERT_DOUBLE_EQ(pixelWaikiri.y, pixelWaikiriForwards.y);
LatLng coordinateFromPixel = transform.screenCoordinateToLatLng(pixelWaikiriForwards);
ASSERT_NEAR(coordinateWaikiri.latitude, coordinateFromPixel.latitude, 0.000001);
ASSERT_NEAR(coordinateWaikiri.longitude, coordinateFromPixel.longitude, 0.000001);

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);
coordinateFromPixel = transform.screenCoordinateToLatLng(pixelWaikiriBackwards);
ASSERT_NEAR(coordinateWaikiri.latitude, coordinateFromPixel.latitude, 0.000001);
ASSERT_NEAR(coordinateWaikiri.longitude, coordinateFromPixel.longitude, 0.000001);
}

TEST(Transform, Camera) {
Expand Down

0 comments on commit fc0a0ef

Please sign in to comment.