Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[osx] Relegated “selection” to context menu
Browse files Browse the repository at this point in the history
Moved feature selection to the context menu and restored the press gesture for dropping a pin. Bust complex features into simple shapes to feed into MGLMapView as overlays.
  • Loading branch information
1ec5 committed May 28, 2016
1 parent 974e669 commit b94a125
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
4 changes: 2 additions & 2 deletions platform/darwin/src/MGLShapeCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
An array of shapes forming the shape collection.
*/
@property (nonatomic, copy, readonly) NS_ARRAY_OF(MGLShape <MGLAnnotation> *) *shapes;
@property (nonatomic, copy, readonly) NS_ARRAY_OF(MGLShape *) *shapes;

/**
Creates and returns a shape collection consisting of the given shapes.
Expand All @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
this array is copied to the new object.
@return A new shape collection object.
*/
+ (instancetype)shapeCollectionWithShapes:(NS_ARRAY_OF(MGLShape <MGLAnnotation> *) *)shapes;
+ (instancetype)shapeCollectionWithShapes:(NS_ARRAY_OF(MGLShape *) *)shapes;

@end

Expand Down
4 changes: 2 additions & 2 deletions platform/darwin/src/MGLShapeCollection.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

@implementation MGLShapeCollection

+ (instancetype)shapeCollectionWithShapes:(NS_ARRAY_OF(MGLShape <MGLAnnotation> *) *)shapes {
+ (instancetype)shapeCollectionWithShapes:(NS_ARRAY_OF(MGLShape *) *)shapes {
return [[self alloc] initWithShapes:shapes];
}

- (instancetype)initWithShapes:(NS_ARRAY_OF(MGLShape <MGLAnnotation> *) *)shapes {
- (instancetype)initWithShapes:(NS_ARRAY_OF(MGLShape *) *)shapes {
if (self = [super init]) {
NSAssert(shapes.count, @"Cannot create an empty shape collection");
_shapes = shapes.copy;
Expand Down
2 changes: 1 addition & 1 deletion platform/osx/app/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15E65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
</dependencies>
Expand Down
8 changes: 7 additions & 1 deletion platform/osx/app/Base.lproj/MapDocument.xib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15E65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
</dependencies>
Expand Down Expand Up @@ -123,6 +123,12 @@
<action selector="removePin:" target="-1" id="w0R-0B-7mG"/>
</connections>
</menuItem>
<menuItem title="Select Features" id="za5-bY-mdf">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="selectFeatures:" target="-1" id="ikt-CZ-yZT"/>
</connections>
</menuItem>
</items>
<connections>
<outlet property="delegate" destination="-2" id="oHe-ZP-lyc"/>
Expand Down
37 changes: 35 additions & 2 deletions platform/osx/app/MapDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@
{ .latitude = -13.15589555, .longitude = -74.2178961777998 },
};

NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotation>) *shapes) {
NSMutableArray *flattenedShapes = [NSMutableArray arrayWithCapacity:shapes.count];
for (id <MGLAnnotation> shape in shapes) {
NSArray *subshapes;
if ([shape isKindOfClass:[MGLMultiPolyline class]]) {
subshapes = [(MGLMultiPolyline *)shape polylines];
} else if ([shape isKindOfClass:[MGLMultiPolygon class]]) {
subshapes = [(MGLMultiPolygon *)shape polygons];
} else if ([shape isKindOfClass:[MGLShapeCollection class]]) {
subshapes = MBXFlattenedShapes([(MGLShapeCollection *)shape shapes]);
}

if (subshapes) {
[flattenedShapes addObjectsFromArray:subshapes];
} else {
[flattenedShapes addObject:shape];
}
}
return flattenedShapes;
}

@interface MapDocument () <NSWindowDelegate, NSSharingServicePickerDelegate, NSMenuDelegate, MGLMapViewDelegate>

@property (weak) IBOutlet NSMenu *mapViewContextMenu;
Expand Down Expand Up @@ -420,8 +441,7 @@ - (void)handlePressGesture:(NSPressGestureRecognizer *)gestureRecognizer {
if (!NSPointInRect([gestureRecognizer locationInView:self.mapView.compass], self.mapView.compass.bounds)
&& !NSPointInRect([gestureRecognizer locationInView:self.mapView.zoomControls], self.mapView.zoomControls.bounds)
&& !NSPointInRect([gestureRecognizer locationInView:self.mapView.attributionView], self.mapView.attributionView.bounds)) {
NSArray *features = [self.mapView visibleFeaturesAtPoint:location];
[self.mapView addAnnotations:features];
[self dropPinAtPoint:location];
}
}
}
Expand Down Expand Up @@ -464,6 +484,16 @@ - (void)removePinAtPoint:(NSPoint)point {
[self.mapView removeAnnotation:[self.mapView annotationAtPoint:point]];
}

- (IBAction)selectFeatures:(id)sender {
[self selectFeaturesAtPoint:_mouseLocationForMapViewContextMenu];
}

- (void)selectFeaturesAtPoint:(NSPoint)point {
NSArray *features = [self.mapView visibleFeaturesAtPoint:point];
NSArray *flattenedFeatures = MBXFlattenedShapes(features);
[self.mapView addAnnotations:flattenedFeatures];
}

#pragma mark User interface validation

- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
Expand Down Expand Up @@ -521,6 +551,9 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
menuItem.hidden = annotationUnderCursor == nil;
return YES;
}
if (menuItem.action == @selector(selectFeatures:)) {
return YES;
}
if (menuItem.action == @selector(toggleTileBoundaries:)) {
BOOL isShown = self.mapView.debugMask & MGLMapDebugTileBoundariesMask;
menuItem.title = isShown ? @"Hide Tile Boundaries" : @"Show Tile Boundaries";
Expand Down

0 comments on commit b94a125

Please sign in to comment.