From 0722d26846c26c6b53b65cb848df577017de1881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Sat, 5 Dec 2015 22:56:40 -0800 Subject: [PATCH] [osx] Remove All Pins command Also fixed an issue where removing a selected annotation failed to deselect it. --- platform/osx/app/AppDelegate.m | 7 +++++++ platform/osx/app/MainMenu.xib | 6 ++++++ platform/osx/src/MGLMapView.mm | 15 ++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/platform/osx/app/AppDelegate.m b/platform/osx/app/AppDelegate.m index cae27b0c6..2427e42cb 100644 --- a/platform/osx/app/AppDelegate.m +++ b/platform/osx/app/AppDelegate.m @@ -279,6 +279,10 @@ static NSString * const MGLDroppedPinAnnotationImageIdentifier = @"dropped"; } } +- (IBAction)removeAllPins:(id)sender { + [self.mapView removeAnnotations:self.mapView.annotations]; +} + #pragma mark Help methods - (IBAction)showShortcuts:(id)sender { @@ -438,6 +442,9 @@ static NSString * const MGLDroppedPinAnnotationImageIdentifier = @"dropped"; if (menuItem.action == @selector(dropManyPins:)) { return YES; } + if (menuItem.action == @selector(removeAllPins:)) { + return self.mapView.annotations.count; + } if (menuItem.action == @selector(showShortcuts:)) { return YES; } diff --git a/platform/osx/app/MainMenu.xib b/platform/osx/app/MainMenu.xib index 56b35dbbf..ac2dfe32f 100644 --- a/platform/osx/app/MainMenu.xib +++ b/platform/osx/app/MainMenu.xib @@ -476,6 +476,12 @@ + + + + + + diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index 0399e7fec..f80ef8fc7 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -479,6 +479,10 @@ public: } } ++ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key { + return [key isEqualToString:@"annotations"] ? YES : [super automaticallyNotifiesObserversForKey:key]; +} + - (void)setDelegate:(id)delegate { _delegate = delegate; @@ -1412,6 +1416,8 @@ public: return; } + [self willChangeValueForKey:@"annotations"]; + BOOL delegateHasImagesForAnnotations = [self.delegate respondsToSelector:@selector(mapView:imageForAnnotation:)]; std::vector points; @@ -1482,6 +1488,8 @@ public: } } + [self didChangeValueForKey:@"annotations"]; + [self updateAnnotationTrackingAreas]; } @@ -1544,18 +1552,19 @@ public: NSAssert(annotationTag != MGLAnnotationTagNotFound, @"No ID for annotation %@", annotation); annotationTagsToRemove.push_back(annotationTag); - _annotationContextsByAnnotationTag.erase(annotationTag); - if (annotationTag == _selectedAnnotationTag) { [self deselectAnnotation:annotation]; } - if (annotationTag == _lastSelectedAnnotationTag) { _lastSelectedAnnotationTag = MGLAnnotationTagNotFound; } + + _annotationContextsByAnnotationTag.erase(annotationTag); } + [self willChangeValueForKey:@"annotations"]; _mbglMap->removeAnnotations(annotationTagsToRemove); + [self didChangeValueForKey:@"annotations"]; [self updateAnnotationTrackingAreas]; }