diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-01-15 15:13:16 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-01-18 16:54:58 -0800 |
commit | 47b69100f984bfc9e2e69cb7fa731c57d220d7dc (patch) | |
tree | fee8f72c06d55eb0954a058f62c1d893865376a8 /platform/osx | |
parent | bf87eaa7b8aa049358559a96f290603e13ac736b (diff) | |
download | qtlocation-mapboxgl-47b69100f984bfc9e2e69cb7fa731c57d220d7dc.tar.gz |
[core, ios, osx, android, glfw] Flipped origin of Map::latLngForPixel(), Map::pixelForLatLng()
Map and Transform methods assume an origin at the top-left corner of the view, like iOS, Android, and GLFW but unlike OS X. Transform is responsible for flipping coordinates between the top-left origin of Map and the bottom-left origin of TransformState.
Fixes #3574.
Diffstat (limited to 'platform/osx')
-rw-r--r-- | platform/osx/src/MGLMapView.mm | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index 954717e5c4..302a9e8c44 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -2133,6 +2133,8 @@ public: /// Converts a geographic coordinate to a point in the view’s coordinate system. - (NSPoint)convertLatLng:(mbgl::LatLng)latLng toPointToView:(nullable NSView *)view { mbgl::vec2<double> pixel = _mbglMap->pixelForLatLng(latLng); + // Cocoa origin is at the lower-left corner. + pixel.y = NSHeight(self.bounds) - pixel.y; return [self convertPoint:NSMakePoint(pixel.x, pixel.y) toView:view]; } @@ -2143,7 +2145,11 @@ public: /// Converts a point in the view’s coordinate system to a geographic coordinate. - (mbgl::LatLng)convertPoint:(NSPoint)point toLatLngFromView:(nullable NSView *)view { NSPoint convertedPoint = [self convertPoint:point fromView:view]; - return _mbglMap->latLngForPixel(mbgl::PrecisionPoint(convertedPoint.x, convertedPoint.y)); + return _mbglMap->latLngForPixel({ + convertedPoint.x, + // mbgl origin is at the top-left corner. + NSHeight(self.bounds) - convertedPoint.y, + }); } - (NSRect)convertCoordinateBounds:(MGLCoordinateBounds)bounds toRectToView:(nullable NSView *)view { |