summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-10-03 15:44:05 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-10-03 18:21:40 -0700
commit736aa52ff06846df5ec55049904a78227fc77569 (patch)
treeb7b2e32e29511547b57079de027e5f5423163b5b
parent2f1c39b1def05a66f1d2d068ded5e0972aee260b (diff)
downloadqtlocation-mapboxgl-736aa52ff06846df5ec55049904a78227fc77569.tar.gz
[macOS] Use `direction` instead of `heading` and update to modified core methods
-rw-r--r--platform/macos/src/MGLMapView.h19
-rw-r--r--platform/macos/src/MGLMapView.mm52
2 files changed, 14 insertions, 57 deletions
diff --git a/platform/macos/src/MGLMapView.h b/platform/macos/src/MGLMapView.h
index bf7484e9f2..073c8d4a97 100644
--- a/platform/macos/src/MGLMapView.h
+++ b/platform/macos/src/MGLMapView.h
@@ -404,17 +404,17 @@ MGL_EXPORT IB_DESIGNABLE
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated;
/**
- Changes the receiver’s viewport to fit the given shape, with the specified heading,
+ Changes the receiver’s viewport to fit the given shape, with the specified direction,
and optionally some additional padding on each side.
@param shape The shape that the viewport will show in its entirety.
- @param heading The heading of the viewport, measured in degrees clockwise from true north.
+ @param direction The direction of the viewport, measured in degrees clockwise from true north.
@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)setVisibleShape:(MGLShape *)shape heading:(double)heading edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated;
+- (void)setVisibleShape:(MGLShape *)shape direction:(double)direction edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated;
/**
Sets the visible region so that the map displays the specified annotations.
@@ -471,19 +471,18 @@ MGL_EXPORT IB_DESIGNABLE
- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets;
/**
- Returns the camera that best fits the given shape, with the specified heading,
+ Returns the camera that best fits the given shape, with the specified direction,
optionally with some additional padding on each side.
@param shape The shape to fit to the receiver’s viewport.
- @param heading The heading of the viewport, measured in degrees clockwise from true north.
+ @param direction The direction of the viewport, measured in degrees clockwise from true north.
@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.
+ @return A camera object centered on the shape's center with zoom level as high
+ (close to the ground) as possible while still including the entire shape. The
+ camera object uses the current pitch.
*/
-- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape heading:(double)heading edgePadding:(NSEdgeInsets)insets;
+- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(double)direction edgePadding:(NSEdgeInsets)insets;
/**
A Boolean value indicating whether the receiver automatically adjusts its
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 00c50cd598..985a1b71c9 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -14,7 +14,7 @@
#import "MGLMultiPoint_Private.h"
#import "MGLOfflineStorage_Private.h"
#import "MGLStyle_Private.h"
-#import "MGLMultiPoint_Private.h"
+#import "MGLShape_Private.h"
#import "MGLAccountManager.h"
#import "MGLMapCamera.h"
@@ -127,46 +127,6 @@ mbgl::util::UnitBezier MGLUnitBezierForMediaTimingFunction(CAMediaTimingFunction
return { p1[0], p1[1], p2[0], p2[1] };
}
-std::vector<mbgl::LatLng> coordinatesForShape(MGLShape *shape) {
- std::vector<mbgl::LatLng> latLngs;
- if ([shape isKindOfClass:[MGLMultiPoint class]]) {
- MGLMultiPoint *multiPoint = (MGLMultiPoint *)shape;
- latLngs.reserve(multiPoint.pointCount);
- CLLocationCoordinate2D *coordinates = multiPoint.coordinates;
- for(int i=0; i < [multiPoint pointCount]; i++) {
- latLngs.push_back({coordinates[i].latitude, coordinates[i].longitude});
- }
- } else if ([shape isKindOfClass:[MGLPointCollection class]]) {
- MGLPointCollection *pointCollection = (MGLPointCollection *)shape;
- latLngs.reserve(pointCollection.pointCount);
- CLLocationCoordinate2D *coordinates = pointCollection.coordinates;
- for(int i=0; i < [pointCollection pointCount]; i++) {
- latLngs.push_back({coordinates[i].latitude, coordinates[i].longitude});
- }
- } else if ([shape isKindOfClass:[MGLMultiPolygon class]]) {
- MGLMultiPolygon *shapeCollection = (MGLMultiPolygon *)shape;
- for(MGLPolygon *s in shapeCollection.polygons) {
- auto shapeLatLngs = coordinatesForShape(s);
- latLngs.insert(latLngs.end(), shapeLatLngs.begin(), shapeLatLngs.end());
- }
- } else if ([shape isKindOfClass:[MGLMultiPolyline class]]) {
- MGLMultiPolyline *shapeCollection = (MGLMultiPolyline *)shape;
- for(MGLPolyline *s in shapeCollection.polylines) {
- auto shapeLatLngs = coordinatesForShape(s);
- latLngs.insert(latLngs.end(), shapeLatLngs.begin(), shapeLatLngs.end());
- }
- } else if ([shape isKindOfClass:[MGLShapeCollection class]]) {
- MGLShapeCollection *shapeCollection = (MGLShapeCollection *)shape;
- for(MGLShape *s in shapeCollection.shapes) {
- auto shapeLatLngs = coordinatesForShape(s);
- latLngs.insert(latLngs.end(), shapeLatLngs.begin(), shapeLatLngs.end());
- }
- } else {
- NSLog(@"Shape doesn't have multiple points");
- }
- return latLngs;
-}
-
/// Lightweight container for metadata about an annotation, including the annotation itself.
class MGLAnnotationContext {
public:
@@ -1297,14 +1257,13 @@ public:
_mbglMap->easeTo(cameraOptions, animationOptions);
}
-- (void)setVisibleShape:(MGLMultiPoint *)shape heading:(double)heading edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated {
+- (void)setVisibleShape:(MGLShape *)shape direction:(double)direction edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated {
_mbglMap->cancelTransitions();
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets);
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets);
- std::vector<mbgl::LatLng> latLngs = coordinatesForShape(shape);
- mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngs(latLngs, heading, padding);
+ mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction);
mbgl::AnimationOptions animationOptions;
if (animated) {
@@ -1334,12 +1293,11 @@ public:
return [self cameraForCameraOptions:cameraOptions];
}
-- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape heading:(double)heading edgePadding:(NSEdgeInsets)insets {
+- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(double)direction edgePadding:(NSEdgeInsets)insets {
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets);
padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets);
- std::vector<mbgl::LatLng> latLngs = coordinatesForShape(shape);
- mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngs(latLngs, heading, padding);
+ mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction);
return [self cameraForCameraOptions:cameraOptions];
}