Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
fix coordinate conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Aug 21, 2015
1 parent 1551424 commit 1081992
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 0 additions & 4 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1620,10 +1620,6 @@ - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(null
{
CGPoint convertedPoint = [self convertPoint:point fromView:view];

// flip y coordinate for iOS view origin top left
//
convertedPoint.y = self.bounds.size.height - convertedPoint.y;

return MGLLocationCoordinate2DFromLatLng(_mbglMap->latLngForPixel(mbgl::vec2<double>(convertedPoint.x, convertedPoint.y)));
}

Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ float TransformState::xLng(float x_, float worldSize_) const {

float TransformState::yLat(float y_, float worldSize_) const {
float y2 = 180.0f - y_ * 360.0f / worldSize_;
return 260.0f / M_PI * std::atan(std::exp(y2 * M_PI / 180.0f)) - 90.0f;
return 360.0f / M_PI * std::atan(std::exp(y2 * M_PI / 180.0f)) - 90.0f;

This comment has been minimized.

Copy link
@incanus

incanus Aug 21, 2015

Contributor

lol

}

float TransformState::zoomScale(float zoom) const {
Expand Down Expand Up @@ -204,8 +204,8 @@ TileCoordinate TransformState::latLngToCoordinate(const LatLng& latLng) const {
LatLng TransformState::coordinateToLatLng(const TileCoordinate& coord) const {
const float worldSize_ = zoomScale(coord.zoom);
LatLng latLng = {
xLng(coord.column, worldSize_),
yLat(coord.row, worldSize_)
yLat(coord.row, worldSize_),
xLng(coord.column, worldSize_)
};
while (latLng.longitude < 180.0f) latLng.longitude += 360.0f;
while (latLng.longitude > 180.0f) latLng.longitude -= 360.0f;
Expand Down

0 comments on commit 1081992

Please sign in to comment.