summaryrefslogtreecommitdiff
path: root/platform/osx
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-04-21 17:23:09 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-04-22 16:39:25 -0700
commit466ed55200ffb3a9bc5954b59d87c7dd5630e5ac (patch)
tree9daedf21439b49b82ea911883eae04ecd2ae3b79 /platform/osx
parent5939dd5b412fcc1ef857711a137589aa865bd442 (diff)
downloadqtlocation-mapboxgl-466ed55200ffb3a9bc5954b59d87c7dd5630e5ac.tar.gz
[core, ios, osx] cameraThatFitsCoordinateBounds
Added an API to get a camera that you can pass into -[MGLMapView setCamera:] that fits the given coordinate bounds, by analogy with -[MKMapView regionThatFits:] or -[MKMapView mapRectThatFits:edgePadding:]. Added mbgl::Map::getCameraOptions() for getting the current camera options more conveniently.
Diffstat (limited to 'platform/osx')
-rw-r--r--platform/osx/include/MGLMapView.h35
-rw-r--r--platform/osx/osx.xcodeproj/project.pbxproj8
-rw-r--r--platform/osx/src/MGLMapView.mm35
3 files changed, 62 insertions, 16 deletions
diff --git a/platform/osx/include/MGLMapView.h b/platform/osx/include/MGLMapView.h
index f6ba86fb05..a8fd24ab5b 100644
--- a/platform/osx/include/MGLMapView.h
+++ b/platform/osx/include/MGLMapView.h
@@ -325,6 +325,41 @@ IB_DESIGNABLE
and zooming or `NO` to immediately display the given bounds. */
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds animated:(BOOL)animated;
+/** Changes the receiver’s viewport to fit the given coordinate bounds and
+ optionally some additional padding on each side.
+
+ @param bounds The bounds that the viewport will show in its entirety.
+ @param insets The minimum padding (in screen points) that will be visible
+ around the given coordinate bounds.
+ @param animated Specify `YES` to animate the change by smoothly scrolling and
+ zooming or `NO` to immediately display the given bounds.
+ */
+- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated;
+
+/** Returns the camera that best fits the given coordinate bounds.
+
+ @param bounds The coordinate bounds to fit to the receiver’s viewport.
+ @return A camera object centered on the same location as the coordinate
+ bounds with zoom level as high (close to the ground) as possible while
+ still including the entire coordinate bounds. The camera object uses the
+ current direction and pitch.
+ */
+- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds;
+
+/** Returns the camera that best fits the given coordinate bounds, optionally
+ with some additional padding on each side.
+
+ @param bounds The coordinate bounds to fit to the receiver’s viewport.
+ @param insets The minimum padding (in screen points) that would be visible
+ around the returned camera object if it were set as the receiver’s
+ camera.
+ @return A camera object centered on the same location as the coordinate
+ bounds with zoom level as high (close to the ground) as possible while
+ still including the entire coordinate bounds. The camera object uses the
+ current direction and pitch.
+ */
+- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets;
+
/** A Boolean value indicating whether the receiver automatically adjusts its
content insets.
diff --git a/platform/osx/osx.xcodeproj/project.pbxproj b/platform/osx/osx.xcodeproj/project.pbxproj
index 456625f574..67fd7a2064 100644
--- a/platform/osx/osx.xcodeproj/project.pbxproj
+++ b/platform/osx/osx.xcodeproj/project.pbxproj
@@ -284,7 +284,6 @@
DA839E891CC2E3400062CAFB = {
isa = PBXGroup;
children = (
- DAE6C3C31CC31F6900DB3429 /* Configuration */,
DA839E941CC2E3400062CAFB /* Demo App */,
DAE6C3291CC30DB200DB3429 /* SDK */,
DAE6C3371CC30DB200DB3429 /* SDK Tests */,
@@ -461,13 +460,6 @@
name = Kit;
sourceTree = "<group>";
};
- DAE6C3C31CC31F6900DB3429 /* Configuration */ = {
- isa = PBXGroup;
- children = (
- );
- name = Configuration;
- sourceTree = "<group>";
- };
DAE6C3C41CC31F7800DB3429 /* Configuration */ = {
isa = PBXGroup;
children = (
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index c707ef2571..5a1a108fee 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -1003,14 +1003,8 @@ public:
}
- (MGLMapCamera *)camera {
- CGFloat pitch = _mbglMap->getPitch();
- CLLocationDistance altitude = MGLAltitudeForZoomLevel(self.zoomLevel, pitch,
- self.centerCoordinate.latitude,
- self.frame.size);
- return [MGLMapCamera cameraLookingAtCenterCoordinate:self.centerCoordinate
- fromDistance:altitude
- pitch:pitch
- heading:self.direction];
+ mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets);
+ return [self cameraForCameraOptions:_mbglMap->getCameraOptions(padding)];
}
- (void)setCamera:(MGLMapCamera *)camera {
@@ -1142,6 +1136,31 @@ public:
_mbglMap->easeTo(cameraOptions, animationOptions);
}
+- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds {
+ return [self cameraThatFitsCoordinateBounds:bounds edgePadding:NSEdgeInsetsZero];
+}
+
+- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets {
+ mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets);
+ padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets);
+ mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding);
+ return [self cameraForCameraOptions:cameraOptions];
+}
+
+- (MGLMapCamera *)cameraForCameraOptions:(const mbgl::CameraOptions &)cameraOptions {
+ CLLocationCoordinate2D centerCoordinate = MGLLocationCoordinate2DFromLatLng(cameraOptions.center ? *cameraOptions.center : _mbglMap->getLatLng());
+ double zoomLevel = cameraOptions.zoom ? *cameraOptions.zoom : self.zoomLevel;
+ CLLocationDirection direction = cameraOptions.angle ? *cameraOptions.angle : self.direction;
+ CGFloat pitch = cameraOptions.pitch ? *cameraOptions.pitch : _mbglMap->getPitch();
+ CLLocationDistance altitude = MGLAltitudeForZoomLevel(zoomLevel, pitch,
+ centerCoordinate.latitude,
+ self.frame.size);
+ return [MGLMapCamera cameraLookingAtCenterCoordinate:centerCoordinate
+ fromDistance:altitude
+ pitch:pitch
+ heading:direction];
+}
+
- (void)setAutomaticallyAdjustsContentInsets:(BOOL)automaticallyAdjustsContentInsets {
_automaticallyAdjustsContentInsets = automaticallyAdjustsContentInsets;
[self adjustContentInsets];