[osx] Blanket the map with pins

This commit is contained in:
Minh Nguyễn
2015-12-01 15:52:05 -08:00
committed by Minh Nguyễn
parent 004d04075a
commit 9d2e0a19ef
2 changed files with 50 additions and 2 deletions

View File

@@ -238,6 +238,39 @@ static NSString * const MGLDroppedPinAnnotationImageIdentifier = @"dropped";
_randomizesCursorsOnDroppedPins = !_randomizesCursorsOnDroppedPins;
}
- (IBAction)dropManyPins:(id)sender {
[self.mapView removeAnnotations:self.mapView.annotations];
NSRect bounds = self.mapView.bounds;
NSMutableArray *annotations = [NSMutableArray array];
for (CGFloat x = NSMinX(bounds); x < NSMaxX(bounds); x += arc4random_uniform(50)) {
for (CGFloat y = NSMaxY(bounds); y >= NSMinY(bounds); y -= arc4random_uniform(100)) {
[annotations addObject:[self pinAtPoint:NSMakePoint(x, y)]];
}
}
[NSTimer scheduledTimerWithTimeInterval:1/60
target:self
selector:@selector(dropOneOfManyPins:)
userInfo:annotations
repeats:YES];
}
- (void)dropOneOfManyPins:(NSTimer *)timer {
NSMutableArray *annotations = timer.userInfo;
NSUInteger numberOfAnnotationsToAdd = 50;
if (annotations.count < numberOfAnnotationsToAdd) {
numberOfAnnotationsToAdd = annotations.count;
}
NSArray *annotationsToAdd = [annotations subarrayWithRange:
NSMakeRange(0, numberOfAnnotationsToAdd)];
[self.mapView addAnnotations:annotationsToAdd];
[annotations removeObjectsInRange:NSMakeRange(0, numberOfAnnotationsToAdd)];
if (!annotations.count) {
[timer invalidate];
}
}
#pragma mark Help methods
- (IBAction)showShortcuts:(id)sender {
@@ -282,6 +315,12 @@ static NSString * const MGLDroppedPinAnnotationImageIdentifier = @"dropped";
}
- (void)dropPinAtPoint:(NSPoint)point {
DroppedPinAnnotation *annotation = [self pinAtPoint:point];
[self.mapView addAnnotation:annotation];
[self.mapView selectAnnotation:annotation animated:YES];
}
- (DroppedPinAnnotation *)pinAtPoint:(NSPoint)point {
DroppedPinAnnotation *annotation = [[DroppedPinAnnotation alloc] init];
annotation.coordinate = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
annotation.title = @"Dropped Pin";
@@ -290,8 +329,7 @@ static NSString * const MGLDroppedPinAnnotationImageIdentifier = @"dropped";
NSString *formattedNumber = [_spellOutNumberFormatter stringFromNumber:@(++_droppedPinCounter)];
annotation.toolTip = formattedNumber;
}
[self.mapView addAnnotation:annotation];
[self.mapView selectAnnotation:annotation animated:YES];
return annotation;
}
- (IBAction)removePin:(NSMenuItem *)sender {
@@ -389,6 +427,9 @@ static NSString * const MGLDroppedPinAnnotationImageIdentifier = @"dropped";
menuItem.title = isRandom ? @"Use Default Cursor for Dropped Pins" : @"Use Random Cursors for Dropped Pins";
return _showsToolTipsOnDroppedPins;
}
if (menuItem.action == @selector(dropManyPins:)) {
return YES;
}
if (menuItem.action == @selector(showShortcuts:)) {
return YES;
}

View File

@@ -469,6 +469,13 @@
<action selector="toggleRandomizesCursorsOnDroppedPins:" target="-1" id="Mpw-b8-oub"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="wQq-Mx-QY0"/>
<menuItem title="Blanket Map With Pins" id="LMZ-oe-Ngh">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="dropManyPins:" target="-1" id="Rtv-8N-3Z8"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>