react-native-maps 1.20.1 → 1.21.0-alpha.10

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 (50) hide show
  1. package/README.md +13 -6
  2. package/android/build.gradle +19 -4
  3. package/android/src/main/java/com/rnmaps/fabric/NativeAirMapsModule.java +51 -0
  4. package/android/src/main/java/com/rnmaps/maps/MapAirModulePackage.java +46 -0
  5. package/ios/AirGoogleMaps/AIRGoogleMap.h +8 -2
  6. package/ios/AirGoogleMaps/AIRGoogleMap.m +151 -7
  7. package/ios/AirGoogleMaps/AIRGoogleMapCircle.h +0 -1
  8. package/ios/AirGoogleMaps/AIRGoogleMapCoordinate.h +13 -0
  9. package/ios/AirGoogleMaps/AIRGoogleMapCoordinate.m +10 -0
  10. package/ios/AirGoogleMaps/AIRGoogleMapManager.h +7 -0
  11. package/ios/AirGoogleMaps/AIRGoogleMapManager.m +28 -119
  12. package/ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m +0 -1
  13. package/ios/AirGoogleMaps/AIRGoogleMapOverlay.h +0 -1
  14. package/ios/AirGoogleMaps/AIRGoogleMapPolygon.h +3 -3
  15. package/ios/AirGoogleMaps/AIRGoogleMapPolygon.m +2 -2
  16. package/ios/AirGoogleMaps/AIRGoogleMapPolygonManager.m +3 -3
  17. package/ios/AirGoogleMaps/AIRGoogleMapPolyline.h +3 -2
  18. package/ios/AirGoogleMaps/AIRGoogleMapPolyline.m +2 -3
  19. package/ios/AirGoogleMaps/AIRGoogleMapPolylineManager.m +2 -2
  20. package/ios/AirGoogleMaps/RCTConvert+GMSMapViewType.h +3 -0
  21. package/ios/AirGoogleMaps/RCTConvert+GMSMapViewType.m +16 -0
  22. package/ios/AirGoogleMaps/RNMapsGoogleMapView.h +26 -0
  23. package/ios/AirGoogleMaps/RNMapsGoogleMapView.mm +581 -0
  24. package/ios/AirGoogleMaps/RNMapsGoogleMapViewManager.mm +25 -0
  25. package/ios/AirMaps/AIRMap.h +8 -5
  26. package/ios/AirMaps/AIRMap.m +180 -27
  27. package/ios/AirMaps/AIRMapManager.m +24 -39
  28. package/ios/AirMaps/AIRMapMarker.m +11 -3
  29. package/ios/AirMaps/RCTConvert+AirMap.h +6 -1
  30. package/ios/AirMaps/RCTConvert+AirMap.m +18 -0
  31. package/ios/AirMaps/RNMapsAirModule.h +16 -0
  32. package/ios/AirMaps/RNMapsAirModule.mm +149 -0
  33. package/ios/AirMaps/RNMapsMapView.h +24 -0
  34. package/ios/AirMaps/RNMapsMapView.mm +535 -0
  35. package/ios/AirMaps/RNMapsMapViewManager.mm +24 -0
  36. package/ios/AirMaps.xcodeproj/project.pbxproj +10 -0
  37. package/lib/MapOverlay.d.ts +1 -1
  38. package/lib/MapView.d.ts +8 -4
  39. package/lib/MapView.js +148 -73
  40. package/lib/createFabricMap.d.ts +23 -0
  41. package/lib/createFabricMap.js +175 -0
  42. package/lib/specs/NativeAirMapsModule.d.ts +31 -0
  43. package/lib/specs/NativeAirMapsModule.js +4 -0
  44. package/lib/specs/NativeComponentGoogleMapView.d.ts +713 -0
  45. package/lib/specs/NativeComponentGoogleMapView.js +21 -0
  46. package/lib/specs/NativeComponentMapView.d.ts +855 -0
  47. package/lib/specs/NativeComponentMapView.js +21 -0
  48. package/package.json +14 -7
  49. package/react-native-maps.podspec +3 -1
  50. package/react-native-google-maps.podspec +0 -25
@@ -20,6 +20,7 @@
20
20
  #import "AIRMapWMSTile.h"
21
21
  #import "AIRMapLocalTile.h"
22
22
  #import "AIRMapOverlay.h"
23
+ #import "AIRMapSnapshot.h"
23
24
 
24
25
  const NSTimeInterval AIRMapRegionChangeObserveInterval = 0.1;
25
26
  const CGFloat AIRMapZoomBoundBuffer = 0.01;
@@ -85,8 +86,8 @@ const NSInteger AIRMapMaxZoomLevel = 20;
85
86
  self.calloutView = [SMCalloutView platformCalloutView];
86
87
  self.calloutView.delegate = self;
87
88
 
88
- self.minZoomLevel = 0;
89
- self.maxZoomLevel = AIRMapMaxZoomLevel;
89
+ self.minZoom = 0;
90
+ self.maxZoom = AIRMapMaxZoomLevel;
90
91
  self.compassOffset = CGPointMake(0, 0);
91
92
  self.legacyZoomConstraintsEnabled = YES;
92
93
  }
@@ -199,36 +200,25 @@ const NSInteger AIRMapMaxZoomLevel = 20;
199
200
  }
200
201
  return marker;
201
202
  }
203
+ // Create Polyline with coordinates
204
+ -(void) fitToCoordinates:(NSArray<AIRMapCoordinate*>*) coordinates edgePadding:(UIEdgeInsets) edgeInsets animated:(Boolean) animated {
205
+ CLLocationCoordinate2D coords[coordinates.count];
206
+ for(int i = 0; i < coordinates.count; i++)
207
+ {
208
+ coords[i] = coordinates[i].coordinate;
209
+ }
210
+ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordinates.count];
202
211
 
212
+ // Set Map viewport
213
+
214
+ [self setVisibleMapRect:[polyline boundingMapRect] edgePadding:edgeInsets animated:animated];
215
+ }
203
216
  - (CGRect) frameForMarker:(AIRMapMarker*) mrkAnn {
204
217
  MKAnnotationView* mrkView = [self viewForAnnotation: mrkAnn];
205
218
  CGRect mrkFrame = mrkView.frame;
206
219
  return mrkFrame;
207
220
  }
208
221
 
209
- - (NSDictionary*) getMarkersFramesWithOnlyVisible:(BOOL)onlyVisible {
210
- NSMutableDictionary* markersFrames = [NSMutableDictionary new];
211
- for (AIRMapMarker* mrkAnn in self.markers) {
212
- CGRect frame = [self frameForMarker:mrkAnn];
213
- CGPoint point = [self convertCoordinate:mrkAnn.coordinate toPointToView:self];
214
- NSDictionary* frameDict = @{
215
- @"x": @(frame.origin.x),
216
- @"y": @(frame.origin.y),
217
- @"width": @(frame.size.width),
218
- @"height": @(frame.size.height)
219
- };
220
- NSDictionary* pointDict = @{
221
- @"x": @(point.x),
222
- @"y": @(point.y)
223
- };
224
- NSString* k = mrkAnn.identifier;
225
- BOOL isVisible = CGRectIntersectsRect(self.bounds, frame);
226
- if (k != nil && (!onlyVisible || isVisible)) {
227
- [markersFrames setObject:@{ @"frame": frameDict, @"point": pointDict } forKey:k];
228
- }
229
- }
230
- return markersFrames;
231
- }
232
222
 
233
223
  - (AIRMapMarker*) markerAtPoint:(CGPoint)point {
234
224
  AIRMapMarker* mrk = nil;
@@ -322,7 +312,7 @@ const NSInteger AIRMapMaxZoomLevel = 20;
322
312
  return kSMCalloutViewRepositionDelayForUIScrollView;
323
313
  }
324
314
 
325
- #pragma mark Accessors
315
+ #pragma mark RNMapsAirModuleDelegate.h
326
316
 
327
317
  - (NSArray *)getMapBoundaries
328
318
  {
@@ -342,6 +332,169 @@ const NSInteger AIRMapMaxZoomLevel = 20;
342
332
  ]
343
333
  ];
344
334
  }
335
+ - (NSDictionary *) getPointForCoordinates:(CLLocationCoordinate2D) location
336
+ {
337
+ CGPoint touchPoint = [self convertCoordinate:location toPointToView:self];
338
+
339
+ return @{
340
+ @"x": @(touchPoint.x),
341
+ @"y": @(touchPoint.y),
342
+ };
343
+ }
344
+ - (NSDictionary *) getCoordinatesForPoint:(CGPoint)point
345
+ {
346
+ CLLocationCoordinate2D coordinate = [self convertPoint:point toCoordinateFromView:self];
347
+ return @{
348
+ @"latitude": @(coordinate.latitude),
349
+ @"longitude": @(coordinate.longitude),
350
+ };
351
+
352
+ }
353
+
354
+ - (NSDictionary*) getMarkersFramesWithOnlyVisible:(BOOL)onlyVisible {
355
+ NSMutableDictionary* markersFrames = [NSMutableDictionary new];
356
+ for (AIRMapMarker* mrkAnn in self.markers) {
357
+ CGRect frame = [self frameForMarker:mrkAnn];
358
+ CGPoint point = [self convertCoordinate:mrkAnn.coordinate toPointToView:self];
359
+ NSDictionary* frameDict = @{
360
+ @"x": @(frame.origin.x),
361
+ @"y": @(frame.origin.y),
362
+ @"width": @(frame.size.width),
363
+ @"height": @(frame.size.height)
364
+ };
365
+ NSDictionary* pointDict = @{
366
+ @"x": @(point.x),
367
+ @"y": @(point.y)
368
+ };
369
+ NSString* k = mrkAnn.identifier;
370
+ BOOL isVisible = CGRectIntersectsRect(self.bounds, frame);
371
+ if (k != nil && (!onlyVisible || isVisible)) {
372
+ [markersFrames setObject:@{ @"frame": frameDict, @"point": pointDict } forKey:k];
373
+ }
374
+ }
375
+ return markersFrames;
376
+ }
377
+
378
+ - (NSDictionary *) getCamera {
379
+ MKMapCamera *camera = [self camera];
380
+ return @{
381
+ @"center": @{
382
+ @"latitude": @(camera.centerCoordinate.latitude),
383
+ @"longitude": @(camera.centerCoordinate.longitude),
384
+ },
385
+ @"pitch": @(camera.pitch),
386
+ @"heading": @(camera.heading),
387
+ @"altitude": @(camera.altitude),
388
+ };
389
+ }
390
+ - (void)takeSnapshotWithConfig:(NSDictionary *)config
391
+ callback:(RCTPromiseResolveBlock) callback
392
+ {
393
+
394
+ MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
395
+
396
+ options.mapType = self.mapType;
397
+ NSNumber *width = config[@"width"];
398
+ NSNumber *height = config[@"height"];
399
+ NSNumber *quality = config[@"quality"];
400
+ NSString*format =config[@"format"];
401
+ NSString*result =config[@"result"];
402
+ MKCoordinateRegion region = [RCTConvert MKCoordinateRegion:config[@"region"]];
403
+
404
+
405
+ options.region = (region.center.latitude && region.center.longitude) ? region : self.region;
406
+ options.size = CGSizeMake(
407
+ ([width floatValue] == 0) ? self.bounds.size.width : [width floatValue],
408
+ ([height floatValue] == 0) ? self.bounds.size.height : [height floatValue]
409
+ );
410
+
411
+ options.scale = [[UIScreen mainScreen] scale];
412
+
413
+
414
+ MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
415
+
416
+ [self takeMapSnapshot:snapshotter
417
+ format:format
418
+ quality:[quality floatValue]
419
+ result:result
420
+ callback:callback];
421
+ }
422
+
423
+ #pragma mark Take Snapshot
424
+ - (void)takeMapSnapshot:(MKMapSnapshotter *) snapshotter
425
+ format:(NSString *)format
426
+ quality:(CGFloat) quality
427
+ result:(NSString *)result
428
+ callback:(RCTPromiseResolveBlock) callback {
429
+ NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
430
+ NSString *pathComponent = [NSString stringWithFormat:@"Documents/snapshot-%.20lf.%@", timeStamp, format];
431
+ NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent: pathComponent];
432
+
433
+ [snapshotter startWithQueue:dispatch_get_main_queue()
434
+ completionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
435
+ if (error) {
436
+ callback(@[error]);
437
+ return;
438
+ }
439
+ MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:nil];
440
+
441
+ UIImage *image = snapshot.image;
442
+ UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale);
443
+ {
444
+ [image drawAtPoint:CGPointMake(0.0f, 0.0f)];
445
+
446
+ CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
447
+
448
+ for (id <AIRMapSnapshot> overlay in self.overlays) {
449
+ if ([overlay respondsToSelector:@selector(drawToSnapshot:context:)]) {
450
+ [overlay drawToSnapshot:snapshot context:UIGraphicsGetCurrentContext()];
451
+ }
452
+ }
453
+
454
+ for (id <MKAnnotation> annotation in self.annotations) {
455
+ CGPoint point = [snapshot pointForCoordinate:annotation.coordinate];
456
+
457
+ MKAnnotationView* anView = [self viewForAnnotation: annotation];
458
+
459
+ if (anView){
460
+ pin = anView;
461
+ }
462
+
463
+ if (CGRectContainsPoint(rect, point)) {
464
+ point.x = point.x + pin.centerOffset.x - (pin.bounds.size.width / 2.0f);
465
+ point.y = point.y + pin.centerOffset.y - (pin.bounds.size.height / 2.0f);
466
+ if (pin.image) {
467
+ [pin.image drawAtPoint:point];
468
+ } else {
469
+ CGRect pinRect = CGRectMake(point.x, point.y, pin.bounds.size.width, pin.bounds.size.height);
470
+ [pin drawViewHierarchyInRect:pinRect afterScreenUpdates:NO];
471
+ }
472
+ }
473
+ }
474
+
475
+ UIImage *compositeImage = UIGraphicsGetImageFromCurrentImageContext();
476
+
477
+ NSData *data;
478
+ if ([format isEqualToString:@"png"]) {
479
+ data = UIImagePNGRepresentation(compositeImage);
480
+ }
481
+ else if([format isEqualToString:@"jpg"]) {
482
+ data = UIImageJPEGRepresentation(compositeImage, quality);
483
+ }
484
+
485
+ if ([result isEqualToString:@"file"]) {
486
+ [data writeToFile:filePath atomically:YES];
487
+ callback(filePath);
488
+ }
489
+ else if ([result isEqualToString:@"base64"]) {
490
+ callback([data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]);
491
+ }
492
+ }
493
+ UIGraphicsEndImageContext();
494
+ }];
495
+ }
496
+
497
+
345
498
 
346
499
  - (void)setShowsUserLocation:(BOOL)showsUserLocation
347
500
  {
@@ -372,7 +525,7 @@ const NSInteger AIRMapMaxZoomLevel = 20;
372
525
 
373
526
  - (void)setFollowsUserLocation:(BOOL)followsUserLocation
374
527
  {
375
- _followUserLocation = followsUserLocation;
528
+ _followsUserLocation = followsUserLocation;
376
529
  }
377
530
 
378
531
  - (void)setUserLocationCalloutEnabled:(BOOL)calloutEnabled
@@ -52,13 +52,13 @@ RCT_EXPORT_MODULE()
52
52
 
53
53
  map.isAccessibilityElement = NO;
54
54
  map.accessibilityElementsHidden = NO;
55
-
55
+
56
56
  // MKMapView doesn't report tap events, so we attach gesture recognizers to it
57
57
  UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleMapTap:)];
58
58
  UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleMapDoubleTap:)];
59
59
  [doubleTap setNumberOfTapsRequired:2];
60
60
  [tap requireGestureRecognizerToFail:doubleTap];
61
-
61
+
62
62
  UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleMapLongPress:)];
63
63
  UIPanGestureRecognizer *drag = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleMapDrag:)];
64
64
  [drag setMinimumNumberOfTouches:1];
@@ -66,13 +66,13 @@ RCT_EXPORT_MODULE()
66
66
  tap.cancelsTouchesInView = NO;
67
67
  doubleTap.cancelsTouchesInView = NO;
68
68
  longPress.cancelsTouchesInView = NO;
69
-
69
+
70
70
  doubleTap.delegate = self;
71
-
71
+
72
72
  // disable drag by default
73
73
  drag.enabled = NO;
74
74
  drag.delegate = self;
75
-
75
+
76
76
  [map addGestureRecognizer:tap];
77
77
  [map addGestureRecognizer:doubleTap];
78
78
  [map addGestureRecognizer:longPress];
@@ -139,7 +139,7 @@ RCT_CUSTOM_VIEW_PROPERTY(initialRegion, MKCoordinateRegion, AIRMap)
139
139
  RCT_CUSTOM_VIEW_PROPERTY(initialCamera, MKMapCamera, AIRMap)
140
140
  {
141
141
  if (json == nil) return;
142
-
142
+
143
143
  // don't emit region change events when we are setting the initialCamera
144
144
  BOOL originalIgnore = view.ignoreRegionChanges;
145
145
  view.ignoreRegionChanges = YES;
@@ -166,7 +166,7 @@ RCT_CUSTOM_VIEW_PROPERTY(region, MKCoordinateRegion, AIRMap)
166
166
  RCT_CUSTOM_VIEW_PROPERTY(camera, MKMapCamera*, AIRMap)
167
167
  {
168
168
  if (json == nil) return;
169
-
169
+
170
170
  // don't emit region change events when we are setting the camera
171
171
  BOOL originalIgnore = view.ignoreRegionChanges;
172
172
  view.ignoreRegionChanges = YES;
@@ -350,23 +350,8 @@ RCT_EXPORT_METHOD(fitToCoordinates:(nonnull NSNumber *)reactTag
350
350
  RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
351
351
  } else {
352
352
  AIRMap *mapView = (AIRMap *)view;
353
-
354
- // Create Polyline with coordinates
355
- CLLocationCoordinate2D coords[coordinates.count];
356
- for(int i = 0; i < coordinates.count; i++)
357
- {
358
- coords[i] = coordinates[i].coordinate;
359
- }
360
- MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordinates.count];
361
-
362
- // Set Map viewport
363
- CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
364
- CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
365
- CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
366
- CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
367
-
368
- [mapView setVisibleMapRect:[polyline boundingMapRect] edgePadding:UIEdgeInsetsMake(top, left, bottom, right) animated:animated];
369
-
353
+ UIEdgeInsets edgeInsets = [RCTConvert UIEdgeInsets:edgePadding];
354
+ [mapView fitToCoordinates: coordinates edgePadding:edgeInsets animated:animated];
370
355
  }
371
356
  }];
372
357
  }
@@ -551,16 +536,16 @@ RCT_EXPORT_METHOD(getAddressFromCoordinates:(nonnull NSNumber *)reactTag
551
536
  [overlay drawToSnapshot:snapshot context:UIGraphicsGetCurrentContext()];
552
537
  }
553
538
  }
554
-
539
+
555
540
  for (id <MKAnnotation> annotation in mapView.annotations) {
556
541
  CGPoint point = [snapshot pointForCoordinate:annotation.coordinate];
557
-
542
+
558
543
  MKAnnotationView* anView = [mapView viewForAnnotation: annotation];
559
-
544
+
560
545
  if (anView){
561
546
  pin = anView;
562
547
  }
563
-
548
+
564
549
  if (CGRectContainsPoint(rect, point)) {
565
550
  point.x = point.x + pin.centerOffset.x - (pin.bounds.size.width / 2.0f);
566
551
  point.y = point.y + pin.centerOffset.y - (pin.bounds.size.height / 2.0f);
@@ -720,7 +705,7 @@ RCT_EXPORT_METHOD(getAddressFromCoordinates:(nonnull NSNumber *)reactTag
720
705
  - (void)handleMapDoubleTap:(UIPanGestureRecognizer*)recognizer {
721
706
  AIRMap *map = (AIRMap *)recognizer.view;
722
707
  if (!map.onDoublePress) return;
723
-
708
+
724
709
  CGPoint touchPoint = [recognizer locationInView:map];
725
710
  CLLocationCoordinate2D coord = [map convertPoint:touchPoint toCoordinateFromView:map];
726
711
  map.onDoublePress(@{
@@ -733,7 +718,7 @@ RCT_EXPORT_METHOD(getAddressFromCoordinates:(nonnull NSNumber *)reactTag
733
718
  @"y": @(touchPoint.y),
734
719
  },
735
720
  });
736
-
721
+
737
722
  }
738
723
 
739
724
 
@@ -925,15 +910,15 @@ static int kDragCenterContext;
925
910
  @"heading": @(location.location.course),
926
911
  }
927
912
  };
928
-
913
+
929
914
  if (mapView.onUserLocationChange) {
930
915
  mapView.onUserLocationChange(event);
931
916
  }
932
-
933
- if (mapView.followUserLocation) {
917
+
918
+ if (mapView.followsUserLocation) {
934
919
  [mapView setCenterCoordinate:location.coordinate animated:YES];
935
920
  }
936
-
921
+
937
922
  }
938
923
 
939
924
  - (void)mapView:(AIRMap *)mapView regionWillChangeAnimated:(BOOL)animated
@@ -1171,15 +1156,15 @@ static int kDragCenterContext;
1171
1156
  // flyover maps don't use mercator projection so we can't calculate their zoom level.
1172
1157
  if (mapView.mapType == MKMapTypeHybridFlyover || mapView.mapType == MKMapTypeSatelliteFlyover) {
1173
1158
  return;
1174
- }
1159
+ }
1175
1160
 
1176
1161
  CGFloat zoomLevel = [mapView getZoomLevel];
1177
1162
 
1178
- if (zoomLevel < mapView.minZoomLevel) {
1179
- [self setCenterCoordinate:[mapView centerCoordinate] zoomLevel:mapView.minZoomLevel animated:TRUE mapView:mapView];
1163
+ if (zoomLevel < mapView.minZoom) {
1164
+ [self setCenterCoordinate:[mapView centerCoordinate] zoomLevel:mapView.minZoom animated:TRUE mapView:mapView];
1180
1165
  }
1181
- else if (zoomLevel > mapView.maxZoomLevel) {
1182
- [self setCenterCoordinate:[mapView centerCoordinate] zoomLevel:mapView.maxZoomLevel animated:TRUE mapView:mapView];
1166
+ else if (zoomLevel > mapView.maxZoom) {
1167
+ [self setCenterCoordinate:[mapView centerCoordinate] zoomLevel:mapView.maxZoom animated:TRUE mapView:mapView];
1183
1168
  }
1184
1169
  }
1185
1170
 
@@ -70,6 +70,14 @@ NSInteger const AIR_CALLOUT_OPEN_ZINDEX_BASELINE = 999;
70
70
  [super insertReactSubview:(UIView *)subview atIndex:atIndex];
71
71
  }
72
72
  }
73
+ - (void) setFrame:(CGRect)frame {
74
+ // hack to ignore call by react transactions when it shouldn't
75
+ if (!CGPointEqualToPoint(self.frame.origin, CGPointZero) &&
76
+ CGPointEqualToPoint(frame.origin, CGPointZero)){
77
+ return;
78
+ }
79
+ [super setFrame:frame];
80
+ }
73
81
 
74
82
  - (void)removeReactSubview:(id<RCTComponent>)subview {
75
83
  if ([subview isKindOfClass:[AIRMapCallout class]] && self.calloutView == subview) {
@@ -84,7 +92,7 @@ NSInteger const AIR_CALLOUT_OPEN_ZINDEX_BASELINE = 999;
84
92
  if ([self shouldUsePinView]) {
85
93
  // In this case, we want to render a platform "default" legacy marker.
86
94
 
87
-
95
+
88
96
  if (_pinView == nil && _useLegacyPinView) {
89
97
  _pinView = [[MKPinAnnotationView alloc] initWithAnnotation:self reuseIdentifier: nil];
90
98
  [self addGestureRecognizerToView:_pinView];
@@ -99,8 +107,8 @@ NSInteger const AIR_CALLOUT_OPEN_ZINDEX_BASELINE = 999;
99
107
 
100
108
  return _pinView;
101
109
  }
102
-
103
-
110
+
111
+
104
112
 
105
113
  if (_markerView == nil && !_useLegacyPinView) {
106
114
  _markerView = [[MKMarkerAnnotationView alloc] initWithAnnotation:self reuseIdentifier: nil];
@@ -7,6 +7,8 @@
7
7
  #import <MapKit/MapKit.h>
8
8
  #import <React/RCTConvert.h>
9
9
 
10
+ @class AIRMapCoordinate;
11
+
10
12
  @interface RCTConvert (AirMap)
11
13
 
12
14
  + (MKCoordinateSpan)MKCoordinateSpan:(id)json;
@@ -14,5 +16,8 @@
14
16
  + (MKMapCamera*)MKMapCamera:(id)json;
15
17
  + (MKMapCamera*)MKMapCameraWithDefaults:(id)json existingCamera:(MKMapCamera*)camera;
16
18
  + (MKMapType)MKMapType:(id)json;
17
-
19
+ + (NSDictionary*) dictonaryFromString:(NSString *) str;
20
+ + (NSArray*) arrayFromString:(NSString *) str;
21
+ + (NSArray<NSArray<AIRMapCoordinate *> *> *)AIRMapCoordinateArrayArray:(id)json;
22
+ + (AIRMapCoordinate*) AIRMapCoordinate:(id)json;
18
23
  @end
@@ -27,12 +27,30 @@
27
27
  };
28
28
  }
29
29
 
30
+
30
31
  + (MKMapCamera*)MKMapCamera:(id)json
31
32
  {
32
33
  json = [self NSDictionary:json];
33
34
  return [RCTConvert MKMapCameraWithDefaults:json existingCamera:nil];
34
35
  }
35
36
 
37
+ + (NSDictionary*) dictonaryFromString:(NSString *) str {
38
+ NSError *jsonError;
39
+ NSData *objectData = [str dataUsingEncoding:NSUTF8StringEncoding];
40
+ return [NSJSONSerialization JSONObjectWithData:objectData
41
+ options:NSJSONReadingMutableContainers
42
+ error:&jsonError];
43
+ }
44
+
45
+ + (NSArray*) arrayFromString:(NSString *) str {
46
+ NSError *jsonError;
47
+ NSData *objectData = [str dataUsingEncoding:NSUTF8StringEncoding];
48
+ return [NSJSONSerialization JSONObjectWithData:objectData
49
+ options:NSJSONReadingMutableContainers
50
+ error:&jsonError];
51
+ }
52
+
53
+
36
54
  + (MKMapCamera*)MKMapCameraWithDefaults:(id)json existingCamera:(MKMapCamera*)camera
37
55
  {
38
56
  json = [self NSDictionary:json];
@@ -0,0 +1,16 @@
1
+ // RCTNativeLocalStorage.h
2
+ // TurboModuleExample
3
+ #ifdef RCT_NEW_ARCH_ENABLED
4
+
5
+ #import <Foundation/Foundation.h>
6
+ #import <RNMapsSpecs/RNMapsSpecs.h>
7
+
8
+ NS_ASSUME_NONNULL_BEGIN
9
+
10
+ @interface RNMapsAirModule : NSObject <NativeAirMapsModuleSpec>
11
+
12
+ @end
13
+
14
+ NS_ASSUME_NONNULL_END
15
+
16
+ #endif
@@ -0,0 +1,149 @@
1
+ //
2
+ // RNMapsMarkerManager.m
3
+ // AirMaps
4
+ //
5
+ // Created by Salah Ghanim on 23.11.24.
6
+ // Copyright © 2024 react-native-maps. All rights reserved.
7
+ //
8
+
9
+ #import "RNMapsAirModule.h"
10
+ #import <React/RCTUIManager.h>
11
+ #import <React/RCTViewManager.h>
12
+ #import "RNMapsMapView.h"
13
+ #import "AIRMap.h"
14
+ #import "AIRMapSnapshot.h"
15
+ #import <MapKit/MapKit.h>
16
+ #import "RCTConvert+AirMap.h"
17
+
18
+ @implementation RNMapsAirModule
19
+
20
+ @synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED;
21
+
22
+ - (void)executeWithMapView:(double)tag
23
+ success:(void (^)(id<RNMapsAirModuleDelegate> mapView))success
24
+ reject:(RCTPromiseRejectBlock)reject {
25
+ dispatch_async(dispatch_get_main_queue(), ^{
26
+ id view = [_viewRegistry_DEPRECATED viewForReactTag:[NSNumber numberWithDouble:tag]];
27
+ if ([view conformsToProtocol:@protocol(RNMapsHostVewDelegate)]) {
28
+ id<RNMapsAirModuleDelegate> mapViewDelegate = [view mapView];
29
+ success(mapViewDelegate);
30
+ } else {
31
+ reject(@"Invalid argument", [NSString stringWithFormat:@"Invalid view returned from registry, expecting RNMapsMapView, got: %@", view], NULL);
32
+ }
33
+ });
34
+ }
35
+
36
+ - (void)getCamera:(double)tag
37
+ resolve:(RCTPromiseResolveBlock)resolve
38
+ reject:(RCTPromiseRejectBlock)reject {
39
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
40
+ resolve([mapView getCamera]);
41
+ } reject:reject];
42
+
43
+ }
44
+
45
+ - (void)getMarkersFrames:(double)tag
46
+ onlyVisible:(BOOL)onlyVisible
47
+ resolve:(RCTPromiseResolveBlock)resolve
48
+ reject:(RCTPromiseRejectBlock)reject
49
+ {
50
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
51
+ resolve([mapView getMarkersFramesWithOnlyVisible:onlyVisible]);
52
+ } reject:reject];
53
+ }
54
+ - (void)getMapBoundaries:(double)tag
55
+ resolve:(RCTPromiseResolveBlock)resolve
56
+ reject:(RCTPromiseRejectBlock)reject
57
+ {
58
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
59
+ resolve([mapView getMapBoundaries]);
60
+ } reject:reject];
61
+ }
62
+ - (void)takeSnapshot:(double)tag
63
+ config:(NSDictionary *)config
64
+ resolve:(RCTPromiseResolveBlock)resolve
65
+ reject:(RCTPromiseRejectBlock)reject
66
+ {
67
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
68
+ [mapView takeSnapshotWithConfig:config callback:resolve];
69
+ } reject:reject];
70
+ }
71
+
72
+ - (void)getAddressFromCoordinates:(double)tag
73
+ coordinate:(JS::NativeAirMapsModule::LatLng &)coordinate
74
+ resolve:(RCTPromiseResolveBlock)resolve
75
+ reject:(RCTPromiseRejectBlock)reject
76
+ {
77
+ double latitude = coordinate.latitude();
78
+ double longitude = coordinate.longitude();
79
+
80
+
81
+ CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude
82
+ longitude:longitude];
83
+ CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
84
+ [geoCoder reverseGeocodeLocation:location
85
+ completionHandler:^(NSArray *placemarks, NSError *error) {
86
+ if (error == nil && [placemarks count] > 0){
87
+ CLPlacemark *placemark = placemarks[0];
88
+ resolve(@{
89
+ @"name" : [NSString stringWithFormat:@"%@", placemark.name],
90
+ @"thoroughfare" : [NSString stringWithFormat:@"%@", placemark.thoroughfare],
91
+ @"subThoroughfare" : [NSString stringWithFormat:@"%@", placemark.subThoroughfare],
92
+ @"locality" : [NSString stringWithFormat:@"%@", placemark.locality],
93
+ @"subLocality" : [NSString stringWithFormat:@"%@", placemark.subLocality],
94
+ @"administrativeArea" : [NSString stringWithFormat:@"%@", placemark.administrativeArea],
95
+ @"subAdministrativeArea" : [NSString stringWithFormat:@"%@", placemark.subAdministrativeArea],
96
+ @"postalCode" : [NSString stringWithFormat:@"%@", placemark.postalCode],
97
+ @"countryCode" : [NSString stringWithFormat:@"%@", placemark.ISOcountryCode],
98
+ @"country" : [NSString stringWithFormat:@"%@", placemark.country],
99
+ });
100
+ } else {
101
+ reject(@"Invalid argument", [NSString stringWithFormat:@"Can not get address location"], NULL);
102
+ }
103
+ }];
104
+ }
105
+
106
+ - (void)getPointForCoordinate:(double)tag
107
+ coordinate:(JS::NativeAirMapsModule::LatLng &)coordinate
108
+ resolve:(RCTPromiseResolveBlock)resolve
109
+ reject:(RCTPromiseRejectBlock)reject
110
+ {
111
+ double latitude = coordinate.latitude();
112
+ double longitude = coordinate.longitude();
113
+
114
+ CLLocationCoordinate2D location = CLLocationCoordinate2DMake(latitude,longitude);
115
+
116
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
117
+ resolve([mapView getPointForCoordinates:location]);
118
+
119
+ } reject:reject];
120
+
121
+ }
122
+ - (void)getCoordinateForPoint:(double)tag
123
+ point:(JS::NativeAirMapsModule::Point &)point
124
+ resolve:(RCTPromiseResolveBlock)resolve
125
+ reject:(RCTPromiseRejectBlock)reject
126
+ {
127
+ double x = point.x();
128
+ double y = point.y();
129
+ CGPoint pt = CGPointMake(x,y);
130
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
131
+ resolve([mapView getCoordinatesForPoint:pt]);
132
+ } reject:reject];
133
+
134
+ }
135
+
136
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
137
+ (const facebook::react::ObjCTurboModule::InitParams &)params
138
+ {
139
+ return std::make_shared<facebook::react::NativeAirMapsModuleSpecJSI>(params);
140
+ }
141
+
142
+ + (NSString *)moduleName {
143
+ return nil;
144
+ }
145
+
146
+
147
+
148
+ @end
149
+
@@ -0,0 +1,24 @@
1
+ //
2
+ // RNMapsMarker.h
3
+ // AirMaps
4
+ //
5
+ // Created by Salah Ghanim on 23.11.24.
6
+ // Copyright © 2024 react-native-maps. All rights reserved.
7
+ //
8
+ #ifdef RCT_NEW_ARCH_ENABLED
9
+
10
+ #import <React/RCTViewComponentView.h>
11
+ #import <UIKit/UIKit.h>
12
+ #import "RNMapsHostVewDelegate.h"
13
+
14
+ @class AIRMap;
15
+
16
+ NS_ASSUME_NONNULL_BEGIN
17
+
18
+ @interface RNMapsMapView : RCTViewComponentView<RNMapsHostVewDelegate>
19
+
20
+ @end
21
+
22
+ NS_ASSUME_NONNULL_END
23
+
24
+ #endif