1//
2//  AIRGoogleMapPolygon.m
3//
4//  Created by Nick Italiano on 10/22/16.
5//
6
7#ifdef HAVE_GOOGLE_MAPS
8
9#import "AIRGoogleMapPolygon.h"
10#import "AIRGMSPolygon.h"
11#import <GoogleMaps/GoogleMaps.h>
12
13@implementation AIRGoogleMapPolygon
14{
15  BOOL _didMoveToWindow;
16}
17
18- (instancetype)init
19{
20  if (self = [super init]) {
21    _didMoveToWindow = false;
22    _polygon = [[AIRGMSPolygon alloc] init];
23  }
24
25  return self;
26}
27
28- (void)didMoveToWindow {
29  [super didMoveToWindow];
30  if(_didMoveToWindow) return;
31  _didMoveToWindow = true;
32  if(_fillColor) {
33    _polygon.fillColor = _fillColor;
34  }
35  if(_strokeColor) {
36    _polygon.strokeColor = _strokeColor;
37  }
38  if(_strokeWidth) {
39    _polygon.strokeWidth = _strokeWidth;
40  }
41}
42
43- (void)setCoordinates:(NSArray<AIRMapCoordinate *> *)coordinates
44{
45  _coordinates = coordinates;
46
47  GMSMutablePath *path = [GMSMutablePath path];
48  for(int i = 0; i < coordinates.count; i++)
49  {
50    [path addCoordinate:coordinates[i].coordinate];
51  }
52
53  _polygon.path = path;
54}
55
56- (void)setHoles:(NSArray<NSArray<AIRMapCoordinate *> *> *)holes
57{
58  _holes = holes;
59
60  if (holes.count)
61  {
62    NSMutableArray<GMSMutablePath *> *interiorPolygons = [NSMutableArray array];
63    for(int h = 0; h < holes.count; h++)
64    {
65      GMSMutablePath *path = [GMSMutablePath path];
66      for(int i = 0; i < holes[h].count; i++)
67      {
68        [path addCoordinate:holes[h][i].coordinate];
69      }
70      [interiorPolygons addObject:path];
71    }
72
73    _polygon.holes = interiorPolygons;
74  }
75}
76
77-(void)setFillColor:(UIColor *)fillColor
78{
79  _fillColor = fillColor;
80  if(_didMoveToWindow) {
81    _polygon.fillColor = fillColor;
82  }
83}
84
85-(void)setStrokeWidth:(double)strokeWidth
86{
87  _strokeWidth = strokeWidth;
88  if(_didMoveToWindow) {
89    _polygon.strokeWidth = strokeWidth;
90  }
91}
92
93-(void)setStrokeColor:(UIColor *) strokeColor
94{
95  _strokeColor = strokeColor;
96  if(_didMoveToWindow) {
97    _polygon.strokeColor = strokeColor;
98  }
99}
100
101-(void)setGeodesic:(BOOL)geodesic
102{
103  _geodesic = geodesic;
104  _polygon.geodesic = geodesic;
105}
106
107-(void)setZIndex:(int)zIndex
108{
109  _zIndex = zIndex;
110  _polygon.zIndex = zIndex;
111}
112
113-(void)setTappable:(BOOL)tappable
114{
115  _tappable = tappable;
116  _polygon.tappable = tappable;
117}
118
119- (void)setOnPress:(RCTBubblingEventBlock)onPress {
120  _polygon.onPress = onPress;
121}
122
123@end
124
125#endif
126