summaryrefslogtreecommitdiff
path: root/platform/macos/src
diff options
context:
space:
mode:
authorJason Wray <friedbunny@users.noreply.github.com>2016-07-21 16:35:59 -0400
committerGitHub <noreply@github.com>2016-07-21 16:35:59 -0400
commit4dd734f040540e7feac6a335d2afec188d67fe77 (patch)
tree7831d85a75bcf2db94c7e168c3efb37530c3fad4 /platform/macos/src
parente686d329220767a498f110963acb8dd2e60b1b0d (diff)
downloadqtlocation-mapboxgl-4dd734f040540e7feac6a335d2afec188d67fe77.tar.gz
[macos] Add `showAnnotations:` methods (#5749)
SDK - Ported `showAnnotations:animated:` and `showAnnotations:edgePadding:animated:` from the iOS SDK. Demo App - Added "Show All Annotations" debug menu item with ⇧⌘A shortcut key. - Disabled "Add Animated Annotation" debug menu item when the annotation already shown.
Diffstat (limited to 'platform/macos/src')
-rw-r--r--platform/macos/src/MGLMapView.h29
-rw-r--r--platform/macos/src/MGLMapView.mm32
2 files changed, 61 insertions, 0 deletions
diff --git a/platform/macos/src/MGLMapView.h b/platform/macos/src/MGLMapView.h
index 69927bf970..7c464fe83a 100644
--- a/platform/macos/src/MGLMapView.h
+++ b/platform/macos/src/MGLMapView.h
@@ -387,6 +387,35 @@ IB_DESIGNABLE
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated;
/**
+ Sets the visible region so that the map displays the specified annotations.
+
+ Calling this method updates the value in the `visibleCoordinateBounds` property
+ and potentially other properties to reflect the new map region. A small amount
+ of padding is reserved around the edges of the map view. To specify a different
+ amount of padding, use the `-showAnnotations:edgePadding:animated:` method.
+
+ @param annotations The annotations that you want to be visible in the map.
+ @param animated `YES` if you want the map region change to be animated, or `NO`
+ if you want the map to display the new region immediately without animations.
+ */
+- (void)showAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations animated:(BOOL)animated;
+
+/**
+ Sets the visible region so that the map displays the specified annotations with
+ the specified amount of padding on each side.
+
+ Calling this method updates the value in the `visibleCoordinateBounds` property
+ and potentially other properties to reflect the new map region.
+
+ @param annotations The annotations that you want to be visible in the map.
+ @param insets The minimum padding (in screen points) around the edges of the
+ map view to keep clear of annotations.
+ @param animated `YES` if you want the map region change to be animated, or `NO`
+ if you want the map to display the new region immediately without animations.
+ */
+- (void)showAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations 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.
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 5785f56e01..7b0aad1db9 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -1998,6 +1998,38 @@ public:
}
}
+- (void)showAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations animated:(BOOL)animated {
+ CGFloat maximumPadding = 100;
+ CGFloat yPadding = (NSHeight(self.bounds) / 5 <= maximumPadding) ? (NSHeight(self.bounds) / 5) : maximumPadding;
+ CGFloat xPadding = (NSWidth(self.bounds) / 5 <= maximumPadding) ? (NSWidth(self.bounds) / 5) : maximumPadding;
+
+ NSEdgeInsets edgeInsets = NSEdgeInsetsMake(yPadding, xPadding, yPadding, xPadding);
+
+ [self showAnnotations:annotations edgePadding:edgeInsets animated:animated];
+}
+
+- (void)showAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated {
+ if ( ! annotations || ! annotations.count) return;
+
+ mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty();
+
+ for (id <MGLAnnotation> annotation in annotations)
+ {
+ if ([annotation conformsToProtocol:@protocol(MGLOverlay)])
+ {
+ bounds.extend(MGLLatLngBoundsFromCoordinateBounds(((id <MGLOverlay>)annotation).overlayBounds));
+ }
+ else
+ {
+ bounds.extend(MGLLatLngFromLocationCoordinate2D(annotation.coordinate));
+ }
+ }
+
+ [self setVisibleCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(bounds)
+ edgePadding:insets
+ animated:animated];
+}
+
/// Returns a popover detailing the annotation.
- (NSPopover *)calloutForAnnotation:(id <MGLAnnotation>)annotation {
NSPopover *callout = [[NSPopover alloc] init];