summaryrefslogtreecommitdiff
path: root/platform/ios/src
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2019-04-28 17:23:23 -0700
committerMinh Nguyễn <mxn@1ec5.org>2019-05-07 22:04:48 -0700
commit910639168aaad8f06749c5be184ae50dbe9d566b (patch)
tree9bd1642efe2c9ed65b51a8a317602975b7c5c73f /platform/ios/src
parent84a11ba4e5a6c64edd63b81d606e2ae57862c798 (diff)
downloadqtlocation-mapboxgl-upstream/1ec5-circle-2167.tar.gz
[ios, macos] Added circle geometryupstream/1ec5-circle-2167
Added an MGLCircle class that generates a many-sided polygon under the hood.
Diffstat (limited to 'platform/ios/src')
-rw-r--r--platform/ios/src/MGLMapView.h2
-rw-r--r--platform/ios/src/MGLMapView.mm56
-rw-r--r--platform/ios/src/MGLMapViewDelegate.h30
-rw-r--r--platform/ios/src/Mapbox.h1
4 files changed, 69 insertions, 20 deletions
diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h
index 63bd28fc0c..ed5462a755 100644
--- a/platform/ios/src/MGLMapView.h
+++ b/platform/ios/src/MGLMapView.h
@@ -11,8 +11,6 @@ NS_ASSUME_NONNULL_BEGIN
@class MGLAnnotationView;
@class MGLAnnotationImage;
@class MGLUserLocation;
-@class MGLPolyline;
-@class MGLPolygon;
@class MGLShape;
@class MGLStyle;
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index fdd91dacd7..f43bb93115 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -38,6 +38,7 @@
#import "MGLFeature_Private.h"
#import "MGLGeometry_Private.h"
#import "MGLMultiPoint_Private.h"
+#import "MGLCircle_Private.h"
#import "MGLOfflineStorage_Private.h"
#import "MGLVectorTileSource_Private.h"
#import "MGLFoundation_Private.h"
@@ -317,6 +318,7 @@ public:
BOOL _delegateHasAlphasForShapeAnnotations;
BOOL _delegateHasStrokeColorsForShapeAnnotations;
+ BOOL _delegateHasFillColorsForPolygonAnnotations;
BOOL _delegateHasFillColorsForShapeAnnotations;
BOOL _delegateHasLineWidthsForShapeAnnotations;
@@ -826,7 +828,8 @@ public:
_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:)];
}
@@ -2557,7 +2560,7 @@ public:
[MGLMapboxEvents ensureMetricsOptoutExists];
}
}
- else if ([keyPath isEqualToString:@"coordinate"] && [object conformsToProtocol:@protocol(MGLAnnotation)] && ![object isKindOfClass:[MGLMultiPoint class]])
+ else if ([keyPath isEqualToString:@"coordinate"] && [object conformsToProtocol:@protocol(MGLAnnotation)] && ![object isKindOfClass:[MGLMultiPoint class]] && ![object isKindOfClass:[MGLCircle class]])
{
id <MGLAnnotation> annotation = object;
MGLAnnotationTag annotationTag = (MGLAnnotationTag)(NSUInteger)context;
@@ -2588,7 +2591,8 @@ public:
}
}
}
- 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;
@@ -4222,6 +4226,21 @@ public:
[(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]]
@@ -4439,11 +4458,26 @@ public:
return color.mgl_color;
}
-- (mbgl::Color)fillColorForPolygonAnnotation:(MGLPolygon *)annotation
+- (mbgl::Color)fillColorForShape:(MGLShape *)shape
{
- UIColor *color = (_delegateHasFillColorsForShapeAnnotations
- ? [self.delegate mapView:self fillColorForPolygonAnnotation:annotation]
- : self.tintColor);
+ UIColor *color = self.tintColor;
+ 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;
}
@@ -4535,6 +4569,10 @@ public:
{
[(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;
self.mbglMap.removeAnnotation(annotationTag);
@@ -5286,6 +5324,10 @@ public:
{
bounds.extend(MGLLatLngBoundsFromCoordinateBounds(((id <MGLOverlay>)annotation).overlayBounds));
}
+ else if ([annotation isKindOfClass:[MGLCircle class]])
+ {
+ bounds.extend(MGLLatLngBoundsFromCoordinateBounds(((MGLCircle *)annotation).coordinateBounds));
+ }
else
{
bounds.extend(MGLLatLngFromLocationCoordinate2D(annotation.coordinate));
diff --git a/platform/ios/src/MGLMapViewDelegate.h b/platform/ios/src/MGLMapViewDelegate.h
index 055d4c9517..c6128ae953 100644
--- a/platform/ios/src/MGLMapViewDelegate.h
+++ b/platform/ios/src/MGLMapViewDelegate.h
@@ -1,11 +1,19 @@
#import <UIKit/UIKit.h>
-#import "Mapbox.h"
#import "MGLCameraChangeReason.h"
NS_ASSUME_NONNULL_BEGIN
+@protocol MGLAnnotation;
+@protocol MGLCalloutView;
+@class MGLAnnotationImage;
+@class MGLAnnotationView;
+@class MGLCircle;
+@class MGLMapCamera;
@class MGLMapView;
+@class MGLPolygon;
+@class MGLPolyline;
+@class MGLShape;
/**
The `MGLMapViewDelegate` protocol defines a set of optional methods that you
@@ -422,25 +430,25 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (UIColor *)mapView:(MGLMapView *)mapView strokeColorForShapeAnnotation:(MGLShape *)annotation;
+- (UIColor *)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 map view’s tint color. If a pattern color is
+ 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.
-
- #### Related examples
- See the <a href="https://docs.mapbox.com/ios/maps/examples/polygon/">Add
- a polygon annotation</a> example to learn how to modify the color of a an
- `MGLPolygon` at runtime.
+ @param shape The annotation being rendered.
+ @return The shape’s fill color.
*/
-- (UIColor *)mapView:(MGLMapView *)mapView fillColorForPolygonAnnotation:(MGLPolygon *)annotation;
+- (UIColor *)mapView:(MGLMapView *)mapView fillColorForShape:(MGLShape *)shape;
/**
Returns the line width in points to use when rendering the outline of a
diff --git a/platform/ios/src/Mapbox.h b/platform/ios/src/Mapbox.h
index 635bda490f..b4f5a707e9 100644
--- a/platform/ios/src/Mapbox.h
+++ b/platform/ios/src/Mapbox.h
@@ -34,6 +34,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"