summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-12-02 16:05:41 -0800
committerMinh Nguyễn <mxn@1ec5.org>2015-12-13 17:26:53 -0800
commitea57be5598826a14991e2ac17a826186c2d9ce0b (patch)
tree627befa3bfd79915eeac17d75153a4fa2de49ac4 /platform
parent73324ae2f886ac32fc673c996b00faf0383d93c0 (diff)
downloadqtlocation-mapboxgl-ea57be5598826a14991e2ac17a826186c2d9ce0b.tar.gz
[osx] Documentation comments for public classes
Added documentation comments for all the public headers that aren’t being shared with iOS. Removed an animated: parameter from -selectAnnotation: and -deselectAnnotation:: because callout popovers may extend beyond the entire window, there is no need to scroll the map to make the entire callout visible. Added missing geometric conversion methods. Renamed -mapView:regionWillChangeAnimated: et al. to say “camera” instead of “region”. “Region” leaves ambiguity about whether properties like rotation and pitch trigger this method. “Camera” associates these methods with the camera property, which seems apt.
Diffstat (limited to 'platform')
-rw-r--r--platform/darwin/MGLGeometry.m3
-rw-r--r--platform/darwin/MGLGeometry.mm21
-rw-r--r--platform/darwin/MGLGeometry_Private.h15
-rw-r--r--platform/osx/app/AppDelegate.m2
-rw-r--r--platform/osx/src/MGLMapView.mm96
5 files changed, 93 insertions, 44 deletions
diff --git a/platform/darwin/MGLGeometry.m b/platform/darwin/MGLGeometry.m
deleted file mode 100644
index 9eab5565fa..0000000000
--- a/platform/darwin/MGLGeometry.m
+++ /dev/null
@@ -1,3 +0,0 @@
-#import "MGLGeometry.h"
-
-const MGLCoordinateSpan MGLCoordinateSpanZero = {0, 0};
diff --git a/platform/darwin/MGLGeometry.mm b/platform/darwin/MGLGeometry.mm
new file mode 100644
index 0000000000..b80203d142
--- /dev/null
+++ b/platform/darwin/MGLGeometry.mm
@@ -0,0 +1,21 @@
+#import "MGLGeometry_Private.h"
+
+const MGLCoordinateSpan MGLCoordinateSpanZero = {0, 0};
+
+CGRect MGLExtendRect(CGRect rect, CGPoint point) {
+ if (point.x < rect.origin.x) {
+ rect.size.width += rect.origin.x - point.x;
+ rect.origin.x = point.x;
+ }
+ if (point.x > rect.origin.x + rect.size.width) {
+ rect.size.width += point.x - (rect.origin.x + rect.size.width);
+ }
+ if (point.y < rect.origin.y) {
+ rect.size.height += rect.origin.y - point.y;
+ rect.origin.y = point.y;
+ }
+ if (point.y > rect.origin.y + rect.size.height) {
+ rect.size.height += point.y - (rect.origin.y + rect.size.height);
+ }
+ return rect;
+}
diff --git a/platform/darwin/MGLGeometry_Private.h b/platform/darwin/MGLGeometry_Private.h
index 08d1ad3695..49a306701d 100644
--- a/platform/darwin/MGLGeometry_Private.h
+++ b/platform/darwin/MGLGeometry_Private.h
@@ -1,10 +1,17 @@
#import "MGLGeometry.h"
#import <TargetConditionals.h>
+#if TARGET_OS_IPHONE
+ #import <UIKit/UIKit.h>
+#endif
#import <mbgl/map/map.hpp>
#import <mbgl/util/geo.hpp>
+/// Returns the smallest rectangle that contains both the given rectangle and
+/// the given point.
+CGRect MGLExtendRect(CGRect rect, CGPoint point);
+
NS_INLINE mbgl::LatLng MGLLatLngFromLocationCoordinate2D(CLLocationCoordinate2D coordinate) {
return mbgl::LatLng(coordinate.latitude, coordinate.longitude);
}
@@ -28,12 +35,12 @@ NS_INLINE BOOL MGLCoordinateInCoordinateBounds(CLLocationCoordinate2D coordinate
return bounds.contains(MGLLatLngFromLocationCoordinate2D(coordinate));
}
-#if TARGET_OS_MAC
-NS_INLINE mbgl::EdgeInsets MGLEdgeInsetsFromNSEdgeInsets(NSEdgeInsets insets) {
+#if TARGET_OS_IPHONE
+NS_INLINE mbgl::EdgeInsets MGLEdgeInsetsFromNSEdgeInsets(UIEdgeInsets insets) {
return { insets.top, insets.left, insets.bottom, insets.right };
}
-#elif TARGET_OS_IOS
-NS_INLINE mbgl::EdgeInsets MGLEdgeInsetsFromNSEdgeInsets(UIEdgeInsets insets) {
+#else
+NS_INLINE mbgl::EdgeInsets MGLEdgeInsetsFromNSEdgeInsets(NSEdgeInsets insets) {
return { insets.top, insets.left, insets.bottom, insets.right };
}
#endif
diff --git a/platform/osx/app/AppDelegate.m b/platform/osx/app/AppDelegate.m
index 1bea883eb2..094260f8d8 100644
--- a/platform/osx/app/AppDelegate.m
+++ b/platform/osx/app/AppDelegate.m
@@ -317,7 +317,7 @@ static NSString * const MGLDroppedPinAnnotationImageIdentifier = @"dropped";
- (void)dropPinAtPoint:(NSPoint)point {
DroppedPinAnnotation *annotation = [self pinAtPoint:point];
[self.mapView addAnnotation:annotation];
- [self.mapView selectAnnotation:annotation animated:YES];
+ [self.mapView selectAnnotation:annotation];
}
- (DroppedPinAnnotation *)pinAtPoint:(NSPoint)point {
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index d81516e6f6..a9ab336263 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -465,6 +465,22 @@ public:
_delegateHasStrokeColorsForShapeAnnotations = [_delegate respondsToSelector:@selector(mapView:strokeColorForShapeAnnotation:)];
_delegateHasFillColorsForShapeAnnotations = [_delegate respondsToSelector:@selector(mapView:fillColorForPolygonAnnotation:)];
_delegateHasLineWidthsForShapeAnnotations = [_delegate respondsToSelector:@selector(mapView:lineWidthForPolylineAnnotation:)];
+
+ if ([self.delegate respondsToSelector:@selector(mapView:regionWillChangeAnimated:)]) {
+ NSLog(@"-mapView:regionWillChangeAnimated: is not supported by the OS X SDK, but %@ implements it anyways. "
+ @"Please implement -[%@ mapView:cameraWillChangeAnimated:] instead.",
+ NSStringFromClass([delegate class]), NSStringFromClass([delegate class]));
+ }
+ if ([self.delegate respondsToSelector:@selector(mapViewRegionIsChanging:)]) {
+ NSLog(@"-mapViewRegionIsChanging: is not supported by the OS X SDK, but %@ implements it anyways. "
+ @"Please implement -[%@ mapViewCameraIsChanging:] instead.",
+ NSStringFromClass([delegate class]), NSStringFromClass([delegate class]));
+ }
+ if ([self.delegate respondsToSelector:@selector(mapView:regionDidChangeAnimated:)]) {
+ NSLog(@"-mapView:regionDidChangeAnimated: is not supported by the OS X SDK, but %@ implements it anyways. "
+ @"Please implement -[%@ mapView:cameraDidChangeAnimated:] instead.",
+ NSStringFromClass([delegate class]), NSStringFromClass([delegate class]));
+ }
}
#pragma mark Style
@@ -507,7 +523,7 @@ public:
#pragma mark View hierarchy and drawing
- (void)viewWillMoveToWindow:(NSWindow *)newWindow {
- [self deselectAnnotation:self.selectedAnnotation animated:NO];
+ [self deselectAnnotation:self.selectedAnnotation];
if (!self.dormant && !newWindow) {
self.dormant = YES;
_mbglMap->pause();
@@ -661,9 +677,9 @@ public:
case mbgl::MapChangeRegionWillChange:
case mbgl::MapChangeRegionWillChangeAnimated:
{
- if ([self.delegate respondsToSelector:@selector(mapView:regionWillChangeAnimated:)]) {
+ if ([self.delegate respondsToSelector:@selector(mapView:cameraWillChangeAnimated:)]) {
BOOL animated = change == mbgl::MapChangeRegionWillChangeAnimated;
- [self.delegate mapView:self regionWillChangeAnimated:animated];
+ [self.delegate mapView:self cameraWillChangeAnimated:animated];
}
break;
}
@@ -674,8 +690,8 @@ public:
[self updateCompass];
[self updateAnnotationCallouts];
- if ([self.delegate respondsToSelector:@selector(mapViewRegionIsChanging:)]) {
- [self.delegate mapViewRegionIsChanging:self];
+ if ([self.delegate respondsToSelector:@selector(mapViewCameraIsChanging:)]) {
+ [self.delegate mapViewCameraIsChanging:self];
}
break;
}
@@ -692,9 +708,9 @@ public:
[self updateAnnotationCallouts];
[self updateAnnotationTrackingAreas];
- if ([self.delegate respondsToSelector:@selector(mapView:regionDidChangeAnimated:)]) {
+ if ([self.delegate respondsToSelector:@selector(mapView:cameraDidChangeAnimated:)]) {
BOOL animated = change == mbgl::MapChangeRegionDidChangeAnimated;
- [self.delegate mapView:self regionDidChangeAnimated:animated];
+ [self.delegate mapView:self cameraDidChangeAnimated:animated];
}
break;
}
@@ -846,7 +862,7 @@ public:
}
- (MGLCoordinateBounds)visibleCoordinateBounds {
- return [self convertRectToCoordinateBounds:self.bounds];
+ return [self convertRect:self.bounds toCoordinateBoundsFromView:self];
}
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds {
@@ -990,10 +1006,10 @@ public:
if (hitAnnotationTag != _selectedAnnotationTag) {
id <MGLAnnotation> annotation = [self annotationWithTag:hitAnnotationTag];
NSAssert(annotation, @"Cannot select nonexistent annotation with ID %i", hitAnnotationTag);
- [self selectAnnotation:annotation animated:YES];
+ [self selectAnnotation:annotation];
}
} else {
- [self deselectAnnotation:self.selectedAnnotation animated:YES];
+ [self deselectAnnotation:self.selectedAnnotation];
}
}
@@ -1353,7 +1369,7 @@ public:
_annotationContextsByAnnotationTag.erase(annotationTag);
if (annotationTag == _selectedAnnotationTag) {
- [self deselectAnnotation:annotation animated:NO];
+ [self deselectAnnotation:annotation];
}
if (annotationTag == _lastSelectedAnnotationTag) {
@@ -1481,7 +1497,7 @@ public:
/// Returns the tags of the annotations coincident with the given rectangle.
- (std::vector<MGLAnnotationTag>)annotationTagsInRect:(NSRect)rect {
- mbgl::LatLngBounds queryBounds = [self convertRectToLatLngBounds:rect];
+ mbgl::LatLngBounds queryBounds = [self convertRect:rect toLatLngBoundsFromView:self];
return _mbglMap->getPointAnnotationsInBounds(queryBounds);
}
@@ -1507,11 +1523,11 @@ public:
// Select the annotation if it’s visible.
if (MGLCoordinateInCoordinateBounds(firstAnnotation.coordinate, self.visibleCoordinateBounds)) {
- [self selectAnnotation:firstAnnotation animated:NO];
+ [self selectAnnotation:firstAnnotation];
}
}
-- (void)selectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated
+- (void)selectAnnotation:(id <MGLAnnotation>)annotation
{
// Only point annotations can be selected.
if (!annotation || [annotation isKindOfClass:[MGLMultiPoint class]]) {
@@ -1524,7 +1540,7 @@ public:
}
// Deselect the annotation before reselecting it.
- [self deselectAnnotation:selectedAnnotation animated:NO];
+ [self deselectAnnotation:selectedAnnotation];
// Add the annotation to the map if it hasn’t been added yet.
MGLAnnotationTag annotationTag = [self annotationTagForAnnotation:annotation];
@@ -1552,7 +1568,6 @@ public:
&& [self.delegate respondsToSelector:@selector(mapView:annotationCanShowCallout:)]
&& [self.delegate mapView:self annotationCanShowCallout:annotation]) {
NSPopover *callout = [self calloutForAnnotation:annotation];
- callout.animates = animated;
// Hang the callout off the right edge of the annotation image’s
// alignment rect, or off the left edge in a right-to-left UI.
@@ -1626,14 +1641,13 @@ public:
return [self dequeueReusableAnnotationImageWithIdentifier:symbolName];
}
-- (void)deselectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated {
+- (void)deselectAnnotation:(id <MGLAnnotation>)annotation {
if (!annotation || self.selectedAnnotation != annotation) {
return;
}
// Close the callout popover gracefully.
NSPopover *callout = self.calloutForSelectedAnnotation;
- callout.animates = animated;
[callout performClose:self];
self.selectedAnnotation = nil;
@@ -1821,40 +1835,50 @@ public:
#pragma mark Geometric methods
+- (NSPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(nullable NSView *)view {
+ return [self convertLatLng:MGLLatLngFromLocationCoordinate2D(coordinate) toPointToView:view];
+}
+
+/// 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);
+ return [self convertPoint:NSMakePoint(pixel.x, pixel.y) toView:view];
+}
+
- (CLLocationCoordinate2D)convertPoint:(NSPoint)point toCoordinateFromView:(nullable NSView *)view {
return MGLLocationCoordinate2DFromLatLng([self convertPoint:point toLatLngFromView:view]);
}
-/// Converts a point in the view’s coordinate system to a coordinate pair.
+/// 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));
}
-- (NSPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(nullable NSView *)view {
- return [self convertLatLng:MGLLatLngFromLocationCoordinate2D(coordinate) toPointToView:view];
+- (NSRect)convertCoordinateBounds:(MGLCoordinateBounds)bounds toRectToView:(nullable NSView *)view {
+ return [self convertLatLngBounds:MGLLatLngBoundsFromCoordinateBounds(bounds) toRectToView:view];
}
-/// Converts a coordinate pair 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);
- return [self convertPoint:NSMakePoint(pixel.x, pixel.y) toView:view];
+/// Converts a geographic bounding box to a rectangle in the view’s coordinate
+/// system.
+- (NSRect)convertLatLngBounds:(mbgl::LatLngBounds)bounds toRectToView:(nullable NSView *)view {
+ NSRect rect = { [self convertLatLng:bounds.sw toPointToView:view], NSZeroSize };
+ rect = MGLExtendRect(rect, [self convertLatLng:bounds.ne toPointToView:view]);
+ return rect;
}
-/// Converts a rectangle in the view’s coordinate system to a coordinate
-/// bounding box.
-- (MGLCoordinateBounds)convertRectToCoordinateBounds:(NSRect)rect {
- return MGLCoordinateBoundsFromLatLngBounds([self convertRectToLatLngBounds:rect]);
+- (MGLCoordinateBounds)convertRect:(NSRect)rect toCoordinateBoundsFromView:(nullable NSView *)view {
+ return MGLCoordinateBoundsFromLatLngBounds([self convertRect:rect toLatLngBoundsFromView:view]);
}
-/// Converts a rectangle in the view’s coordinate system to a coordinate
+/// Converts a rectangle in the given view’s coordinate system to a geographic
/// bounding box.
-- (mbgl::LatLngBounds)convertRectToLatLngBounds:(NSRect)rect {
+- (mbgl::LatLngBounds)convertRect:(NSRect)rect toLatLngBoundsFromView:(nullable NSView *)view {
mbgl::LatLngBounds bounds = mbgl::LatLngBounds::getExtendable();
- bounds.extend([self convertPoint:rect.origin toLatLngFromView:self]);
- bounds.extend([self convertPoint:{ NSMaxX(rect), NSMinY(rect) } toLatLngFromView:self]);
- bounds.extend([self convertPoint:{ NSMaxX(rect), NSMaxY(rect) } toLatLngFromView:self]);
- bounds.extend([self convertPoint:{ NSMinX(rect), NSMaxY(rect) } toLatLngFromView:self]);
+ bounds.extend([self convertPoint:rect.origin toLatLngFromView:view]);
+ bounds.extend([self convertPoint:{ NSMaxX(rect), NSMinY(rect) } toLatLngFromView:view]);
+ bounds.extend([self convertPoint:{ NSMaxX(rect), NSMaxY(rect) } toLatLngFromView:view]);
+ bounds.extend([self convertPoint:{ NSMinX(rect), NSMaxY(rect) } toLatLngFromView:view]);
// The world is wrapping if a point just outside the bounds is also within
// the rect.
@@ -1872,7 +1896,7 @@ public:
}
// If the world is wrapping, extend the bounds to cover all longitudes.
- if (NSPointInRect([self convertLatLng:outsideLatLng toPointToView:self], rect)) {
+ if (NSPointInRect([self convertLatLng:outsideLatLng toPointToView:view], rect)) {
bounds.sw.longitude = -180;
bounds.ne.longitude = 180;
}