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];
}