diff --git a/platform/darwin/src/MGLShapeCollection.h b/platform/darwin/src/MGLShapeCollection.h index 6a21d6fb903..a617223ea75 100644 --- a/platform/darwin/src/MGLShapeCollection.h +++ b/platform/darwin/src/MGLShapeCollection.h @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN /** An array of shapes forming the shape collection. */ -@property (nonatomic, copy, readonly) NS_ARRAY_OF(MGLShape *) *shapes; +@property (nonatomic, copy, readonly) NS_ARRAY_OF(MGLShape *) *shapes; /** Creates and returns a shape collection consisting of the given shapes. @@ -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 *) *)shapes; ++ (instancetype)shapeCollectionWithShapes:(NS_ARRAY_OF(MGLShape *) *)shapes; @end diff --git a/platform/darwin/src/MGLShapeCollection.m b/platform/darwin/src/MGLShapeCollection.m index 3fc4cdda759..5d42b5a51ca 100644 --- a/platform/darwin/src/MGLShapeCollection.m +++ b/platform/darwin/src/MGLShapeCollection.m @@ -2,11 +2,11 @@ @implementation MGLShapeCollection -+ (instancetype)shapeCollectionWithShapes:(NS_ARRAY_OF(MGLShape *) *)shapes { ++ (instancetype)shapeCollectionWithShapes:(NS_ARRAY_OF(MGLShape *) *)shapes { return [[self alloc] initWithShapes:shapes]; } -- (instancetype)initWithShapes:(NS_ARRAY_OF(MGLShape *) *)shapes { +- (instancetype)initWithShapes:(NS_ARRAY_OF(MGLShape *) *)shapes { if (self = [super init]) { NSAssert(shapes.count, @"Cannot create an empty shape collection"); _shapes = shapes.copy; diff --git a/platform/osx/app/Base.lproj/MainMenu.xib b/platform/osx/app/Base.lproj/MainMenu.xib index 4afb3b244e6..c80428ff00b 100644 --- a/platform/osx/app/Base.lproj/MainMenu.xib +++ b/platform/osx/app/Base.lproj/MainMenu.xib @@ -1,5 +1,5 @@ - + diff --git a/platform/osx/app/Base.lproj/MapDocument.xib b/platform/osx/app/Base.lproj/MapDocument.xib index 9a3db47df6a..55d82d21d08 100644 --- a/platform/osx/app/Base.lproj/MapDocument.xib +++ b/platform/osx/app/Base.lproj/MapDocument.xib @@ -1,5 +1,5 @@ - + @@ -123,6 +123,12 @@ + + + + + + diff --git a/platform/osx/app/MapDocument.m b/platform/osx/app/MapDocument.m index 6fcfc7ce5d3..4274126747f 100644 --- a/platform/osx/app/MapDocument.m +++ b/platform/osx/app/MapDocument.m @@ -14,6 +14,27 @@ { .latitude = -13.15589555, .longitude = -74.2178961777998 }, }; +NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *shapes) { + NSMutableArray *flattenedShapes = [NSMutableArray arrayWithCapacity:shapes.count]; + for (id 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 () @property (weak) IBOutlet NSMenu *mapViewContextMenu; @@ -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]; } } } @@ -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 { @@ -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";