From b6fca670896e6351a03916fd9fb646e1970d3ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 7 Jan 2016 21:32:10 -0800 Subject: [PATCH] [ios] Added some missing coordinate conversion methods These methods were public in the OS X SDK but not here. --- include/mbgl/ios/MGLMapView.h | 22 ++++++++++++++++++++++ platform/ios/src/MGLMapView.mm | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index 8a5ebef2a..feb5c6d63 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -592,6 +592,28 @@ IB_DESIGNABLE */ - (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(nullable UIView *)view; +/** + Converts a rectangle in the given view’s coordinate system to a geographic + bounding box. + + @param rect The rectangle to convert. + @param view The view in whose coordinate system the rectangle is expressed. + @return The geographic bounding box coextensive with the given rectangle. + */ +- (MGLCoordinateBounds)convertRect:(CGRect)rect toCoordinateBoundsFromView:(nullable UIView *)view; + +/** + Converts a geographic bounding box to a rectangle in the given view’s + coordinate system. + + @param bounds The geographic bounding box to convert. + @param view The view in whose coordinate system the returned rectangle should + be expressed. If this parameter is `nil`, the returned rectangle is + expressed in the window’s coordinate system. If `view` is not `nil`, it must + belong to the same window as the map view. + */ +- (CGRect)convertCoordinateBounds:(MGLCoordinateBounds)bounds toRectToView:(nullable UIView *)view; + /** Returns the distance spanned by one point in the map view's coordinate system at the given latitude and current zoom level. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index c7c5eda59..7fe040b0f 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1926,6 +1926,19 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration) return MGLCoordinateBoundsFromLatLngBounds([self convertRect:rect toLatLngBoundsFromView:view]); } +- (CGRect)convertCoordinateBounds:(MGLCoordinateBounds)bounds toRectToView:(nullable UIView *)view +{ + return [self convertLatLngBounds:MGLLatLngBoundsFromCoordinateBounds(bounds) toRectToView:view]; +} + +/// Converts a geographic bounding box to a rectangle in the view’s coordinate +/// system. +- (CGRect)convertLatLngBounds:(mbgl::LatLngBounds)bounds toRectToView:(nullable UIView *)view { + CGRect rect = { [self convertLatLng:bounds.sw toPointToView:view], CGSizeZero }; + rect = MGLExtendRect(rect, [self convertLatLng:bounds.ne toPointToView:view]); + return rect; +} + /// Converts a rectangle in the given view’s coordinate system to a geographic /// bounding box. - (mbgl::LatLngBounds)convertRect:(CGRect)rect toLatLngBoundsFromView:(nullable UIView *)view