diff --git a/CHANGELOG.md b/CHANGELOG.md index f70cf17b4bb..8d403d5ad3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,8 @@ Known issues: ## iOS master +- Polygons and polylines now default to using the map view's tint color. ([#4028](https://github.com/mapbox/mapbox-gl-native/pull/4028)) + ## iOS 3.1.0 - The SDK is now distributed as a dynamic framework instead of a static library, resulting in a simpler installation workflow and significantly reduced download size. The framework contains both simulator and device content; due to [an Xcode bug](http://www.openradar.me/radar?id=6409498411401216), you’ll need to strip out the simulator content before submitting your application to the App Store. ([#3183](https://github.com/mapbox/mapbox-gl-native/pull/3183)) diff --git a/platform/ios/include/MGLMapView.h b/platform/ios/include/MGLMapView.h index dc03c13f7b0..d974f4673e4 100644 --- a/platform/ios/include/MGLMapView.h +++ b/platform/ios/include/MGLMapView.h @@ -1133,7 +1133,7 @@ IB_DESIGNABLE - (CGFloat)mapView:(MGLMapView *)mapView alphaForShapeAnnotation:(MGLShape *)annotation; /** - Returns the stroke color to use when rendering a shape annotation. Defaults to black. + Returns the stroke color to use when rendering a shape annotation. Defaults to the map view’s tint color. @param mapView The map view rendering the shape annotation. @param annotation The annotation being rendered. @@ -1142,7 +1142,7 @@ IB_DESIGNABLE - (UIColor *)mapView:(MGLMapView *)mapView strokeColorForShapeAnnotation:(MGLShape *)annotation; /** - Returns the fill color to use when rendering a polygon annotation. Defaults to blue. + Returns the fill color to use when rendering a polygon annotation. Defaults to the map view’s tint color. @param mapView The map view rendering the polygon annotation. @param annotation The annotation being rendered. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 748bfc7414c..1d5eb2ea778 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2469,7 +2469,7 @@ - (double)alphaForShapeAnnotation:(MGLShape *)annotation { UIColor *color = (_delegateHasStrokeColorsForShapeAnnotations ? [self.delegate mapView:self strokeColorForShapeAnnotation:annotation] - : [UIColor blackColor]); + : self.tintColor); return MGLColorObjectFromUIColor(color); } @@ -2477,7 +2477,7 @@ - (double)alphaForShapeAnnotation:(MGLShape *)annotation { UIColor *color = (_delegateHasFillColorsForShapeAnnotations ? [self.delegate mapView:self fillColorForPolygonAnnotation:annotation] - : [UIColor blueColor]); + : self.tintColor); return MGLColorObjectFromUIColor(color); } diff --git a/platform/osx/app/MainMenu.xib b/platform/osx/app/MainMenu.xib index 844af08f3e3..64ff4e550d2 100644 --- a/platform/osx/app/MainMenu.xib +++ b/platform/osx/app/MainMenu.xib @@ -1,7 +1,7 @@ - + - + @@ -473,10 +473,16 @@ - + - + + + + + + + @@ -545,7 +551,7 @@ - + diff --git a/platform/osx/app/MapDocument.m b/platform/osx/app/MapDocument.m index 6881f6bd5bf..7c42bc98022 100644 --- a/platform/osx/app/MapDocument.m +++ b/platform/osx/app/MapDocument.m @@ -33,6 +33,7 @@ @implementation MapDocument { BOOL _showsToolTipsOnDroppedPins; BOOL _randomizesCursorsOnDroppedPins; BOOL _isTouringWorld; + BOOL _isShowingPolygonAndPolylineAnnotations; } #pragma mark Lifecycle @@ -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]; @@ -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++) { @@ -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 { @@ -457,8 +488,8 @@ - (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; @@ -466,6 +497,9 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { if (menuItem.action == @selector(stopWorldTour:)) { return _isTouringWorld; } + if (menuItem.action == @selector(drawPolygonAndPolyLineAnnotations:)) { + return !_isShowingPolygonAndPolylineAnnotations; + } if (menuItem.action == @selector(giveFeedback:)) { return YES; } diff --git a/platform/osx/include/MGLMapViewDelegate.h b/platform/osx/include/MGLMapViewDelegate.h index eece606c399..fcd013284d9 100644 --- a/platform/osx/include/MGLMapViewDelegate.h +++ b/platform/osx/include/MGLMapViewDelegate.h @@ -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. @@ -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. diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index de65e0496dd..ec3fb7eb351 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -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); }