diff options
Diffstat (limited to 'platform/macos')
-rw-r--r-- | platform/macos/CHANGELOG.md | 2 | ||||
-rw-r--r-- | platform/macos/app/Base.lproj/MainMenu.xib | 4 | ||||
-rw-r--r-- | platform/macos/app/MapDocument.m | 78 | ||||
-rw-r--r-- | platform/macos/jazzy.yml | 1 | ||||
-rw-r--r-- | platform/macos/macos.xcodeproj/project.pbxproj | 12 | ||||
-rw-r--r-- | platform/macos/sdk-files.json | 3 | ||||
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 63 | ||||
-rw-r--r-- | platform/macos/src/MGLMapViewDelegate.h | 16 | ||||
-rw-r--r-- | platform/macos/src/Mapbox.h | 1 | ||||
-rw-r--r-- | platform/macos/test/MGLMapViewDelegateIntegrationTests.swift | 2 |
10 files changed, 134 insertions, 48 deletions
diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 98bdda0abc..f0ba162cf6 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -20,6 +20,8 @@ ### Annotations +* Added the `MGLCircle` class for adding physical circles to the map view as overlays or to a shape source as polygons. ([#14534](https://github.com/mapbox/mapbox-gl-native/pull/14534)) +* Deprecated the `-[MGLMapViewDelegate mapView:fillColorForPolygonAnnotation:]` method in favor of `-[MGLMapViewDelegate mapView:fillColorForShape:]`, which is also called for `MGLCircle` annotations. ([#14534](https://github.com/mapbox/mapbox-gl-native/pull/14534)) * Fixed a bug with `MGLMapView.visibleAnnotations` that resulted in incorrect results and performance degradation. ([#13745](https://github.com/mapbox/mapbox-gl-native/pull/13745)) * Fixed a bug where selecting partially on-screen annotations (without a callout) would move the map. ([#13727](https://github.com/mapbox/mapbox-gl-native/pull/13727)) diff --git a/platform/macos/app/Base.lproj/MainMenu.xib b/platform/macos/app/Base.lproj/MainMenu.xib index 6f8f24ce99..a359570d8a 100644 --- a/platform/macos/app/Base.lproj/MainMenu.xib +++ b/platform/macos/app/Base.lproj/MainMenu.xib @@ -542,9 +542,9 @@ <action selector="dropManyPins:" target="-1" id="Rtv-8N-3Z8"/> </connections> </menuItem> - <menuItem title="Add Polygon and Polyline" keyEquivalent="l" id="DVr-vT-lpe"> + <menuItem title="Simulate Nightfall" keyEquivalent="l" id="DVr-vT-lpe"> <connections> - <action selector="drawPolygonAndPolyLineAnnotations:" target="-1" id="EhT-CB-gee"/> + <action selector="addNightAndLighthouse:" target="-1" id="EhT-CB-gee"/> </connections> </menuItem> <menuItem title="Add Animated Annotation" id="Etf-JN-Aoc"> diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 213aa33107..7716dfeb05 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -99,7 +99,7 @@ NSArray<id <MGLAnnotation>> *MBXFlattenedShapes(NSArray<id <MGLAnnotation>> *sha BOOL _showsToolTipsOnDroppedPins; BOOL _randomizesCursorsOnDroppedPins; BOOL _isTouringWorld; - BOOL _isShowingPolygonAndPolylineAnnotations; + BOOL _isShowingNightAndLighthouse; BOOL _isShowingAnimatedAnnotation; MGLMapSnapshotter *_snapshotter; @@ -627,7 +627,7 @@ NSArray<id <MGLAnnotation>> *MBXFlattenedShapes(NSArray<id <MGLAnnotation>> *sha - (IBAction)removeAllAnnotations:(id)sender { [self.mapView removeAnnotations:self.mapView.annotations]; - _isShowingPolygonAndPolylineAnnotations = NO; + _isShowingNightAndLighthouse = NO; _isShowingAnimatedAnnotation = NO; } @@ -673,33 +673,55 @@ NSArray<id <MGLAnnotation>> *MBXFlattenedShapes(NSArray<id <MGLAnnotation>> *sha self.mapView.camera = self.mapView.camera; } -- (IBAction)drawPolygonAndPolyLineAnnotations:(id)sender { +- (IBAction)addNightAndLighthouse:(id)sender { - if (_isShowingPolygonAndPolylineAnnotations) { - [self removeAllAnnotations:sender]; + if (_isShowingNightAndLighthouse) { return; } - _isShowingPolygonAndPolylineAnnotations = YES; + _isShowingNightAndLighthouse = YES; - // Pacific Northwest triangle - CLLocationCoordinate2D triangleCoordinates[3] = { - CLLocationCoordinate2DMake(44, -122), - CLLocationCoordinate2DMake(46, -122), - CLLocationCoordinate2DMake(46, -121) + // Daylight map, produced by multiple spherical caps simulating night + // https://en.wikipedia.org/wiki/Twilight + CLLocationDistance nightRadius = M_PI_2 * 6378137.0; + CLLocationDistance nightCapRadii[] = { + nightRadius, // civil twilight + nightRadius * (1.0 - 18.0 / 180 * 2), // nautical twilight + nightRadius * (1.0 - 12.0 / 180 * 2), // astronomical twilight + nightRadius * (1.0 - 6.0 / 180 * 2), // night }; - 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]; + NSMutableArray *nightCaps = [NSMutableArray array]; + for (size_t i = 0; i < sizeof(nightCapRadii) / sizeof(nightCapRadii[0]); i++) { + MGLCircle *cap = [MGLCircle circleWithCenterCoordinate:CLLocationCoordinate2DMake(23.5, 0) + radius:nightCapRadii[i]]; + cap.title = @"Night"; + [nightCaps addObject:cap]; + } + [self.mapView addAnnotations:nightCaps]; + + // Concentric circles around Boston Light + // https://en.wikipedia.org/wiki/Boston_Light + CLLocationCoordinate2D epicenter = CLLocationCoordinate2DMake(42.32792025, -70.8901050288306); + NSMutableArray *concentricCircles = [NSMutableArray array]; + for (NSUInteger magnitude = 0; magnitude < 8; magnitude++) { + CLLocationDistance radius = exp(magnitude); + MGLCircle *circle = [MGLCircle circleWithCenterCoordinate:epicenter radius:radius]; + [concentricCircles addObject:circle]; + } + [self.mapView addAnnotations:concentricCircles]; + [self.mapView showAnnotations:@[concentricCircles[5]] animated:NO]; + + __block NSUInteger stepCount = 0; + [NSTimer scheduledTimerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) { + // Pulse each circle for a minute. + [concentricCircles enumerateObjectsUsingBlock:^(MGLCircle * _Nonnull circle, NSUInteger magnitude, BOOL * _Nonnull stop) { + circle.radius = exp(magnitude) + exp(magnitude - 1) * sin(M_PI / 10 * stepCount); + }]; + + if (++stepCount >= 60) { + [timer invalidate]; + } + }]; } - (IBAction)drawAnimatedAnnotation:(id)sender { @@ -1249,8 +1271,8 @@ NSArray<id <MGLAnnotation>> *MBXFlattenedShapes(NSArray<id <MGLAnnotation>> *sha if (menuItem.action == @selector(dropManyPins:)) { return YES; } - if (menuItem.action == @selector(drawPolygonAndPolyLineAnnotations:)) { - return !_isShowingPolygonAndPolylineAnnotations; + if (menuItem.action == @selector(addNightAndLighthouse:)) { + return !_isShowingNightAndLighthouse; } if (menuItem.action == @selector(drawAnimatedAnnotation:)) { return !_isShowingAnimatedAnnotation; @@ -1442,7 +1464,11 @@ NSArray<id <MGLAnnotation>> *MBXFlattenedShapes(NSArray<id <MGLAnnotation>> *sha } - (CGFloat)mapView:(MGLMapView *)mapView alphaForShapeAnnotation:(MGLShape *)annotation { - return 0.8; + return [annotation isKindOfClass:[MGLCircle class]] ? 0.1 : 0.8; +} + +- (NSColor *)mapView:(MGLMapView *)mapView fillColorForShape:(MGLShape *)shape { + return shape.title ? [NSColor blackColor] : [NSColor whiteColor]; } #pragma mark - MGLComputedShapeSourceDataSource diff --git a/platform/macos/jazzy.yml b/platform/macos/jazzy.yml index 381e6f8b33..3cea18e80d 100644 --- a/platform/macos/jazzy.yml +++ b/platform/macos/jazzy.yml @@ -41,6 +41,7 @@ custom_categories: - MGLMultiPoint - MGLPointAnnotation - MGLPointCollection + - MGLCircle - MGLPolygon - MGLPolyline - MGLMultiPolygon diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 91ed2f4cfa..e0c584b0ad 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -145,6 +145,9 @@ DA35A2CF1CCAAED300E826B2 /* NSValue+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DA35A2CD1CCAAED300E826B2 /* NSValue+MGLAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA35A2D01CCAAED300E826B2 /* NSValue+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2CE1CCAAED300E826B2 /* NSValue+MGLAdditions.m */; }; DA35D08A1E1A631B007DED41 /* one-liner.json in Resources */ = {isa = PBXBuildFile; fileRef = DA35D0891E1A631B007DED41 /* one-liner.json */; }; + DA44898422730B4A005B8357 /* MGLCircle.h in Headers */ = {isa = PBXBuildFile; fileRef = DA44898222730B49005B8357 /* MGLCircle.h */; settings = {ATTRIBUTES = (Public, ); }; }; + DA44898522730B4A005B8357 /* MGLCircle.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA44898322730B4A005B8357 /* MGLCircle.mm */; }; + DA44898722731139005B8357 /* MGLCircle_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA44898622731139005B8357 /* MGLCircle_Private.h */; }; DA551B821DB496AC0009AFAF /* MGLTileSource.h in Headers */ = {isa = PBXBuildFile; fileRef = DA551B7F1DB496AC0009AFAF /* MGLTileSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA551B831DB496AC0009AFAF /* MGLTileSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA551B801DB496AC0009AFAF /* MGLTileSource_Private.h */; }; DA551B841DB496AC0009AFAF /* MGLTileSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA551B811DB496AC0009AFAF /* MGLTileSource.mm */; }; @@ -488,6 +491,9 @@ DA35A2CD1CCAAED300E826B2 /* NSValue+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSValue+MGLAdditions.h"; sourceTree = "<group>"; }; DA35A2CE1CCAAED300E826B2 /* NSValue+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSValue+MGLAdditions.m"; sourceTree = "<group>"; }; DA35D0891E1A631B007DED41 /* one-liner.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "one-liner.json"; path = "../../darwin/test/one-liner.json"; sourceTree = "<group>"; }; + DA44898222730B49005B8357 /* MGLCircle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLCircle.h; sourceTree = "<group>"; }; + DA44898322730B4A005B8357 /* MGLCircle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLCircle.mm; sourceTree = "<group>"; }; + DA44898622731139005B8357 /* MGLCircle_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLCircle_Private.h; sourceTree = "<group>"; }; DA551B7F1DB496AC0009AFAF /* MGLTileSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLTileSource.h; sourceTree = "<group>"; }; DA551B801DB496AC0009AFAF /* MGLTileSource_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLTileSource_Private.h; sourceTree = "<group>"; }; DA551B811DB496AC0009AFAF /* MGLTileSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLTileSource.mm; sourceTree = "<group>"; }; @@ -1047,6 +1053,9 @@ isa = PBXGroup; children = ( DAE6C34B1CC31E0400DB3429 /* MGLAnnotation.h */, + DA44898622731139005B8357 /* MGLCircle_Private.h */, + DA44898222730B49005B8357 /* MGLCircle.h */, + DA44898322730B4A005B8357 /* MGLCircle.mm */, CA4045C4216720D700B356E1 /* MGLCluster.h */, DACC22171CF3D4F700D220D9 /* MGLFeature_Private.h */, DACC22121CF3D3E200D220D9 /* MGLFeature.h */, @@ -1361,6 +1370,7 @@ DAE6C3621CC31E0400DB3429 /* MGLOverlay.h in Headers */, DAE6C3651CC31E0400DB3429 /* MGLPolyline.h in Headers */, DAE6C39A1CC31E2A00DB3429 /* NSProcessInfo+MGLAdditions.h in Headers */, + DA44898722731139005B8357 /* MGLCircle_Private.h in Headers */, 92F2C3EB1F0E3A1900268EC0 /* MGLRendererFrontend.h in Headers */, DA8F258B1D51CA540010E6B5 /* MGLLineStyleLayer.h in Headers */, 35C6DF841E214C0400ACA483 /* MGLDistanceFormatter.h in Headers */, @@ -1370,6 +1380,7 @@ 359819591E02F611008FC139 /* NSCoder+MGLAdditions.h in Headers */, DAE6C38E1CC31E2A00DB3429 /* MGLOfflineStorage_Private.h in Headers */, 747ABE61219B2C0000523B67 /* MGLLineStyleLayer_Private.h in Headers */, + DA44898422730B4A005B8357 /* MGLCircle.h in Headers */, 747ABE5F219B2BED00523B67 /* MGLHillshadeStyleLayer_Private.h in Headers */, DA87A9A01DC9DC6200810D09 /* MGLValueEvaluator.h in Headers */, 8946239D200E744800DA8EF2 /* MGLHeatmapStyleLayer.h in Headers */, @@ -1652,6 +1663,7 @@ 35602BFB1D3EA99F0050646F /* MGLFillStyleLayer.mm in Sources */, DAE6C3931CC31E2A00DB3429 /* MGLShape.mm in Sources */, 352742861D4C244700A1ECE6 /* MGLRasterTileSource.mm in Sources */, + DA44898522730B4A005B8357 /* MGLCircle.mm in Sources */, 558DE7A71E56161C00C7916D /* MGLFoundation.mm in Sources */, DAE6C39D1CC31E2A00DB3429 /* NSString+MGLAdditions.m in Sources */, 3598195A1E02F611008FC139 /* NSCoder+MGLAdditions.mm in Sources */, diff --git a/platform/macos/sdk-files.json b/platform/macos/sdk-files.json index 4448de1f5b..bb68180f65 100644 --- a/platform/macos/sdk-files.json +++ b/platform/macos/sdk-files.json @@ -23,6 +23,7 @@ "platform/darwin/src/MGLFillStyleLayer.mm", "platform/darwin/src/MGLShape.mm", "platform/darwin/src/MGLRasterTileSource.mm", + "platform/darwin/src/MGLCircle.mm", "platform/darwin/src/MGLFoundation.mm", "platform/darwin/src/NSString+MGLAdditions.m", "platform/darwin/src/NSCoder+MGLAdditions.mm", @@ -118,6 +119,7 @@ "MGLPolyline.h": "platform/darwin/src/MGLPolyline.h", "MGLLineStyleLayer.h": "platform/darwin/src/MGLLineStyleLayer.h", "MGLDistanceFormatter.h": "platform/darwin/src/MGLDistanceFormatter.h", + "MGLCircle.h": "platform/darwin/src/MGLCircle.h", "MGLHeatmapStyleLayer.h": "platform/darwin/src/MGLHeatmapStyleLayer.h", "MGLOfflineRegion.h": "platform/darwin/src/MGLOfflineRegion.h", "MGLTilePyramidOfflineRegion.h": "platform/darwin/src/MGLTilePyramidOfflineRegion.h", @@ -178,6 +180,7 @@ "NSCompoundPredicate+MGLAdditions.h": "platform/darwin/src/NSCompoundPredicate+MGLAdditions.h", "MGLSymbolStyleLayer_Private.h": "platform/darwin/src/MGLSymbolStyleLayer_Private.h", "NSProcessInfo+MGLAdditions.h": "platform/macos/src/NSProcessInfo+MGLAdditions.h", + "MGLCircle_Private.h": "platform/darwin/src/MGLCircle_Private.h", "MGLRendererFrontend.h": "platform/darwin/src/MGLRendererFrontend.h", "NSValue+MGLStyleAttributeAdditions.h": "platform/darwin/src/NSValue+MGLStyleAttributeAdditions.h", "NSImage+MGLAdditions.h": "platform/macos/src/NSImage+MGLAdditions.h", diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index e9259cf907..9c1cc890f6 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -21,6 +21,7 @@ #import "MGLMapCamera.h" #import "MGLPolygon.h" #import "MGLPolyline.h" +#import "MGLCircle_Private.h" #import "MGLAnnotationImage.h" #import "MGLMapViewDelegate.h" #import "MGLImageSource.h" @@ -194,6 +195,7 @@ public: BOOL _delegateHasAlphasForShapeAnnotations; BOOL _delegateHasStrokeColorsForShapeAnnotations; + BOOL _delegateHasFillColorsForPolygonAnnotations; BOOL _delegateHasFillColorsForShapeAnnotations; BOOL _delegateHasLineWidthsForShapeAnnotations; @@ -566,7 +568,8 @@ public: [self adjustContentInsets]; } else if ([keyPath isEqualToString:@"coordinate"] && [object conformsToProtocol:@protocol(MGLAnnotation)] && - ![object isKindOfClass:[MGLMultiPoint class]]) { + ![object isKindOfClass:[MGLMultiPoint class]] && + ![object isKindOfClass:[MGLCircle class]]) { id <MGLAnnotation> annotation = object; MGLAnnotationTag annotationTag = (MGLAnnotationTag)(NSUInteger)context; // We can get here because a subclass registered itself as an observer @@ -581,8 +584,11 @@ public: _mbglMap->updateAnnotation(annotationTag, mbgl::SymbolAnnotation { point, annotationImage.styleIconIdentifier.UTF8String ?: "" }); [self updateAnnotationCallouts]; } - } else if ([keyPath isEqualToString:@"coordinates"] && - [object isKindOfClass:[MGLMultiPoint class]]) { + } else if (([keyPath isEqualToString:@"coordinates"] && + [object isKindOfClass:[MGLMultiPoint class]]) || + (([keyPath isEqualToString:@"coordinate"] || + [keyPath isEqualToString:@"radius"]) && + [object isKindOfClass:[MGLCircle class]])) { MGLMultiPoint *annotation = object; MGLAnnotationTag annotationTag = (MGLAnnotationTag)(NSUInteger)context; // We can get here because a subclass registered itself as an observer @@ -609,7 +615,8 @@ public: // hot loop, namely the annotation style methods. _delegateHasAlphasForShapeAnnotations = [_delegate respondsToSelector:@selector(mapView:alphaForShapeAnnotation:)]; _delegateHasStrokeColorsForShapeAnnotations = [_delegate respondsToSelector:@selector(mapView:strokeColorForShapeAnnotation:)]; - _delegateHasFillColorsForShapeAnnotations = [_delegate respondsToSelector:@selector(mapView:fillColorForPolygonAnnotation:)]; + _delegateHasFillColorsForPolygonAnnotations = [_delegate respondsToSelector:@selector(mapView:fillColorForPolygonAnnotation:)]; + _delegateHasFillColorsForShapeAnnotations = [_delegate respondsToSelector:@selector(mapView:fillColorForShape:)]; _delegateHasLineWidthsForShapeAnnotations = [_delegate respondsToSelector:@selector(mapView:lineWidthForPolylineAnnotation:)]; #pragma clang diagnostic push @@ -1979,6 +1986,19 @@ public: _annotationTagsByAnnotation[annotation] = annotationTag; [(NSObject *)annotation addObserver:self forKeyPath:@"coordinates" options:0 context:(void *)(NSUInteger)annotationTag]; + } else if ([annotation isKindOfClass:[MGLCircle class]]) { + // The circle knows how to style itself (with the map view’s help). + MGLCircle *circle = (MGLCircle *)annotation; + + _isChangingAnnotationLayers = YES; + MGLAnnotationTag annotationTag = _mbglMap->addAnnotation([circle annotationObjectWithDelegate:self]); + MGLAnnotationContext context; + context.annotation = annotation; + _annotationContextsByAnnotationTag[annotationTag] = context; + _annotationTagsByAnnotation[annotation] = annotationTag; + + [(NSObject *)annotation addObserver:self forKeyPath:@"coordinate" options:0 context:(void *)(NSUInteger)annotationTag]; + [(NSObject *)annotation addObserver:self forKeyPath:@"radius" options:0 context:(void *)(NSUInteger)annotationTag]; } else if (![annotation isKindOfClass:[MGLMultiPolyline class]] && ![annotation isKindOfClass:[MGLMultiPolygon class]] && ![annotation isKindOfClass:[MGLShapeCollection class]] @@ -2111,6 +2131,9 @@ public: } else if ([annotation isKindOfClass:[MGLMultiPoint class]]) { [(NSObject *)annotation removeObserver:self forKeyPath:@"coordinates" context:(void *)(NSUInteger)annotationTag]; } + if ([annotation isKindOfClass:[MGLCircle class]]) { + [(NSObject *)annotation removeObserver:self forKeyPath:@"radius" context:(void *)(NSUInteger)annotationTag]; + } _isChangingAnnotationLayers = YES; _mbglMap->removeAnnotation(annotationTag); @@ -2477,14 +2500,12 @@ public: mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); - for (id <MGLAnnotation> annotation in annotations) - { - if ([annotation conformsToProtocol:@protocol(MGLOverlay)]) - { + for (id <MGLAnnotation> annotation in annotations) { + if ([annotation conformsToProtocol:@protocol(MGLOverlay)]) { bounds.extend(MGLLatLngBoundsFromCoordinateBounds(((id <MGLOverlay>)annotation).overlayBounds)); - } - else - { + } else if ([annotation isKindOfClass:[MGLCircle class]]) { + bounds.extend(MGLLatLngBoundsFromCoordinateBounds(((MGLCircle *)annotation).coordinateBounds)); + } else { bounds.extend(MGLLatLngFromLocationCoordinate2D(annotation.coordinate)); } } @@ -2634,10 +2655,22 @@ public: return color.mgl_color; } -- (mbgl::Color)fillColorForPolygonAnnotation:(MGLPolygon *)annotation { - NSColor *color = (_delegateHasFillColorsForShapeAnnotations - ? [self.delegate mapView:self fillColorForPolygonAnnotation:annotation] - : [NSColor selectedMenuItemColor]); +- (mbgl::Color)fillColorForShape:(MGLShape *)shape { + NSColor *color = [NSColor selectedMenuItemColor]; + if (_delegateHasFillColorsForShapeAnnotations) { + color = [self.delegate mapView:self fillColorForShape:shape]; + } else if (_delegateHasFillColorsForPolygonAnnotations && [shape isKindOfClass:[MGLPolygon class]]) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSLog(@"-[MGLMapViewDelegate mapView:fillColorForPolygonAnnotation:] is deprecated; " + @"use -[MGLMapViewDelegate mapView:fillColorForShape:] instead." + @"This warning will only appear once."); + }); + color = [self.delegate mapView:self fillColorForPolygonAnnotation:(MGLPolygon *)shape]; +#pragma clang diagnostic pop + } return color.mgl_color; } diff --git a/platform/macos/src/MGLMapViewDelegate.h b/platform/macos/src/MGLMapViewDelegate.h index c7d6786666..4717df68ea 100644 --- a/platform/macos/src/MGLMapViewDelegate.h +++ b/platform/macos/src/MGLMapViewDelegate.h @@ -6,6 +6,7 @@ NS_ASSUME_NONNULL_BEGIN @class MGLAnnotationImage; @class MGLPolygon; @class MGLPolyline; +@class MGLCircle; @class MGLShape; /** @@ -227,20 +228,25 @@ NS_ASSUME_NONNULL_BEGIN */ - (NSColor *)mapView:(MGLMapView *)mapView strokeColorForShapeAnnotation:(MGLShape *)annotation; +- (NSColor *)mapView:(MGLMapView *)mapView fillColorForPolygonAnnotation:(MGLPolygon *)annotation __attribute__((deprecated("", "-mapView:fillColorForShape:"))); + /** - Returns the color to use when rendering the fill of a polygon annotation. + Returns the color to use when rendering the fill of a shape annotation. + This method is only called for `MGLPolygon` and `MGLCircle` annotations. It is + not possible to fill a polyline or point annotation. + The default fill color is the selected menu item color. If a pattern color is specified, the result is undefined. Opacity may be set by specifying an alpha component. The default alpha value is `1.0` and results in a completely opaque shape. - @param mapView The map view rendering the polygon annotation. - @param annotation The annotation being rendered. - @return The polygon’s interior fill color. + @param mapView The map view rendering the shape annotation. + @param shape The annotation being rendered. + @return The shape’s fill color. */ -- (NSColor *)mapView:(MGLMapView *)mapView fillColorForPolygonAnnotation:(MGLPolygon *)annotation; +- (NSColor *)mapView:(MGLMapView *)mapView fillColorForShape:(MGLShape *)shape; /** Returns the line width in points to use when rendering the outline of a diff --git a/platform/macos/src/Mapbox.h b/platform/macos/src/Mapbox.h index 6728992d6b..595ce08d92 100644 --- a/platform/macos/src/Mapbox.h +++ b/platform/macos/src/Mapbox.h @@ -32,6 +32,7 @@ FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[]; #import "MGLPointCollection.h" #import "MGLPolygon.h" #import "MGLPolyline.h" +#import "MGLCircle.h" #import "MGLShape.h" #import "MGLShapeCollection.h" #import "MGLStyle.h" diff --git a/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift b/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift index 83c7160fde..345b15df49 100644 --- a/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift +++ b/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift @@ -54,6 +54,8 @@ extension MGLMapViewDelegateIntegrationTests: MGLMapViewDelegate { func mapView(_ mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> NSColor { return .black } func mapView(_ mapView: MGLMapView, fillColorForPolygonAnnotation annotation: MGLPolygon) -> NSColor { return .black } + + func mapView(_ mapView: MGLMapView, fillColorFor shape: MGLShape) -> NSColor { return .black } func mapView(_ mapView: MGLMapView, calloutViewControllerFor annotation: MGLAnnotation) -> NSViewController? { return nil } |