@lugg/maps 0.2.0-alpha.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 (114) hide show
  1. package/LICENSE +20 -0
  2. package/LuggMaps.podspec +23 -0
  3. package/README.md +119 -0
  4. package/android/build.gradle +78 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/luggmaps/LuggMapsGoogleMapView.kt +438 -0
  8. package/android/src/main/java/com/luggmaps/LuggMapsGoogleMapViewManager.kt +144 -0
  9. package/android/src/main/java/com/luggmaps/LuggMapsMarkerView.kt +134 -0
  10. package/android/src/main/java/com/luggmaps/LuggMapsMarkerViewManager.kt +69 -0
  11. package/android/src/main/java/com/luggmaps/LuggMapsPackage.kt +13 -0
  12. package/android/src/main/java/com/luggmaps/LuggMapsPolylineView.kt +79 -0
  13. package/android/src/main/java/com/luggmaps/LuggMapsPolylineViewManager.kt +71 -0
  14. package/android/src/main/java/com/luggmaps/LuggMapsWrapperView.kt +39 -0
  15. package/android/src/main/java/com/luggmaps/LuggMapsWrapperViewManager.kt +25 -0
  16. package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +180 -0
  17. package/android/src/main/java/com/luggmaps/events/CameraIdleEvent.kt +21 -0
  18. package/android/src/main/java/com/luggmaps/events/CameraMoveEvent.kt +28 -0
  19. package/app.plugin.js +1 -0
  20. package/ios/LuggMapsAppleMapView.h +16 -0
  21. package/ios/LuggMapsAppleMapView.mm +544 -0
  22. package/ios/LuggMapsGoogleMapView.h +13 -0
  23. package/ios/LuggMapsGoogleMapView.mm +439 -0
  24. package/ios/LuggMapsMarkerView.h +29 -0
  25. package/ios/LuggMapsMarkerView.mm +154 -0
  26. package/ios/LuggMapsPolylineView.h +27 -0
  27. package/ios/LuggMapsPolylineView.mm +116 -0
  28. package/ios/LuggMapsWrapperView.h +9 -0
  29. package/ios/LuggMapsWrapperView.mm +36 -0
  30. package/ios/core/GMSPolylineAnimator.h +11 -0
  31. package/ios/core/GMSPolylineAnimator.m +151 -0
  32. package/ios/core/MKPolylineAnimator.h +12 -0
  33. package/ios/core/MKPolylineAnimator.m +252 -0
  34. package/ios/core/PolylineAnimatorBase.h +22 -0
  35. package/ios/core/PolylineAnimatorBase.m +35 -0
  36. package/ios/events/CameraIdleEvent.h +24 -0
  37. package/ios/events/CameraMoveEvent.h +26 -0
  38. package/ios/extensions/MKMapView+Zoom.h +19 -0
  39. package/ios/extensions/MKMapView+Zoom.m +45 -0
  40. package/lib/module/MapView.js +87 -0
  41. package/lib/module/MapView.js.map +1 -0
  42. package/lib/module/MapView.types.js +4 -0
  43. package/lib/module/MapView.types.js.map +1 -0
  44. package/lib/module/Marker.js +34 -0
  45. package/lib/module/Marker.js.map +1 -0
  46. package/lib/module/Marker.types.js +4 -0
  47. package/lib/module/Marker.types.js.map +1 -0
  48. package/lib/module/Polyline.js +30 -0
  49. package/lib/module/Polyline.js.map +1 -0
  50. package/lib/module/Polyline.types.js +4 -0
  51. package/lib/module/Polyline.types.js.map +1 -0
  52. package/lib/module/fabric/LuggMapsAppleMapViewNativeComponent.ts +73 -0
  53. package/lib/module/fabric/LuggMapsGoogleMapViewNativeComponent.ts +74 -0
  54. package/lib/module/fabric/LuggMapsMarkerViewNativeComponent.ts +25 -0
  55. package/lib/module/fabric/LuggMapsPolylineViewNativeComponent.ts +19 -0
  56. package/lib/module/fabric/LuggMapsWrapperViewNativeComponent.ts +8 -0
  57. package/lib/module/index.js +6 -0
  58. package/lib/module/index.js.map +1 -0
  59. package/lib/module/package.json +1 -0
  60. package/lib/module/types.js +2 -0
  61. package/lib/module/types.js.map +1 -0
  62. package/lib/typescript/package.json +1 -0
  63. package/lib/typescript/plugin/src/index.d.ts +16 -0
  64. package/lib/typescript/plugin/src/index.d.ts.map +1 -0
  65. package/lib/typescript/plugin/src/withMapsAndroid.d.ts +6 -0
  66. package/lib/typescript/plugin/src/withMapsAndroid.d.ts.map +1 -0
  67. package/lib/typescript/plugin/src/withMapsIOS.d.ts +6 -0
  68. package/lib/typescript/plugin/src/withMapsIOS.d.ts.map +1 -0
  69. package/lib/typescript/src/MapView.d.ts +12 -0
  70. package/lib/typescript/src/MapView.d.ts.map +1 -0
  71. package/lib/typescript/src/MapView.types.d.ts +102 -0
  72. package/lib/typescript/src/MapView.types.d.ts.map +1 -0
  73. package/lib/typescript/src/Marker.d.ts +6 -0
  74. package/lib/typescript/src/Marker.d.ts.map +1 -0
  75. package/lib/typescript/src/Marker.types.d.ts +32 -0
  76. package/lib/typescript/src/Marker.types.d.ts.map +1 -0
  77. package/lib/typescript/src/Polyline.d.ts +6 -0
  78. package/lib/typescript/src/Polyline.d.ts.map +1 -0
  79. package/lib/typescript/src/Polyline.types.d.ts +24 -0
  80. package/lib/typescript/src/Polyline.types.d.ts.map +1 -0
  81. package/lib/typescript/src/fabric/LuggMapsAppleMapViewNativeComponent.d.ts +47 -0
  82. package/lib/typescript/src/fabric/LuggMapsAppleMapViewNativeComponent.d.ts.map +1 -0
  83. package/lib/typescript/src/fabric/LuggMapsGoogleMapViewNativeComponent.d.ts +48 -0
  84. package/lib/typescript/src/fabric/LuggMapsGoogleMapViewNativeComponent.d.ts.map +1 -0
  85. package/lib/typescript/src/fabric/LuggMapsMarkerViewNativeComponent.d.ts +20 -0
  86. package/lib/typescript/src/fabric/LuggMapsMarkerViewNativeComponent.d.ts.map +1 -0
  87. package/lib/typescript/src/fabric/LuggMapsPolylineViewNativeComponent.d.ts +15 -0
  88. package/lib/typescript/src/fabric/LuggMapsPolylineViewNativeComponent.d.ts.map +1 -0
  89. package/lib/typescript/src/fabric/LuggMapsWrapperViewNativeComponent.d.ts +6 -0
  90. package/lib/typescript/src/fabric/LuggMapsWrapperViewNativeComponent.d.ts.map +1 -0
  91. package/lib/typescript/src/index.d.ts +8 -0
  92. package/lib/typescript/src/index.d.ts.map +1 -0
  93. package/lib/typescript/src/types.d.ts +28 -0
  94. package/lib/typescript/src/types.d.ts.map +1 -0
  95. package/package.json +200 -0
  96. package/plugin/build/index.d.ts +15 -0
  97. package/plugin/build/index.js +13 -0
  98. package/plugin/build/withMapsAndroid.d.ts +5 -0
  99. package/plugin/build/withMapsAndroid.js +15 -0
  100. package/plugin/build/withMapsIOS.d.ts +5 -0
  101. package/plugin/build/withMapsIOS.js +27 -0
  102. package/src/MapView.tsx +111 -0
  103. package/src/MapView.types.ts +110 -0
  104. package/src/Marker.tsx +31 -0
  105. package/src/Marker.types.ts +32 -0
  106. package/src/Polyline.tsx +32 -0
  107. package/src/Polyline.types.ts +24 -0
  108. package/src/fabric/LuggMapsAppleMapViewNativeComponent.ts +73 -0
  109. package/src/fabric/LuggMapsGoogleMapViewNativeComponent.ts +74 -0
  110. package/src/fabric/LuggMapsMarkerViewNativeComponent.ts +25 -0
  111. package/src/fabric/LuggMapsPolylineViewNativeComponent.ts +19 -0
  112. package/src/fabric/LuggMapsWrapperViewNativeComponent.ts +8 -0
  113. package/src/index.ts +13 -0
  114. package/src/types.ts +30 -0
@@ -0,0 +1,544 @@
1
+ #import "LuggMapsAppleMapView.h"
2
+ #import "LuggMapsMarkerView.h"
3
+ #import "LuggMapsPolylineView.h"
4
+ #import "LuggMapsWrapperView.h"
5
+ #import "core/MKPolylineAnimator.h"
6
+ #import "events/CameraIdleEvent.h"
7
+ #import "events/CameraMoveEvent.h"
8
+ #import "extensions/MKMapView+Zoom.h"
9
+
10
+ #import <react/renderer/components/RNMapsSpec/ComponentDescriptors.h>
11
+ #import <react/renderer/components/RNMapsSpec/EventEmitters.h>
12
+ #import <react/renderer/components/RNMapsSpec/Props.h>
13
+ #import <react/renderer/components/RNMapsSpec/RCTComponentViewHelpers.h>
14
+
15
+ #import "RCTFabricComponentsPlugins.h"
16
+
17
+ using namespace facebook::react;
18
+ using namespace luggmaps::events;
19
+
20
+ @interface AppleMarkerAnnotation : NSObject <MKAnnotation>
21
+ @property(nonatomic, assign) CLLocationCoordinate2D coordinate;
22
+ @property(nonatomic, copy, nullable) NSString *title;
23
+ @property(nonatomic, copy, nullable) NSString *subtitle;
24
+ @property(nonatomic, strong) LuggMapsMarkerView *markerView;
25
+ @property(nonatomic, weak) MKAnnotationView *annotationView;
26
+ @end
27
+
28
+ @implementation AppleMarkerAnnotation
29
+ @end
30
+
31
+ @implementation LuggMapsAppleMapViewContent
32
+ @end
33
+
34
+ @interface LuggMapsAppleMapView () <
35
+ RCTLuggMapsAppleMapViewViewProtocol, MKMapViewDelegate,
36
+ LuggMapsMarkerViewDelegate, LuggMapsPolylineViewDelegate>
37
+ @end
38
+
39
+ @implementation LuggMapsAppleMapView {
40
+ LuggMapsAppleMapViewContent *_mapView;
41
+ LuggMapsWrapperView *_mapWrapperView;
42
+ BOOL _isDragging;
43
+ }
44
+
45
+ + (ComponentDescriptorProvider)componentDescriptorProvider {
46
+ return concreteComponentDescriptorProvider<
47
+ LuggMapsAppleMapViewComponentDescriptor>();
48
+ }
49
+
50
+ - (instancetype)initWithFrame:(CGRect)frame {
51
+ if (self = [super initWithFrame:frame]) {
52
+ static const auto defaultProps =
53
+ std::make_shared<const LuggMapsAppleMapViewProps>();
54
+ _props = defaultProps;
55
+ }
56
+
57
+ return self;
58
+ }
59
+
60
+ #pragma mark - View Lifecycle
61
+
62
+ - (void)mountChildComponentView:
63
+ (UIView<RCTComponentViewProtocol> *)childComponentView
64
+ index:(NSInteger)index {
65
+ [super mountChildComponentView:childComponentView index:index];
66
+
67
+ if ([childComponentView isKindOfClass:[LuggMapsWrapperView class]]) {
68
+ _mapWrapperView = (LuggMapsWrapperView *)childComponentView;
69
+ } else if ([childComponentView isKindOfClass:[LuggMapsMarkerView class]]) {
70
+ LuggMapsMarkerView *markerView = (LuggMapsMarkerView *)childComponentView;
71
+ markerView.delegate = self;
72
+
73
+ AppleMarkerAnnotation *annotation = [[AppleMarkerAnnotation alloc] init];
74
+ annotation.markerView = markerView;
75
+ markerView.marker = annotation;
76
+
77
+ if (_mapView) {
78
+ [_mapView addAnnotation:annotation];
79
+ }
80
+
81
+ [self markerViewDidUpdate:markerView];
82
+ } else if ([childComponentView isKindOfClass:[LuggMapsPolylineView class]]) {
83
+ LuggMapsPolylineView *polylineView =
84
+ (LuggMapsPolylineView *)childComponentView;
85
+ polylineView.delegate = self;
86
+ [self addPolylineViewToMap:polylineView];
87
+ }
88
+ }
89
+
90
+ - (void)unmountChildComponentView:
91
+ (UIView<RCTComponentViewProtocol> *)childComponentView
92
+ index:(NSInteger)index {
93
+ if ([childComponentView isKindOfClass:[LuggMapsMarkerView class]]) {
94
+ LuggMapsMarkerView *markerView = (LuggMapsMarkerView *)childComponentView;
95
+ markerView.delegate = nil;
96
+
97
+ AppleMarkerAnnotation *annotation =
98
+ (AppleMarkerAnnotation *)markerView.marker;
99
+
100
+ if (annotation) {
101
+ annotation.markerView = nil;
102
+ annotation.annotationView = nil;
103
+ [_mapView removeAnnotation:annotation];
104
+ markerView.marker = nil;
105
+ }
106
+ } else if ([childComponentView isKindOfClass:[LuggMapsPolylineView class]]) {
107
+ LuggMapsPolylineView *polylineView =
108
+ (LuggMapsPolylineView *)childComponentView;
109
+ polylineView.delegate = nil;
110
+ MKPolyline *polyline = (MKPolyline *)polylineView.polyline;
111
+ if (polyline) {
112
+ [_mapView removeOverlay:polyline];
113
+ polylineView.polyline = nil;
114
+ }
115
+ }
116
+
117
+ [super unmountChildComponentView:childComponentView index:index];
118
+ }
119
+
120
+ - (void)didMoveToWindow {
121
+ [super didMoveToWindow];
122
+ if (self.window && !_mapView && _mapWrapperView) {
123
+ [self initializeMap];
124
+ }
125
+ }
126
+
127
+ - (void)prepareForRecycle {
128
+ [super prepareForRecycle];
129
+
130
+ [_mapView removeFromSuperview];
131
+ _mapView = nil;
132
+ _mapWrapperView = nil;
133
+ }
134
+
135
+ #pragma mark - Map Initialization
136
+
137
+ - (void)initializeMap {
138
+ if (_mapView || !_mapWrapperView) {
139
+ return;
140
+ }
141
+
142
+ const auto &viewProps =
143
+ *std::static_pointer_cast<LuggMapsAppleMapViewProps const>(_props);
144
+
145
+ _mapView = [[LuggMapsAppleMapViewContent alloc]
146
+ initWithFrame:_mapWrapperView.bounds];
147
+ _mapView.autoresizingMask =
148
+ UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
149
+ _mapView.delegate = self;
150
+ _mapView.insetsLayoutMarginsFromSafeArea = NO;
151
+ _mapView.zoomEnabled = viewProps.zoomEnabled;
152
+ _mapView.scrollEnabled = viewProps.scrollEnabled;
153
+ _mapView.rotateEnabled = viewProps.rotateEnabled;
154
+ _mapView.pitchEnabled = viewProps.pitchEnabled;
155
+
156
+ [_mapWrapperView addSubview:_mapView];
157
+
158
+ [self setCameraWithLatitude:viewProps.initialCoordinate.latitude
159
+ longitude:viewProps.initialCoordinate.longitude
160
+ zoom:viewProps.initialZoom
161
+ animated:NO];
162
+
163
+ // Add annotations for any markers that were mounted before map was ready
164
+ for (UIView *subview in self.subviews) {
165
+ if ([subview isKindOfClass:[LuggMapsMarkerView class]]) {
166
+ LuggMapsMarkerView *markerView = (LuggMapsMarkerView *)subview;
167
+ AppleMarkerAnnotation *annotation =
168
+ (AppleMarkerAnnotation *)markerView.marker;
169
+ if (annotation) {
170
+ [_mapView addAnnotation:annotation];
171
+ }
172
+ } else if ([subview isKindOfClass:[LuggMapsPolylineView class]]) {
173
+ LuggMapsPolylineView *polylineView = (LuggMapsPolylineView *)subview;
174
+ [self addPolylineViewToMap:polylineView];
175
+ }
176
+ }
177
+ }
178
+
179
+ - (void)setCameraWithLatitude:(double)latitude
180
+ longitude:(double)longitude
181
+ zoom:(double)zoom
182
+ animated:(BOOL)animated {
183
+ CLLocationCoordinate2D center =
184
+ CLLocationCoordinate2DMake(latitude, longitude);
185
+ [_mapView setCenterCoordinate:center zoomLevel:zoom animated:animated];
186
+ }
187
+
188
+ - (MKMapView *)mapView {
189
+ return _mapView;
190
+ }
191
+
192
+ #pragma mark - Property Setters
193
+
194
+ - (void)updateProps:(Props::Shared const &)props
195
+ oldProps:(Props::Shared const &)oldProps {
196
+ const auto &newViewProps =
197
+ *std::static_pointer_cast<LuggMapsAppleMapViewProps const>(props);
198
+
199
+ if (_mapView) {
200
+ _mapView.zoomEnabled = newViewProps.zoomEnabled;
201
+ _mapView.scrollEnabled = newViewProps.scrollEnabled;
202
+ _mapView.rotateEnabled = newViewProps.rotateEnabled;
203
+ _mapView.pitchEnabled = newViewProps.pitchEnabled;
204
+ _mapView.layoutMargins = UIEdgeInsetsMake(
205
+ newViewProps.padding.top, newViewProps.padding.left,
206
+ newViewProps.padding.bottom, newViewProps.padding.right);
207
+ }
208
+
209
+ [super updateProps:props oldProps:oldProps];
210
+ }
211
+
212
+ #pragma mark - Annotation Helpers
213
+
214
+ - (void)updateAnnotationViewFrame:(AppleMarkerAnnotation *)annotation {
215
+ MKAnnotationView *annotationView = annotation.annotationView;
216
+ LuggMapsMarkerView *markerView = annotation.markerView;
217
+
218
+ if (!annotationView || !markerView) {
219
+ return;
220
+ }
221
+
222
+ UIView *iconView = markerView.iconView;
223
+ CGRect frame = iconView.frame;
224
+ if (frame.size.width > 0 && frame.size.height > 0) {
225
+ annotationView.frame = frame;
226
+
227
+ CGPoint anchor = markerView.anchor;
228
+ annotationView.centerOffset =
229
+ CGPointMake(frame.size.width * (anchor.x - 0.5),
230
+ -frame.size.height * (anchor.y - 0.5));
231
+ }
232
+ }
233
+
234
+ #pragma mark - PolylineViewDelegate
235
+
236
+ - (void)polylineViewDidUpdate:(LuggMapsPolylineView *)polylineView {
237
+ [self syncPolylineView:polylineView];
238
+ }
239
+
240
+ #pragma mark - Polyline Management
241
+
242
+ - (void)addPolylineViewToMap:(LuggMapsPolylineView *)polylineView {
243
+ if (!_mapView) {
244
+ return;
245
+ }
246
+
247
+ NSArray<CLLocation *> *coordinates = polylineView.coordinates;
248
+ if (coordinates.count == 0) {
249
+ return;
250
+ }
251
+
252
+ CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(
253
+ sizeof(CLLocationCoordinate2D) * coordinates.count);
254
+ for (NSUInteger i = 0; i < coordinates.count; i++) {
255
+ coords[i] = coordinates[i].coordinate;
256
+ }
257
+
258
+ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords
259
+ count:coordinates.count];
260
+ free(coords);
261
+
262
+ polylineView.polyline = polyline;
263
+ [_mapView addOverlay:polyline];
264
+ }
265
+
266
+ - (void)syncPolylineView:(LuggMapsPolylineView *)polylineView {
267
+ if (!_mapView) {
268
+ return;
269
+ }
270
+
271
+ MKPolylineAnimator *renderer = (MKPolylineAnimator *)polylineView.renderer;
272
+ MKPolyline *oldPolyline = (MKPolyline *)polylineView.polyline;
273
+
274
+ // Build new polyline from coordinates
275
+ NSArray<CLLocation *> *coordinates = polylineView.coordinates;
276
+ if (coordinates.count == 0) {
277
+ if (oldPolyline) {
278
+ [_mapView removeOverlay:oldPolyline];
279
+ polylineView.polyline = nil;
280
+ polylineView.renderer = nil;
281
+ }
282
+ return;
283
+ }
284
+
285
+ CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(
286
+ sizeof(CLLocationCoordinate2D) * coordinates.count);
287
+ for (NSUInteger i = 0; i < coordinates.count; i++) {
288
+ coords[i] = coordinates[i].coordinate;
289
+ }
290
+ MKPolyline *newPolyline =
291
+ [MKPolyline polylineWithCoordinates:coords count:coordinates.count];
292
+ free(coords);
293
+
294
+ polylineView.polyline = newPolyline;
295
+
296
+ // If we have an existing renderer, update it in place
297
+ if (renderer && oldPolyline) {
298
+ [renderer updatePolyline:newPolyline];
299
+ renderer.lineWidth = polylineView.strokeWidth;
300
+ renderer.strokeColor = polylineView.strokeColors.firstObject;
301
+ renderer.strokeColors =
302
+ polylineView.strokeColors.count > 1 ? polylineView.strokeColors : nil;
303
+ renderer.animated = polylineView.animated;
304
+ return;
305
+ }
306
+
307
+ // Otherwise do full add
308
+ if (oldPolyline) {
309
+ [_mapView removeOverlay:oldPolyline];
310
+ }
311
+ [_mapView addOverlay:newPolyline];
312
+ }
313
+
314
+ - (LuggMapsPolylineView *)findPolylineViewForOverlay:(id<MKOverlay>)overlay {
315
+ for (UIView *subview in self.subviews) {
316
+ if ([subview isKindOfClass:[LuggMapsPolylineView class]]) {
317
+ LuggMapsPolylineView *polylineView = (LuggMapsPolylineView *)subview;
318
+ if (polylineView.polyline == overlay) {
319
+ return polylineView;
320
+ }
321
+ }
322
+ }
323
+ return nil;
324
+ }
325
+
326
+ #pragma mark - MarkerViewDelegate
327
+
328
+ - (void)markerViewDidLayout:(LuggMapsMarkerView *)markerView {
329
+ AppleMarkerAnnotation *annotation =
330
+ (AppleMarkerAnnotation *)markerView.marker;
331
+ if (annotation) {
332
+ [self updateAnnotationViewFrame:annotation];
333
+ }
334
+ }
335
+
336
+ - (void)markerViewDidUpdate:(LuggMapsMarkerView *)markerView {
337
+ AppleMarkerAnnotation *annotation =
338
+ (AppleMarkerAnnotation *)markerView.marker;
339
+
340
+ if (!annotation) {
341
+ RCTLogWarn(@"markerViewDidUpdate called without annotation");
342
+ return;
343
+ }
344
+
345
+ annotation.coordinate = markerView.coordinate;
346
+ annotation.title = markerView.title;
347
+ annotation.subtitle = markerView.markerDescription;
348
+
349
+ [self updateAnnotationViewFrame:annotation];
350
+ }
351
+
352
+ #pragma mark - MKMapViewDelegate
353
+
354
+ - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
355
+ _isDragging = [self isUserInteracting:mapView];
356
+ }
357
+
358
+ - (BOOL)isUserInteracting:(MKMapView *)mapView {
359
+ UIView *mapContainerView = mapView.subviews.firstObject;
360
+ for (UIGestureRecognizer *gesture in mapContainerView.gestureRecognizers) {
361
+ if (gesture.state == UIGestureRecognizerStateBegan ||
362
+ gesture.state == UIGestureRecognizerStateChanged) {
363
+ return YES;
364
+ }
365
+ }
366
+ return NO;
367
+ }
368
+
369
+ - (void)mapViewDidChangeVisibleRegion:(MKMapView *)mapView {
370
+ if (_eventEmitter) {
371
+ auto emitter =
372
+ std::static_pointer_cast<LuggMapsAppleMapViewEventEmitter const>(
373
+ _eventEmitter);
374
+ CameraMoveEvent{mapView.centerCoordinate.latitude,
375
+ mapView.centerCoordinate.longitude, mapView.zoomLevel,
376
+ _isDragging}
377
+ .emit(emitter);
378
+ }
379
+ }
380
+
381
+ - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
382
+ _isDragging = NO;
383
+ if (_eventEmitter) {
384
+ auto emitter =
385
+ std::static_pointer_cast<LuggMapsAppleMapViewEventEmitter const>(
386
+ _eventEmitter);
387
+ CameraIdleEvent{mapView.centerCoordinate.latitude,
388
+ mapView.centerCoordinate.longitude, mapView.zoomLevel}
389
+ .emit(emitter);
390
+ }
391
+ }
392
+
393
+ - (MKAnnotationView *)mapView:(MKMapView *)mapView
394
+ viewForAnnotation:(id<MKAnnotation>)annotation {
395
+ if (![annotation isKindOfClass:[AppleMarkerAnnotation class]]) {
396
+ return nil;
397
+ }
398
+
399
+ AppleMarkerAnnotation *markerAnnotation = (AppleMarkerAnnotation *)annotation;
400
+ LuggMapsMarkerView *markerView = markerAnnotation.markerView;
401
+
402
+ if (!markerView || !markerView.hasCustomView) {
403
+ return nil;
404
+ }
405
+
406
+ MKAnnotationView *annotationView =
407
+ [[MKAnnotationView alloc] initWithAnnotation:annotation
408
+ reuseIdentifier:nil];
409
+ annotationView.canShowCallout = YES;
410
+ annotationView.displayPriority = MKFeatureDisplayPriorityRequired;
411
+ annotationView.collisionMode = MKAnnotationViewCollisionModeNone;
412
+
413
+ UIView *iconView = markerView.iconView;
414
+ [iconView removeFromSuperview];
415
+ [annotationView addSubview:iconView];
416
+
417
+ // Set frame and centerOffset based on iconView
418
+ CGRect frame = iconView.frame;
419
+ if (frame.size.width > 0 && frame.size.height > 0) {
420
+ annotationView.frame =
421
+ CGRectMake(0, 0, frame.size.width, frame.size.height);
422
+ iconView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
423
+
424
+ CGPoint anchor = markerView.anchor;
425
+ annotationView.centerOffset =
426
+ CGPointMake(frame.size.width * (anchor.x - 0.5),
427
+ -frame.size.height * (anchor.y - 0.5));
428
+ }
429
+
430
+ markerAnnotation.annotationView = annotationView;
431
+
432
+ return annotationView;
433
+ }
434
+
435
+ - (MKOverlayRenderer *)mapView:(MKMapView *)mapView
436
+ rendererForOverlay:(id<MKOverlay>)overlay {
437
+ if ([overlay isKindOfClass:[MKPolyline class]]) {
438
+ LuggMapsPolylineView *polylineView =
439
+ [self findPolylineViewForOverlay:overlay];
440
+ MKPolyline *polyline = (MKPolyline *)overlay;
441
+
442
+ if (polylineView) {
443
+ NSArray<UIColor *> *colors = polylineView.strokeColors;
444
+
445
+ MKPolylineAnimator *renderer =
446
+ [[MKPolylineAnimator alloc] initWithPolyline:polyline];
447
+ renderer.lineWidth = polylineView.strokeWidth;
448
+ renderer.strokeColor = colors.firstObject;
449
+ if (colors.count > 1) {
450
+ renderer.strokeColors = colors;
451
+ }
452
+ renderer.animated = polylineView.animated;
453
+ polylineView.renderer = renderer;
454
+ return renderer;
455
+ }
456
+
457
+ MKPolylineRenderer *renderer =
458
+ [[MKPolylineRenderer alloc] initWithPolyline:polyline];
459
+ return renderer;
460
+ }
461
+ return nil;
462
+ }
463
+
464
+ #pragma mark - Commands
465
+
466
+ - (void)moveCamera:(double)latitude
467
+ longitude:(double)longitude
468
+ zoom:(double)zoom
469
+ duration:(double)duration {
470
+ if (!_mapView) {
471
+ return;
472
+ }
473
+
474
+ if (duration < 0) {
475
+ [self setCameraWithLatitude:latitude
476
+ longitude:longitude
477
+ zoom:zoom
478
+ animated:YES];
479
+ } else if (duration > 0) {
480
+ CLLocationCoordinate2D center =
481
+ CLLocationCoordinate2DMake(latitude, longitude);
482
+ MKCoordinateRegion region = [_mapView regionForCenterCoordinate:center
483
+ zoomLevel:zoom];
484
+ [UIView animateWithDuration:duration / 1000.0
485
+ animations:^{
486
+ [self->_mapView setRegion:region animated:NO];
487
+ }];
488
+ } else {
489
+ [self setCameraWithLatitude:latitude
490
+ longitude:longitude
491
+ zoom:zoom
492
+ animated:NO];
493
+ }
494
+ }
495
+
496
+ - (void)fitCoordinates:(NSArray *)coordinates
497
+ padding:(double)padding
498
+ duration:(double)duration {
499
+ if (!_mapView || coordinates.count == 0) {
500
+ return;
501
+ }
502
+
503
+ CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(
504
+ sizeof(CLLocationCoordinate2D) * coordinates.count);
505
+ for (NSUInteger i = 0; i < coordinates.count; i++) {
506
+ NSDictionary *coord = coordinates[i];
507
+ coords[i] = CLLocationCoordinate2DMake([coord[@"latitude"] doubleValue],
508
+ [coord[@"longitude"] doubleValue]);
509
+ }
510
+
511
+ MKMapRect mapRect = MKMapRectNull;
512
+ for (NSUInteger i = 0; i < coordinates.count; i++) {
513
+ MKMapPoint point = MKMapPointForCoordinate(coords[i]);
514
+ MKMapRect pointRect = MKMapRectMake(point.x, point.y, 0, 0);
515
+ mapRect = MKMapRectUnion(mapRect, pointRect);
516
+ }
517
+ free(coords);
518
+
519
+ UIEdgeInsets edgePadding =
520
+ UIEdgeInsetsMake(padding, padding, padding, padding);
521
+
522
+ if (duration < 0) {
523
+ [_mapView setVisibleMapRect:mapRect edgePadding:edgePadding animated:YES];
524
+ } else if (duration > 0) {
525
+ [UIView animateWithDuration:duration / 1000.0
526
+ animations:^{
527
+ [self->_mapView setVisibleMapRect:mapRect
528
+ edgePadding:edgePadding
529
+ animated:NO];
530
+ }];
531
+ } else {
532
+ [_mapView setVisibleMapRect:mapRect edgePadding:edgePadding animated:NO];
533
+ }
534
+ }
535
+
536
+ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
537
+ RCTLuggMapsAppleMapViewHandleCommand(self, commandName, args);
538
+ }
539
+
540
+ Class<RCTComponentViewProtocol> LuggMapsAppleMapViewCls(void) {
541
+ return LuggMapsAppleMapView.class;
542
+ }
543
+
544
+ @end
@@ -0,0 +1,13 @@
1
+ #import <GoogleMaps/GoogleMaps.h>
2
+ #import <React/RCTViewComponentView.h>
3
+ #import <UIKit/UIKit.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ @interface LuggMapsGoogleMapView : RCTViewComponentView
8
+
9
+ @property(nonatomic, readonly, nullable) GMSMapView *mapView;
10
+
11
+ @end
12
+
13
+ NS_ASSUME_NONNULL_END