From 9e6a79ad9b8182105088ff21f1dcbaf3c5c9bb69 Mon Sep 17 00:00:00 2001 From: Eimantas Date: Sun, 21 May 2017 06:32:10 +0300 Subject: [ios, macos] Add overlays property to MGLMapView (#8617) * Add `overlays` property to `MGLMapView.mm` Implemented by filtering the `annotations` property for annotations that conform to `MGLOverlay` protocol. * Handle `nil` case when returning overlays * Add basic documentation for `overlays` property Copied verbatim from `annotations` property. Changed types. * Add `overlays` property to iOS sdk Implementation is identical to the one in macOS SDK. * Match curly braces style * Make `overlays` property `nonnull` on iOS * Make `overlays` property `nonnull` on macOS * Make cosmetic changes * [ios, macos] Moved changelog entry to master --- platform/macos/CHANGELOG.md | 1 + platform/macos/src/MGLMapView.h | 9 +++++++++ platform/macos/src/MGLMapView.mm | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) (limited to 'platform/macos') diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 377c321452..579624f0e6 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -3,6 +3,7 @@ ## master * The previously-deprecated support for style classes has been removed. For interface compatibility, the API methods remain, but they are now non-functional. +* Added an `overlays` property to `MGLMapView`. ([#8617](https://github.com/mapbox/mapbox-gl-native/pull/8617)) ## 0.5.0 diff --git a/platform/macos/src/MGLMapView.h b/platform/macos/src/MGLMapView.h index fb715a506d..6bfdcfd100 100644 --- a/platform/macos/src/MGLMapView.h +++ b/platform/macos/src/MGLMapView.h @@ -729,6 +729,15 @@ MGL_EXPORT IB_DESIGNABLE #pragma mark Overlaying the Map +/** + The complete list of overlays associated with the receiver. (read-only) + + The objects in this array must adopt the `MGLOverlay` protocol. If no + overlays are associated with the map view, the value of this property is + empty array. + */ +@property (nonatomic, readonly, nonnull) NS_ARRAY_OF(id ) *overlays; + /** Adds a single overlay to the map. diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 59951f946d..98958f045d 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -2413,6 +2413,22 @@ public: #pragma mark Overlays +- (nonnull NS_ARRAY_OF(id ) *)overlays +{ + if (self.annotations == nil) { return @[]; } + + NS_MUTABLE_ARRAY_OF(id ) *mutableOverlays = [NSMutableArray array]; + + [self.annotations enumerateObjectsUsingBlock:^(id _Nonnull annotation, NSUInteger idx, BOOL * _Nonnull stop) { + if ([annotation conformsToProtocol:@protocol(MGLOverlay)]) + { + [mutableOverlays addObject:(id)annotation]; + } + }]; + + return [NSArray arrayWithArray:mutableOverlays]; +} + - (void)addOverlay:(id )overlay { [self addOverlays:@[overlay]]; } -- cgit v1.2.1