@lugg/maps 0.2.0-alpha.9 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +20 -19
  2. package/android/src/main/java/com/luggmaps/LuggMapView.kt +290 -0
  3. package/android/src/main/java/com/luggmaps/{LuggGoogleMapViewManager.kt → LuggMapViewManager.kt} +99 -36
  4. package/android/src/main/java/com/luggmaps/LuggMapWrapperView.kt +13 -5
  5. package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +157 -13
  6. package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +28 -0
  7. package/android/src/main/java/com/luggmaps/LuggPackage.kt +1 -4
  8. package/android/src/main/java/com/luggmaps/LuggPolygonView.kt +85 -0
  9. package/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt +100 -0
  10. package/android/src/main/java/com/luggmaps/LuggPolylineView.kt +16 -0
  11. package/android/src/main/java/com/luggmaps/LuggPolylineViewManager.kt +22 -0
  12. package/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +698 -0
  13. package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +60 -0
  14. package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +89 -24
  15. package/android/src/main/java/com/luggmaps/events/LongPressEvent.kt +29 -0
  16. package/android/src/main/java/com/luggmaps/events/MarkerDragEvent.kt +41 -0
  17. package/android/src/main/java/com/luggmaps/events/MarkerPressEvent.kt +34 -0
  18. package/android/src/main/java/com/luggmaps/events/PolygonPressEvent.kt +12 -0
  19. package/android/src/main/java/com/luggmaps/events/PressEvent.kt +29 -0
  20. package/ios/LuggMapView.h +9 -0
  21. package/ios/LuggMapView.mm +343 -0
  22. package/ios/LuggMarkerView.h +13 -0
  23. package/ios/LuggMarkerView.mm +119 -0
  24. package/ios/LuggPolygonView.h +31 -0
  25. package/ios/LuggPolygonView.mm +151 -0
  26. package/ios/LuggPolylineView.h +4 -0
  27. package/ios/LuggPolylineView.mm +23 -0
  28. package/ios/core/AppleMapProvider.h +15 -0
  29. package/ios/core/AppleMapProvider.mm +1029 -0
  30. package/ios/core/GMSPolylineAnimator.h +3 -0
  31. package/ios/core/GMSPolylineAnimator.m +101 -15
  32. package/ios/core/GoogleMapProvider.h +13 -0
  33. package/ios/core/GoogleMapProvider.mm +689 -0
  34. package/ios/core/MKPolylineAnimator.h +4 -0
  35. package/ios/core/MKPolylineAnimator.m +167 -42
  36. package/ios/core/MapProviderDelegate.h +84 -0
  37. package/ios/core/PolylineAnimatorBase.h +24 -1
  38. package/ios/core/PolylineAnimatorBase.m +82 -19
  39. package/ios/events/LongPressEvent.h +29 -0
  40. package/ios/events/MarkerDragEvent.h +69 -0
  41. package/ios/events/MarkerPressEvent.h +29 -0
  42. package/ios/events/PolygonPressEvent.h +20 -0
  43. package/ios/events/PressEvent.h +29 -0
  44. package/ios/extensions/MKMapView+Zoom.h +2 -0
  45. package/ios/extensions/MKMapView+Zoom.m +14 -4
  46. package/lib/module/MapProvider.js +2 -4
  47. package/lib/module/MapProvider.js.map +1 -1
  48. package/lib/module/MapProvider.web.js +12 -7
  49. package/lib/module/MapProvider.web.js.map +1 -1
  50. package/lib/module/MapView.js +33 -16
  51. package/lib/module/MapView.js.map +1 -1
  52. package/lib/module/MapView.web.js +283 -181
  53. package/lib/module/MapView.web.js.map +1 -1
  54. package/lib/module/components/GeoJson.js +159 -0
  55. package/lib/module/components/GeoJson.js.map +1 -0
  56. package/lib/module/components/GeoJson.types.js +4 -0
  57. package/lib/module/components/GeoJson.types.js.map +1 -0
  58. package/lib/module/components/Marker.js +28 -4
  59. package/lib/module/components/Marker.js.map +1 -1
  60. package/lib/module/components/Marker.types.js +4 -0
  61. package/lib/module/components/Marker.types.js.map +1 -0
  62. package/lib/module/components/Marker.web.js +98 -27
  63. package/lib/module/components/Marker.web.js.map +1 -1
  64. package/lib/module/components/Polygon.js +46 -0
  65. package/lib/module/components/Polygon.js.map +1 -0
  66. package/lib/module/components/Polygon.types.js +4 -0
  67. package/lib/module/components/Polygon.types.js.map +1 -0
  68. package/lib/module/components/Polygon.web.js +87 -0
  69. package/lib/module/components/Polygon.web.js.map +1 -0
  70. package/lib/module/components/Polyline.js +17 -4
  71. package/lib/module/components/Polyline.js.map +1 -1
  72. package/lib/module/components/Polyline.types.js +4 -0
  73. package/lib/module/components/Polyline.types.js.map +1 -0
  74. package/lib/module/components/Polyline.web.js +108 -31
  75. package/lib/module/components/Polyline.web.js.map +1 -1
  76. package/lib/module/components/index.js +4 -2
  77. package/lib/module/components/index.js.map +1 -1
  78. package/lib/module/components/index.web.js +2 -0
  79. package/lib/module/components/index.web.js.map +1 -1
  80. package/lib/module/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +43 -7
  81. package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +49 -1
  82. package/lib/module/fabric/LuggPolygonViewNativeComponent.ts +25 -0
  83. package/lib/module/fabric/LuggPolylineViewNativeComponent.ts +8 -0
  84. package/lib/module/index.js +4 -1
  85. package/lib/module/index.js.map +1 -1
  86. package/lib/module/index.web.js +4 -1
  87. package/lib/module/index.web.js.map +1 -1
  88. package/lib/typescript/src/MapProvider.d.ts +1 -1
  89. package/lib/typescript/src/MapProvider.d.ts.map +1 -1
  90. package/lib/typescript/src/MapProvider.web.d.ts +17 -1
  91. package/lib/typescript/src/MapProvider.web.d.ts.map +1 -1
  92. package/lib/typescript/src/MapView.d.ts +4 -4
  93. package/lib/typescript/src/MapView.d.ts.map +1 -1
  94. package/lib/typescript/src/MapView.types.d.ts +35 -9
  95. package/lib/typescript/src/MapView.types.d.ts.map +1 -1
  96. package/lib/typescript/src/MapView.web.d.ts +2 -11
  97. package/lib/typescript/src/MapView.web.d.ts.map +1 -1
  98. package/lib/typescript/src/components/GeoJson.d.ts +4 -0
  99. package/lib/typescript/src/components/GeoJson.d.ts.map +1 -0
  100. package/lib/typescript/src/components/GeoJson.types.d.ts +79 -0
  101. package/lib/typescript/src/components/GeoJson.types.d.ts.map +1 -0
  102. package/lib/typescript/src/components/Marker.d.ts +6 -33
  103. package/lib/typescript/src/components/Marker.d.ts.map +1 -1
  104. package/lib/typescript/src/components/Marker.types.d.ts +74 -0
  105. package/lib/typescript/src/components/Marker.types.d.ts.map +1 -0
  106. package/lib/typescript/src/components/Marker.web.d.ts +2 -5
  107. package/lib/typescript/src/components/Marker.web.d.ts.map +1 -1
  108. package/lib/typescript/src/components/Polygon.d.ts +10 -0
  109. package/lib/typescript/src/components/Polygon.d.ts.map +1 -0
  110. package/lib/typescript/src/components/Polygon.types.d.ts +33 -0
  111. package/lib/typescript/src/components/Polygon.types.d.ts.map +1 -0
  112. package/lib/typescript/src/components/Polygon.web.d.ts +3 -0
  113. package/lib/typescript/src/components/Polygon.web.d.ts.map +1 -0
  114. package/lib/typescript/src/components/Polyline.d.ts +6 -21
  115. package/lib/typescript/src/components/Polyline.d.ts.map +1 -1
  116. package/lib/typescript/src/components/Polyline.types.d.ts +53 -0
  117. package/lib/typescript/src/components/Polyline.types.d.ts.map +1 -0
  118. package/lib/typescript/src/components/Polyline.web.d.ts +2 -5
  119. package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -1
  120. package/lib/typescript/src/components/index.d.ts +8 -2
  121. package/lib/typescript/src/components/index.d.ts.map +1 -1
  122. package/lib/typescript/src/components/index.web.d.ts +6 -2
  123. package/lib/typescript/src/components/index.web.d.ts.map +1 -1
  124. package/lib/typescript/src/fabric/{LuggGoogleMapViewNativeComponent.d.ts → LuggMapViewNativeComponent.d.ts} +30 -4
  125. package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -0
  126. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts +45 -1
  127. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts.map +1 -1
  128. package/lib/typescript/src/fabric/LuggPolygonViewNativeComponent.d.ts +18 -0
  129. package/lib/typescript/src/fabric/LuggPolygonViewNativeComponent.d.ts.map +1 -0
  130. package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts +7 -0
  131. package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts.map +1 -1
  132. package/lib/typescript/src/index.d.ts +11 -3
  133. package/lib/typescript/src/index.d.ts.map +1 -1
  134. package/lib/typescript/src/index.web.d.ts +9 -1
  135. package/lib/typescript/src/index.web.d.ts.map +1 -1
  136. package/lib/typescript/src/types.d.ts +11 -0
  137. package/lib/typescript/src/types.d.ts.map +1 -1
  138. package/package.json +10 -9
  139. package/src/MapProvider.tsx +1 -3
  140. package/src/MapProvider.web.tsx +12 -3
  141. package/src/MapView.tsx +32 -26
  142. package/src/MapView.types.ts +43 -9
  143. package/src/MapView.web.tsx +345 -211
  144. package/src/components/GeoJson.tsx +221 -0
  145. package/src/components/GeoJson.types.ts +107 -0
  146. package/src/components/Marker.tsx +45 -36
  147. package/src/components/Marker.types.ts +75 -0
  148. package/src/components/Marker.web.tsx +116 -28
  149. package/src/components/Polygon.tsx +52 -0
  150. package/src/components/Polygon.types.ts +33 -0
  151. package/src/components/Polygon.web.tsx +104 -0
  152. package/src/components/Polyline.tsx +23 -22
  153. package/src/components/Polyline.types.ts +55 -0
  154. package/src/components/Polyline.web.tsx +151 -37
  155. package/src/components/index.ts +16 -2
  156. package/src/components/index.web.ts +6 -2
  157. package/src/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +43 -7
  158. package/src/fabric/LuggMarkerViewNativeComponent.ts +49 -1
  159. package/src/fabric/LuggPolygonViewNativeComponent.ts +25 -0
  160. package/src/fabric/LuggPolylineViewNativeComponent.ts +8 -0
  161. package/src/index.ts +28 -1
  162. package/src/index.web.ts +15 -1
  163. package/src/types.ts +13 -0
  164. package/android/src/main/java/com/luggmaps/LuggGoogleMapView.kt +0 -511
  165. package/ios/LuggAppleMapView.h +0 -16
  166. package/ios/LuggAppleMapView.mm +0 -592
  167. package/ios/LuggGoogleMapView.h +0 -13
  168. package/ios/LuggGoogleMapView.mm +0 -455
  169. package/lib/module/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
  170. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts +0 -54
  171. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts.map +0 -1
  172. package/lib/typescript/src/fabric/LuggGoogleMapViewNativeComponent.d.ts.map +0 -1
  173. package/src/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
@@ -0,0 +1,689 @@
1
+ #import "GoogleMapProvider.h"
2
+ #import "../LuggMarkerView.h"
3
+ #import "../LuggPolygonView.h"
4
+ #import "../LuggPolylineView.h"
5
+ #import "GMSPolylineAnimator.h"
6
+ #import "PolylineAnimatorBase.h"
7
+
8
+ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
9
+
10
+ @interface GoogleMapProvider () <
11
+ LuggMarkerViewDelegate, LuggPolylineViewDelegate, LuggPolygonViewDelegate>
12
+ @end
13
+
14
+ @implementation GoogleMapProvider {
15
+ GMSMapView *_mapView;
16
+ BOOL _isMapReady;
17
+ BOOL _isDragging;
18
+ NSInteger _theme;
19
+ UIEdgeInsets _edgeInsets;
20
+ NSMutableArray<LuggMarkerView *> *_pendingMarkerViews;
21
+ NSMutableArray<LuggPolylineView *> *_pendingPolylineViews;
22
+ NSMutableArray<LuggPolygonView *> *_pendingPolygonViews;
23
+ NSMapTable<LuggPolylineView *, GMSPolylineAnimator *> *_polylineAnimators;
24
+ NSMapTable<GMSPolygon *, LuggPolygonView *> *_polygonToViewMap;
25
+ NSMapTable<GMSMarker *, LuggMarkerView *> *_markerToViewMap;
26
+
27
+ // Edge insets animation
28
+ CADisplayLink *_edgeInsetsDisplayLink;
29
+ UIEdgeInsets _edgeInsetsFrom;
30
+ UIEdgeInsets _edgeInsetsTo;
31
+ CFTimeInterval _edgeInsetsAnimationStart;
32
+ CFTimeInterval _edgeInsetsAnimationDuration;
33
+ }
34
+
35
+ @synthesize delegate = _delegate;
36
+
37
+ - (instancetype)init {
38
+ if (self = [super init]) {
39
+ _isMapReady = NO;
40
+ _mapId = kDemoMapId;
41
+ _pendingMarkerViews = [NSMutableArray array];
42
+ _pendingPolylineViews = [NSMutableArray array];
43
+ _pendingPolygonViews = [NSMutableArray array];
44
+ _polylineAnimators = [NSMapTable weakToStrongObjectsMapTable];
45
+ _polygonToViewMap = [NSMapTable strongToWeakObjectsMapTable];
46
+ _markerToViewMap = [NSMapTable strongToWeakObjectsMapTable];
47
+ }
48
+ return self;
49
+ }
50
+
51
+ - (BOOL)isMapReady {
52
+ return _isMapReady;
53
+ }
54
+
55
+ - (GMSMapView *)mapView {
56
+ return _mapView;
57
+ }
58
+
59
+ #pragma mark - MapProvider
60
+
61
+ - (void)initializeMapInView:(UIView *)wrapperView
62
+ initialCoordinate:(CLLocationCoordinate2D)coordinate
63
+ initialZoom:(double)zoom {
64
+ if (_mapView)
65
+ return;
66
+
67
+ GMSMapID *gmsMapId;
68
+ if ([_mapId isEqualToString:kDemoMapId] || _mapId.length == 0) {
69
+ gmsMapId = [GMSMapID demoMapID];
70
+ } else {
71
+ gmsMapId = [GMSMapID mapIDWithIdentifier:_mapId];
72
+ }
73
+
74
+ GMSCameraPosition *camera =
75
+ [GMSCameraPosition cameraWithLatitude:coordinate.latitude
76
+ longitude:coordinate.longitude
77
+ zoom:zoom];
78
+
79
+ GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init];
80
+ options.frame = wrapperView.bounds;
81
+ options.camera = camera;
82
+ options.mapID = gmsMapId;
83
+
84
+ _mapView = [[GMSMapView alloc] initWithOptions:options];
85
+ _mapView.autoresizingMask =
86
+ UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
87
+ _mapView.delegate = self;
88
+ _mapView.paddingAdjustmentBehavior =
89
+ kGMSMapViewPaddingAdjustmentBehaviorNever;
90
+
91
+ [wrapperView addSubview:_mapView];
92
+
93
+ [self applyTheme];
94
+
95
+ _isMapReady = YES;
96
+ [self processPendingMarkers];
97
+ [self processPendingPolylines];
98
+ [self processPendingPolygons];
99
+
100
+ [_delegate mapProviderDidReady];
101
+ }
102
+
103
+ - (void)destroy {
104
+ [self stopEdgeInsetsAnimation];
105
+ [_pendingMarkerViews removeAllObjects];
106
+ [_pendingPolylineViews removeAllObjects];
107
+ [_pendingPolygonViews removeAllObjects];
108
+ [_polylineAnimators removeAllObjects];
109
+ [_polygonToViewMap removeAllObjects];
110
+ [_markerToViewMap removeAllObjects];
111
+ [_mapView clear];
112
+ [_mapView removeFromSuperview];
113
+ _mapView = nil;
114
+ _isMapReady = NO;
115
+ }
116
+
117
+ #pragma mark - Props
118
+
119
+ - (void)setZoomEnabled:(BOOL)enabled {
120
+ _mapView.settings.zoomGestures = enabled;
121
+ }
122
+
123
+ - (void)setScrollEnabled:(BOOL)enabled {
124
+ _mapView.settings.scrollGestures = enabled;
125
+ }
126
+
127
+ - (void)setRotateEnabled:(BOOL)enabled {
128
+ _mapView.settings.rotateGestures = enabled;
129
+ }
130
+
131
+ - (void)setPitchEnabled:(BOOL)enabled {
132
+ _mapView.settings.tiltGestures = enabled;
133
+ }
134
+
135
+ - (void)setUserLocationEnabled:(BOOL)enabled {
136
+ _mapView.myLocationEnabled = enabled;
137
+ }
138
+
139
+ - (void)setTheme:(NSInteger)theme {
140
+ _theme = theme;
141
+ [self applyTheme];
142
+ }
143
+
144
+ - (void)applyTheme {
145
+ if (!_mapView)
146
+ return;
147
+
148
+ switch (_theme) {
149
+ case 1: // Dark
150
+ _mapView.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
151
+ break;
152
+ case 0: // Light
153
+ _mapView.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
154
+ break;
155
+ default: // System
156
+ _mapView.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
157
+ break;
158
+ }
159
+ }
160
+
161
+ - (void)setMinZoom:(double)minZoom {
162
+ if (!_mapView)
163
+ return;
164
+ float min = minZoom > 0 ? (float)minZoom : _mapView.minZoom;
165
+ [_mapView setMinZoom:min maxZoom:_mapView.maxZoom];
166
+ }
167
+
168
+ - (void)setMaxZoom:(double)maxZoom {
169
+ if (!_mapView)
170
+ return;
171
+ float max = maxZoom > 0 ? (float)maxZoom : _mapView.maxZoom;
172
+ [_mapView setMinZoom:_mapView.minZoom maxZoom:max];
173
+ }
174
+
175
+ - (void)setEdgeInsets:(UIEdgeInsets)edgeInsets
176
+ oldEdgeInsets:(UIEdgeInsets)oldEdgeInsets {
177
+ [self setEdgeInsets:edgeInsets oldEdgeInsets:oldEdgeInsets duration:0];
178
+ }
179
+
180
+ - (void)setEdgeInsets:(UIEdgeInsets)edgeInsets
181
+ oldEdgeInsets:(UIEdgeInsets)oldEdgeInsets
182
+ duration:(double)duration {
183
+ if (UIEdgeInsetsEqualToEdgeInsets(_edgeInsets, edgeInsets))
184
+ return;
185
+
186
+ [self stopEdgeInsetsAnimation];
187
+
188
+ if (duration != 0 && _mapView) {
189
+ double actualDuration = duration < 0 ? 0.3 : duration / 1000.0;
190
+ _edgeInsetsFrom = _edgeInsets;
191
+ _edgeInsetsTo = edgeInsets;
192
+ _edgeInsets = edgeInsets;
193
+ _edgeInsetsAnimationDuration = actualDuration;
194
+ _edgeInsetsAnimationStart = CACurrentMediaTime();
195
+
196
+ _edgeInsetsDisplayLink = [CADisplayLink
197
+ displayLinkWithTarget:self
198
+ selector:@selector(edgeInsetsAnimationTick:)];
199
+ [_edgeInsetsDisplayLink addToRunLoop:[NSRunLoop mainRunLoop]
200
+ forMode:NSRunLoopCommonModes];
201
+ } else {
202
+ _edgeInsets = edgeInsets;
203
+ _mapView.padding = edgeInsets;
204
+ }
205
+ }
206
+
207
+ - (void)edgeInsetsAnimationTick:(CADisplayLink *)displayLink {
208
+ CFTimeInterval elapsed = CACurrentMediaTime() - _edgeInsetsAnimationStart;
209
+ CGFloat progress = MIN(elapsed / _edgeInsetsAnimationDuration, 1.0);
210
+
211
+ // Ease out cubic
212
+ CGFloat t = 1.0 - (1.0 - progress) * (1.0 - progress) * (1.0 - progress);
213
+
214
+ UIEdgeInsets current = UIEdgeInsetsMake(
215
+ _edgeInsetsFrom.top + (_edgeInsetsTo.top - _edgeInsetsFrom.top) * t,
216
+ _edgeInsetsFrom.left + (_edgeInsetsTo.left - _edgeInsetsFrom.left) * t,
217
+ _edgeInsetsFrom.bottom +
218
+ (_edgeInsetsTo.bottom - _edgeInsetsFrom.bottom) * t,
219
+ _edgeInsetsFrom.right +
220
+ (_edgeInsetsTo.right - _edgeInsetsFrom.right) * t);
221
+
222
+ _mapView.padding = current;
223
+
224
+ if (progress >= 1.0) {
225
+ [self stopEdgeInsetsAnimation];
226
+ }
227
+ }
228
+
229
+ - (void)stopEdgeInsetsAnimation {
230
+ [_edgeInsetsDisplayLink invalidate];
231
+ _edgeInsetsDisplayLink = nil;
232
+ }
233
+
234
+ #pragma mark - GMSMapViewDelegate
235
+
236
+ - (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture {
237
+ _isDragging = gesture;
238
+ if (_isDragging) {
239
+ for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
240
+ [animator pause];
241
+ }
242
+ }
243
+ }
244
+
245
+ - (void)mapView:(GMSMapView *)mapView
246
+ didChangeCameraPosition:(GMSCameraPosition *)position {
247
+ [_delegate mapProviderDidMoveCamera:position.target.latitude
248
+ longitude:position.target.longitude
249
+ zoom:position.zoom
250
+ gesture:_isDragging];
251
+ }
252
+
253
+ - (void)mapView:(GMSMapView *)mapView
254
+ idleAtCameraPosition:(GMSCameraPosition *)position {
255
+ BOOL wasDragging = _isDragging;
256
+ _isDragging = NO;
257
+ if (wasDragging) {
258
+ for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
259
+ [animator resume];
260
+ }
261
+ }
262
+ [_delegate mapProviderDidIdleCamera:position.target.latitude
263
+ longitude:position.target.longitude
264
+ zoom:position.zoom
265
+ gesture:wasDragging];
266
+ }
267
+
268
+ - (void)mapView:(GMSMapView *)mapView
269
+ didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
270
+ CGPoint point = [mapView.projection pointForCoordinate:coordinate];
271
+ [_delegate mapProviderDidPress:coordinate.latitude
272
+ longitude:coordinate.longitude
273
+ x:point.x
274
+ y:point.y];
275
+ }
276
+
277
+ - (void)mapView:(GMSMapView *)mapView
278
+ didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate {
279
+ CGPoint point = [mapView.projection pointForCoordinate:coordinate];
280
+ [_delegate mapProviderDidLongPress:coordinate.latitude
281
+ longitude:coordinate.longitude
282
+ x:point.x
283
+ y:point.y];
284
+ }
285
+
286
+ - (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay {
287
+ if (![overlay isKindOfClass:[GMSPolygon class]])
288
+ return;
289
+
290
+ GMSPolygon *polygon = (GMSPolygon *)overlay;
291
+ LuggPolygonView *polygonView = [_polygonToViewMap objectForKey:polygon];
292
+ if (!polygonView || !polygonView.tappable)
293
+ return;
294
+
295
+ [polygonView emitPressEvent];
296
+ }
297
+
298
+ - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
299
+ LuggMarkerView *markerView = [_markerToViewMap objectForKey:marker];
300
+ if (markerView) {
301
+ CGPoint point = [_mapView.projection pointForCoordinate:marker.position];
302
+ [markerView emitPressEventWithPoint:point];
303
+ }
304
+ return NO;
305
+ }
306
+
307
+ - (void)mapView:(GMSMapView *)mapView
308
+ didBeginDraggingMarker:(GMSMarker *)marker {
309
+ LuggMarkerView *markerView = [_markerToViewMap objectForKey:marker];
310
+ if (markerView) {
311
+ [markerView updateCoordinate:marker.position];
312
+ CGPoint point = [_mapView.projection pointForCoordinate:marker.position];
313
+ [markerView emitDragStartEventWithPoint:point];
314
+ }
315
+ }
316
+
317
+ - (void)mapView:(GMSMapView *)mapView didDragMarker:(GMSMarker *)marker {
318
+ LuggMarkerView *markerView = [_markerToViewMap objectForKey:marker];
319
+ if (markerView) {
320
+ [markerView updateCoordinate:marker.position];
321
+ CGPoint point = [_mapView.projection pointForCoordinate:marker.position];
322
+ [markerView emitDragChangeEventWithPoint:point];
323
+ }
324
+ }
325
+
326
+ - (void)mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker {
327
+ LuggMarkerView *markerView = [_markerToViewMap objectForKey:marker];
328
+ if (markerView) {
329
+ [markerView updateCoordinate:marker.position];
330
+ CGPoint point = [_mapView.projection pointForCoordinate:marker.position];
331
+ [markerView emitDragEndEventWithPoint:point];
332
+ }
333
+ }
334
+
335
+ #pragma mark - MarkerViewDelegate
336
+
337
+ - (void)markerViewDidLayout:(LuggMarkerView *)markerView {
338
+ [self syncMarkerView:markerView];
339
+ }
340
+
341
+ - (void)markerViewDidUpdate:(LuggMarkerView *)markerView {
342
+ [self syncMarkerView:markerView];
343
+ }
344
+
345
+ #pragma mark - PolylineViewDelegate
346
+
347
+ - (void)polylineViewDidUpdate:(LuggPolylineView *)polylineView {
348
+ [self syncPolylineView:polylineView];
349
+ }
350
+
351
+ #pragma mark - PolygonViewDelegate
352
+
353
+ - (void)polygonViewDidUpdate:(LuggPolygonView *)polygonView {
354
+ [self syncPolygonView:polygonView];
355
+ }
356
+
357
+ #pragma mark - Marker Management
358
+
359
+ - (void)addMarkerView:(LuggMarkerView *)markerView {
360
+ markerView.delegate = self;
361
+ [self syncMarkerView:markerView];
362
+ }
363
+
364
+ - (void)removeMarkerView:(LuggMarkerView *)markerView {
365
+ GMSAdvancedMarker *marker = (GMSAdvancedMarker *)markerView.marker;
366
+ if (marker) {
367
+ [_markerToViewMap removeObjectForKey:marker];
368
+ marker.iconView = nil;
369
+ marker.map = nil;
370
+ markerView.marker = nil;
371
+ }
372
+ [markerView resetIconViewTransform];
373
+ }
374
+
375
+ - (void)syncMarkerView:(LuggMarkerView *)markerView {
376
+ if (!_mapView) {
377
+ if (![_pendingMarkerViews containsObject:markerView]) {
378
+ [_pendingMarkerViews addObject:markerView];
379
+ }
380
+ return;
381
+ }
382
+
383
+ if (!markerView.marker) {
384
+ [self addMarkerViewToMap:markerView];
385
+ return;
386
+ }
387
+
388
+ GMSAdvancedMarker *marker = (GMSAdvancedMarker *)markerView.marker;
389
+ marker.position = markerView.coordinate;
390
+ marker.title = markerView.title;
391
+ marker.snippet = markerView.markerDescription;
392
+ marker.zIndex = (int)markerView.zIndex;
393
+ marker.draggable = markerView.draggable;
394
+ [self applyMarkerStyle:markerView marker:marker];
395
+ }
396
+
397
+ - (void)processPendingMarkers {
398
+ if (!_mapView)
399
+ return;
400
+
401
+ for (LuggMarkerView *markerView in _pendingMarkerViews) {
402
+ [self addMarkerViewToMap:markerView];
403
+ }
404
+ [_pendingMarkerViews removeAllObjects];
405
+ }
406
+
407
+ - (void)addMarkerViewToMap:(LuggMarkerView *)markerView {
408
+ if (!_mapView)
409
+ return;
410
+
411
+ GMSAdvancedMarker *marker = [[GMSAdvancedMarker alloc] init];
412
+ marker.position = markerView.coordinate;
413
+ marker.title = markerView.title;
414
+ marker.snippet = markerView.markerDescription;
415
+ marker.zIndex = (int)markerView.zIndex;
416
+ marker.draggable = markerView.draggable;
417
+
418
+ [self applyMarkerStyle:markerView marker:marker];
419
+
420
+ marker.map = _mapView;
421
+ markerView.marker = marker;
422
+ [_markerToViewMap setObject:markerView forKey:marker];
423
+ }
424
+
425
+ - (void)applyMarkerStyle:(LuggMarkerView *)markerView
426
+ marker:(GMSAdvancedMarker *)marker {
427
+ if (markerView.hasCustomView) {
428
+ if (markerView.rasterize) {
429
+ marker.iconView = nil;
430
+ marker.icon = [markerView createScaledIconImage];
431
+ marker.rotation = markerView.rotate;
432
+ } else {
433
+ UIView *iconView = markerView.iconView;
434
+ if (marker.iconView != iconView) {
435
+ [iconView removeFromSuperview];
436
+ marker.iconView = iconView;
437
+ }
438
+ CGFloat scale = markerView.scale;
439
+ CGFloat radians = markerView.rotate * M_PI / 180.0;
440
+ iconView.transform =
441
+ CGAffineTransformConcat(CGAffineTransformMakeScale(scale, scale),
442
+ CGAffineTransformMakeRotation(radians));
443
+ marker.rotation = 0;
444
+ }
445
+ marker.groundAnchor = markerView.anchor;
446
+ } else {
447
+ marker.iconView = nil;
448
+ marker.icon = nil;
449
+ marker.rotation = markerView.rotate;
450
+ marker.groundAnchor = CGPointMake(0.5, 1);
451
+ }
452
+ }
453
+
454
+ #pragma mark - Polyline Management
455
+
456
+ - (void)addPolylineView:(LuggPolylineView *)polylineView {
457
+ polylineView.delegate = self;
458
+ [self syncPolylineView:polylineView];
459
+ }
460
+
461
+ - (void)removePolylineView:(LuggPolylineView *)polylineView {
462
+ [_polylineAnimators removeObjectForKey:polylineView];
463
+ GMSPolyline *polyline = (GMSPolyline *)polylineView.polyline;
464
+ if (polyline) {
465
+ polyline.map = nil;
466
+ polylineView.polyline = nil;
467
+ }
468
+ }
469
+
470
+ - (void)syncPolylineView:(LuggPolylineView *)polylineView {
471
+ if (!_mapView) {
472
+ if (![_pendingPolylineViews containsObject:polylineView]) {
473
+ [_pendingPolylineViews addObject:polylineView];
474
+ }
475
+ return;
476
+ }
477
+
478
+ if (!polylineView.polyline) {
479
+ [self addPolylineViewToMap:polylineView];
480
+ return;
481
+ }
482
+
483
+ GMSPolyline *polyline = (GMSPolyline *)polylineView.polyline;
484
+ polyline.strokeWidth = polylineView.strokeWidth;
485
+ polyline.zIndex = (int)polylineView.zIndex;
486
+
487
+ GMSPolylineAnimator *animator =
488
+ [_polylineAnimators objectForKey:polylineView];
489
+ if (animator) {
490
+ animator.coordinates = polylineView.coordinates;
491
+ animator.strokeColors = polylineView.strokeColors;
492
+ animator.animatedOptions = polylineView.animatedOptions;
493
+ animator.animated = polylineView.animated;
494
+ [animator update];
495
+ }
496
+ }
497
+
498
+ - (void)processPendingPolylines {
499
+ if (!_mapView)
500
+ return;
501
+
502
+ for (LuggPolylineView *polylineView in _pendingPolylineViews) {
503
+ [self addPolylineViewToMap:polylineView];
504
+ }
505
+ [_pendingPolylineViews removeAllObjects];
506
+ }
507
+
508
+ - (void)addPolylineViewToMap:(LuggPolylineView *)polylineView {
509
+ if (!_mapView)
510
+ return;
511
+
512
+ GMSPolyline *polyline = [GMSPolyline polylineWithPath:[GMSMutablePath path]];
513
+ polyline.strokeWidth = polylineView.strokeWidth;
514
+ polyline.zIndex = (int)polylineView.zIndex;
515
+ polyline.map = _mapView;
516
+ polylineView.polyline = polyline;
517
+
518
+ GMSPolylineAnimator *animator = [[GMSPolylineAnimator alloc] init];
519
+ animator.polyline = polyline;
520
+ animator.coordinates = polylineView.coordinates;
521
+ animator.strokeColors = polylineView.strokeColors;
522
+ animator.animatedOptions = polylineView.animatedOptions;
523
+ animator.animated = polylineView.animated;
524
+ [animator update];
525
+
526
+ [_polylineAnimators setObject:animator forKey:polylineView];
527
+ }
528
+
529
+ #pragma mark - Polygon Management
530
+
531
+ - (void)addPolygonView:(LuggPolygonView *)polygonView {
532
+ polygonView.delegate = self;
533
+ [self syncPolygonView:polygonView];
534
+ }
535
+
536
+ - (void)removePolygonView:(LuggPolygonView *)polygonView {
537
+ GMSPolygon *polygon = (GMSPolygon *)polygonView.polygon;
538
+ if (polygon) {
539
+ [_polygonToViewMap removeObjectForKey:polygon];
540
+ polygon.map = nil;
541
+ polygonView.polygon = nil;
542
+ }
543
+ }
544
+
545
+ - (void)syncPolygonView:(LuggPolygonView *)polygonView {
546
+ if (!_mapView) {
547
+ if (![_pendingPolygonViews containsObject:polygonView]) {
548
+ [_pendingPolygonViews addObject:polygonView];
549
+ }
550
+ return;
551
+ }
552
+
553
+ if (!polygonView.polygon) {
554
+ [self addPolygonViewToMap:polygonView];
555
+ return;
556
+ }
557
+
558
+ GMSPolygon *polygon = (GMSPolygon *)polygonView.polygon;
559
+
560
+ GMSMutablePath *path = [GMSMutablePath path];
561
+ for (CLLocation *location in polygonView.coordinates) {
562
+ [path addCoordinate:location.coordinate];
563
+ }
564
+ polygon.path = path;
565
+ polygon.holes = [self holesPathsFromPolygonView:polygonView];
566
+ polygon.fillColor = polygonView.fillColor;
567
+ polygon.strokeColor = polygonView.strokeColor;
568
+ polygon.strokeWidth = polygonView.strokeWidth;
569
+ polygon.zIndex = (int)polygonView.zIndex;
570
+ polygon.tappable = polygonView.tappable;
571
+ }
572
+
573
+ - (NSArray<GMSPath *> *)holesPathsFromPolygonView:
574
+ (LuggPolygonView *)polygonView {
575
+ NSMutableArray<GMSPath *> *holePaths = [NSMutableArray array];
576
+ for (NSArray<CLLocation *> *hole in polygonView.holes) {
577
+ GMSMutablePath *holePath = [GMSMutablePath path];
578
+ for (CLLocation *location in hole) {
579
+ [holePath addCoordinate:location.coordinate];
580
+ }
581
+ [holePaths addObject:holePath];
582
+ }
583
+ return [holePaths copy];
584
+ }
585
+
586
+ - (void)processPendingPolygons {
587
+ if (!_mapView)
588
+ return;
589
+
590
+ for (LuggPolygonView *polygonView in _pendingPolygonViews) {
591
+ [self addPolygonViewToMap:polygonView];
592
+ }
593
+ [_pendingPolygonViews removeAllObjects];
594
+ }
595
+
596
+ - (void)addPolygonViewToMap:(LuggPolygonView *)polygonView {
597
+ if (!_mapView)
598
+ return;
599
+
600
+ GMSMutablePath *path = [GMSMutablePath path];
601
+ for (CLLocation *location in polygonView.coordinates) {
602
+ [path addCoordinate:location.coordinate];
603
+ }
604
+
605
+ GMSPolygon *polygon = [GMSPolygon polygonWithPath:path];
606
+ polygon.holes = [self holesPathsFromPolygonView:polygonView];
607
+ polygon.fillColor = polygonView.fillColor;
608
+ polygon.strokeColor = polygonView.strokeColor;
609
+ polygon.strokeWidth = polygonView.strokeWidth;
610
+ polygon.zIndex = (int)polygonView.zIndex;
611
+ polygon.tappable = polygonView.tappable;
612
+ polygon.map = _mapView;
613
+ polygonView.polygon = polygon;
614
+ [_polygonToViewMap setObject:polygonView forKey:polygon];
615
+ }
616
+
617
+ #pragma mark - Lifecycle
618
+
619
+ - (void)pauseAnimations {
620
+ for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
621
+ [animator pause];
622
+ }
623
+ }
624
+
625
+ - (void)resumeAnimations {
626
+ for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
627
+ [animator resume];
628
+ }
629
+ }
630
+
631
+ #pragma mark - Commands
632
+
633
+ - (void)moveCamera:(double)latitude
634
+ longitude:(double)longitude
635
+ zoom:(double)zoom
636
+ duration:(double)duration {
637
+ if (!_mapView)
638
+ return;
639
+
640
+ float targetZoom = zoom > 0 ? (float)zoom : _mapView.camera.zoom;
641
+ GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
642
+ longitude:longitude
643
+ zoom:targetZoom];
644
+ if (duration < 0) {
645
+ [_mapView animateToCameraPosition:camera];
646
+ } else if (duration > 0) {
647
+ [CATransaction begin];
648
+ [CATransaction setAnimationDuration:duration / 1000.0];
649
+ [_mapView animateToCameraPosition:camera];
650
+ [CATransaction commit];
651
+ } else {
652
+ [_mapView setCamera:camera];
653
+ }
654
+ }
655
+
656
+ - (void)fitCoordinates:(NSArray *)coordinates
657
+ edgeInsetsTop:(double)edgeInsetsTop
658
+ edgeInsetsLeft:(double)edgeInsetsLeft
659
+ edgeInsetsBottom:(double)edgeInsetsBottom
660
+ edgeInsetsRight:(double)edgeInsetsRight
661
+ duration:(double)duration {
662
+ if (!_mapView || coordinates.count == 0)
663
+ return;
664
+
665
+ GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] init];
666
+ for (NSDictionary *coord in coordinates) {
667
+ double lat = [coord[@"latitude"] doubleValue];
668
+ double lng = [coord[@"longitude"] doubleValue];
669
+ bounds = [bounds includingCoordinate:CLLocationCoordinate2DMake(lat, lng)];
670
+ }
671
+
672
+ UIEdgeInsets insets = UIEdgeInsetsMake(edgeInsetsTop, edgeInsetsLeft,
673
+ edgeInsetsBottom, edgeInsetsRight);
674
+ GMSCameraUpdate *cameraUpdate = [GMSCameraUpdate fitBounds:bounds
675
+ withEdgeInsets:insets];
676
+
677
+ if (duration < 0) {
678
+ [_mapView animateWithCameraUpdate:cameraUpdate];
679
+ } else if (duration > 0) {
680
+ [CATransaction begin];
681
+ [CATransaction setAnimationDuration:duration / 1000.0];
682
+ [_mapView animateWithCameraUpdate:cameraUpdate];
683
+ [CATransaction commit];
684
+ } else {
685
+ [_mapView moveCamera:cameraUpdate];
686
+ }
687
+ }
688
+
689
+ @end
@@ -1,3 +1,4 @@
1
+ #import "PolylineAnimatorBase.h"
1
2
  #import <MapKit/MapKit.h>
2
3
 
3
4
  @interface MKPolylineAnimator : MKOverlayPathRenderer
@@ -6,7 +7,10 @@
6
7
 
7
8
  @property(nonatomic, strong) NSArray<UIColor *> *strokeColors;
8
9
  @property(nonatomic, assign) BOOL animated;
10
+ @property(nonatomic, strong) PolylineAnimatedOptions *animatedOptions;
9
11
 
10
12
  - (void)updatePolyline:(MKPolyline *)polyline;
13
+ - (void)pause;
14
+ - (void)resume;
11
15
 
12
16
  @end