summaryrefslogtreecommitdiff
path: root/platform/macos/src/MGLMapView.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/macos/src/MGLMapView.mm')
-rw-r--r--platform/macos/src/MGLMapView.mm63
1 files changed, 48 insertions, 15 deletions
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;
}