[osx] Remove All Pins command
Also fixed an issue where removing a selected annotation failed to deselect it.
This commit is contained in:
committed by
Minh Nguyễn
parent
b869d3c820
commit
0722d26846
@@ -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;
|
||||
}
|
||||
|
||||
@@ -476,6 +476,12 @@
|
||||
<action selector="dropManyPins:" target="-1" id="Rtv-8N-3Z8"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Remove All Pins" id="6rC-68-vk0">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="removeAllPins:" target="-1" id="NRM-y5-Wul"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
|
||||
@@ -479,6 +479,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key {
|
||||
return [key isEqualToString:@"annotations"] ? YES : [super automaticallyNotifiesObserversForKey:key];
|
||||
}
|
||||
|
||||
- (void)setDelegate:(id<MGLMapViewDelegate>)delegate {
|
||||
_delegate = delegate;
|
||||
|
||||
@@ -1412,6 +1416,8 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
[self willChangeValueForKey:@"annotations"];
|
||||
|
||||
BOOL delegateHasImagesForAnnotations = [self.delegate respondsToSelector:@selector(mapView:imageForAnnotation:)];
|
||||
|
||||
std::vector<mbgl::PointAnnotation> 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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user