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

Commit

Permalink
[osx] Set default polyline and polygon color to the selected menu ite…
Browse files Browse the repository at this point in the history
…m color

Fixes #3927
  • Loading branch information
friedbunny committed Feb 19, 2016
1 parent 390057b commit 21ce6fb
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
16 changes: 11 additions & 5 deletions platform/osx/app/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10109" systemVersion="15E39d" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10109"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand Down Expand Up @@ -473,10 +473,16 @@
<action selector="dropManyPins:" target="-1" id="Rtv-8N-3Z8"/>
</connections>
</menuItem>
<menuItem title="Remove All Pins" id="6rC-68-vk0">
<menuItem title="Add Polygon and Polyline" id="DVr-vT-lpe">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="removeAllPins:" target="-1" id="NRM-y5-Wul"/>
<action selector="drawPolygonAndPolyLineAnnotations:" target="-1" id="EhT-CB-gee"/>
</connections>
</menuItem>
<menuItem title="Remove All Annotations" id="6rC-68-vk0">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="removeAllAnnotations:" target="-1" id="6v3-0E-LsR"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="wQq-Mx-QY0"/>
Expand Down Expand Up @@ -545,7 +551,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="109" y="131" width="350" height="62"/>
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1050"/>
<view key="contentView" id="eA4-n3-qPe">
<rect key="frame" x="0.0" y="0.0" width="350" height="62"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down
44 changes: 39 additions & 5 deletions platform/osx/app/MapDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ @implementation MapDocument {
BOOL _showsToolTipsOnDroppedPins;
BOOL _randomizesCursorsOnDroppedPins;
BOOL _isTouringWorld;
BOOL _isShowingPolygonAndPolylineAnnotations;
}

#pragma mark Lifecycle
Expand Down Expand Up @@ -241,7 +242,7 @@ - (IBAction)toggleRandomizesCursorsOnDroppedPins:(id)sender {
}

- (IBAction)dropManyPins:(id)sender {
[self.mapView removeAnnotations:self.mapView.annotations];
[self removeAllAnnotations:sender];

NSRect bounds = self.mapView.bounds;
NSMutableArray *annotations = [NSMutableArray array];
Expand Down Expand Up @@ -273,14 +274,15 @@ - (void)dropOneOfManyPins:(NSTimer *)timer {
}
}

- (IBAction)removeAllPins:(id)sender {
- (IBAction)removeAllAnnotations:(id)sender {
[self.mapView removeAnnotations:self.mapView.annotations];
_isShowingPolygonAndPolylineAnnotations = NO;
}

- (IBAction)startWorldTour:(id)sender {
_isTouringWorld = YES;

[self removeAllPins:sender];
[self removeAllAnnotations:sender];
NSUInteger numberOfAnnotations = sizeof(WorldTourDestinations) / sizeof(WorldTourDestinations[0]);
NSMutableArray *annotations = [NSMutableArray arrayWithCapacity:numberOfAnnotations];
for (NSUInteger i = 0; i < numberOfAnnotations; i++) {
Expand Down Expand Up @@ -319,6 +321,35 @@ - (IBAction)stopWorldTour:(id)sender {
self.mapView.camera = self.mapView.camera;
}

- (IBAction)drawPolygonAndPolyLineAnnotations:(id)sender {

if (_isShowingPolygonAndPolylineAnnotations) {
[self removeAllAnnotations:sender];
return;
}

_isShowingPolygonAndPolylineAnnotations = YES;

// Pacific Northwest triangle
CLLocationCoordinate2D triangleCoordinates[3] = {
CLLocationCoordinate2DMake(44, -122),
CLLocationCoordinate2DMake(46, -122),
CLLocationCoordinate2DMake(46, -121)
};
MGLPolygon *triangle = [MGLPolygon polygonWithCoordinates:triangleCoordinates count:3];
[self.mapView addAnnotation:triangle];

// West coast line
CLLocationCoordinate2D lineCoordinates[4] = {
CLLocationCoordinate2DMake(47.6025, -122.3327),
CLLocationCoordinate2DMake(45.5189, -122.6726),
CLLocationCoordinate2DMake(37.7790, -122.4177),
CLLocationCoordinate2DMake(34.0532, -118.2349)
};
MGLPolyline *line = [MGLPolyline polylineWithCoordinates:lineCoordinates count:4];
[self.mapView addAnnotation:line];
}

#pragma mark Help methods

- (IBAction)giveFeedback:(id)sender {
Expand Down Expand Up @@ -457,15 +488,18 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
if (menuItem.action == @selector(dropManyPins:)) {
return YES;
}
if (menuItem.action == @selector(removeAllPins:)) {
return self.mapView.annotations.count;
if (menuItem.action == @selector(removeAllAnnotations:)) {
return self.mapView.annotations.count > 0;
}
if (menuItem.action == @selector(startWorldTour:)) {
return !_isTouringWorld;
}
if (menuItem.action == @selector(stopWorldTour:)) {
return _isTouringWorld;
}
if (menuItem.action == @selector(drawPolygonAndPolyLineAnnotations:)) {
return !_isShowingPolygonAndPolylineAnnotations;
}
if (menuItem.action == @selector(giveFeedback:)) {
return YES;
}
Expand Down
8 changes: 4 additions & 4 deletions platform/osx/include/MGLMapViewDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ NS_ASSUME_NONNULL_BEGIN

/** Returns the color to use when rendering the outline of a shape annotation.
The default stroke color is black. If a pattern color is specified, the
result is undefined.
The default stroke color is the selected menu item color. If a pattern
color is specified, the result is undefined.
@param mapView The map view rendering the shape annotation.
@param annotation The annotation being rendered.
Expand All @@ -114,8 +114,8 @@ NS_ASSUME_NONNULL_BEGIN

/** Returns the color to use when rendering the fill of a polygon annotation.
The default fill color is blue. If a pattern color is specified, the result
is undefined.
The default fill color is selected menu item color. If a pattern color
is specified, the result is undefined.
@param mapView The map view rendering the polygon annotation.
@param annotation The annotation being rendered.
Expand Down
4 changes: 2 additions & 2 deletions platform/osx/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1987,14 +1987,14 @@ - (double)alphaForShapeAnnotation:(MGLShape *)annotation {
- (mbgl::Color)strokeColorForShapeAnnotation:(MGLShape *)annotation {
NSColor *color = (_delegateHasStrokeColorsForShapeAnnotations
? [self.delegate mapView:self strokeColorForShapeAnnotation:annotation]
: [NSColor blackColor]);
: [NSColor selectedMenuItemColor]);
return MGLColorObjectFromNSColor(color);
}

- (mbgl::Color)fillColorForPolygonAnnotation:(MGLPolygon *)annotation {
NSColor *color = (_delegateHasFillColorsForShapeAnnotations
? [self.delegate mapView:self fillColorForPolygonAnnotation:annotation]
: [NSColor blueColor]);
: [NSColor selectedMenuItemColor]);
return MGLColorObjectFromNSColor(color);
}

Expand Down

0 comments on commit 21ce6fb

Please sign in to comment.