react-native-maps 1.21.0-alpha.7 → 1.21.0-alpha.9

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.
@@ -13,10 +13,10 @@
13
13
  #import <GoogleMaps/GoogleMaps.h>
14
14
  #import <MapKit/MapKit.h>
15
15
  #import "AIRGMSMarker.h"
16
-
16
+ #import "RNMapsAirModuleDelegate.h"
17
17
  #import "AIRGoogleMapCoordinate.h"
18
18
 
19
- @interface AIRGoogleMap : GMSMapView
19
+ @interface AIRGoogleMap : GMSMapView <RNMapsAirModuleDelegate>
20
20
 
21
21
  // TODO: don't use MK region?
22
22
  @property (nonatomic, weak) RCTBridge *bridge;
@@ -748,6 +748,63 @@ id regionAsJSON(MKCoordinateRegion region) {
748
748
  return [map cameraForBounds:bounds insets:UIEdgeInsetsZero];
749
749
  }
750
750
 
751
+ #pragma mark - RNMapsAirModuleDelegate
752
+
753
+ - (NSDictionary *) getCoordinatesForPoint:(CGPoint)point
754
+ {
755
+ CLLocationCoordinate2D coordinate = [self.projection coordinateForPoint:point];
756
+ return @{
757
+ @"latitude": @(coordinate.latitude),
758
+ @"longitude": @(coordinate.longitude),
759
+ };
760
+ }
761
+
762
+ - (NSDictionary *) getPointForCoordinates:(CLLocationCoordinate2D)location
763
+ {
764
+ CGPoint touchPoint = [self.projection pointForCoordinate:location];
765
+ return @{
766
+ @"x": @(touchPoint.x),
767
+ @"y": @(touchPoint.y),
768
+ };
769
+ }
770
+
771
+ -(void) takeSnapshotWithConfig:(NSDictionary *)config callback:(RCTPromiseResolveBlock) callback
772
+ {
773
+ /* unused
774
+ NSNumber *width = [config objectForKey:@"width"];
775
+ NSNumber *height = [config objectForKey:@"height"];
776
+ */
777
+ NSNumber *quality = [config objectForKey:@"quality"];
778
+
779
+ NSString *format = [config objectForKey:@"format"];
780
+ NSString *result = [config objectForKey:@"result"];
781
+ NSString *filePath = [config objectForKey:@"filePath"];
782
+
783
+
784
+ // TODO: currently we are ignoring width, height, region
785
+
786
+ UIGraphicsBeginImageContextWithOptions(self.frame.size, YES, 0.0f);
787
+ [self.layer renderInContext:UIGraphicsGetCurrentContext()];
788
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
789
+
790
+ NSData *data;
791
+ if ([format isEqualToString:@"png"]) {
792
+ data = UIImagePNGRepresentation(image);
793
+
794
+ } else if([format isEqualToString:@"jpg"]) {
795
+ data = UIImageJPEGRepresentation(image, quality.floatValue);
796
+ }
797
+
798
+ if ([result isEqualToString:@"file"]) {
799
+ [data writeToFile:filePath atomically:YES];
800
+ callback(filePath);
801
+ } else if ([result isEqualToString:@"base64"]) {
802
+ callback([data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]);
803
+ }
804
+
805
+ UIGraphicsEndImageContext();
806
+ }
807
+
751
808
  #pragma mark - Utils
752
809
 
753
810
  - (CGRect) frameForMarker:(AIRGoogleMapMarker*) mrkView {
@@ -253,7 +253,7 @@ RCT_EXPORT_METHOD(takeSnapshot:(nonnull NSNumber *)reactTag
253
253
  format:(nonnull NSString *)format
254
254
  quality:(nonnull NSNumber *)quality
255
255
  result:(nonnull NSString *)result
256
- withCallback:(RCTResponseSenderBlock)callback)
256
+ withCallback:(RCTPromiseResolveBlock)callback)
257
257
  {
258
258
  NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
259
259
  NSString *pathComponent = [NSString stringWithFormat:@"Documents/snapshot-%.20lf.%@", timeStamp, format];
@@ -264,7 +264,17 @@ RCT_EXPORT_METHOD(takeSnapshot:(nonnull NSNumber *)reactTag
264
264
  if (![view isKindOfClass:[AIRGoogleMap class]]) {
265
265
  RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
266
266
  } else {
267
- AIRGoogleMap *mapView = (AIRGoogleMap *)view;
267
+ AIRGoogleMap *mapView = (AIRGoogleMap *)view;
268
+ NSMutableDictionary* config = [NSMutableDictionary new];
269
+
270
+ [mapView takeSnapshotWithConfig:config callback:callback];
271
+
272
+ [config setObject:width forKey:@"width"];
273
+ [config setObject:height forKey:@"height"];
274
+ [config setObject:format forKey:@"format"];
275
+ [config setObject:quality forKey:@"quality"];
276
+ [config setObject:result forKey:@"result"];
277
+ [config setObject:filePath forKey:@"filePath"];
268
278
 
269
279
  // TODO: currently we are ignoring width, height, region
270
280
 
@@ -310,13 +320,7 @@ RCT_EXPORT_METHOD(pointForCoordinate:(nonnull NSNumber *)reactTag
310
320
  RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
311
321
  } else {
312
322
  AIRGoogleMap *mapView = (AIRGoogleMap *)view;
313
-
314
- CGPoint touchPoint = [mapView.projection pointForCoordinate:coord];
315
-
316
- resolve(@{
317
- @"x": @(touchPoint.x),
318
- @"y": @(touchPoint.y),
319
- });
323
+ resolve([mapView getPointForCoordinates:coord]);
320
324
  }
321
325
  }];
322
326
  }
@@ -337,13 +341,7 @@ RCT_EXPORT_METHOD(coordinateForPoint:(nonnull NSNumber *)reactTag
337
341
  RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
338
342
  } else {
339
343
  AIRGoogleMap *mapView = (AIRGoogleMap *)view;
340
-
341
- CLLocationCoordinate2D coordinate = [mapView.projection coordinateForPoint:pt];
342
-
343
- resolve(@{
344
- @"latitude": @(coordinate.latitude),
345
- @"longitude": @(coordinate.longitude),
346
- });
344
+ resolve([view getCoordinatesForPoint:pt]);
347
345
  }
348
346
  }];
349
347
  }
@@ -373,18 +371,7 @@ RCT_EXPORT_METHOD(getMapBoundaries:(nonnull NSNumber *)reactTag
373
371
  if (![view isKindOfClass:[AIRGoogleMap class]]) {
374
372
  RCTLogError(@"Invalid view returned from registry, expecting AIRGoogleMap, got: %@", view);
375
373
  } else {
376
- NSArray *boundingBox = [view getMapBoundaries];
377
-
378
- resolve(@{
379
- @"northEast" : @{
380
- @"longitude" : boundingBox[0][0],
381
- @"latitude" : boundingBox[0][1]
382
- },
383
- @"southWest" : @{
384
- @"longitude" : boundingBox[1][0],
385
- @"latitude" : boundingBox[1][1]
386
- }
387
- });
374
+ resolve([view getMapBoundaries]);
388
375
  }
389
376
  }];
390
377
  }
@@ -9,9 +9,12 @@
9
9
  #import <Foundation/Foundation.h>
10
10
  #import <GoogleMaps/GoogleMaps.h>
11
11
  #import <React/RCTConvert.h>
12
+ #import "AIRGoogleMapCoordinate.h"
12
13
 
13
14
  @interface RCTConvert (GMSMapViewType)
14
15
  + (GMSCameraPosition*)GMSCameraPositionWithDefaults:(id)json existingCamera:(GMSCameraPosition*)existingCamera;
16
+ + (NSArray<NSArray<AIRGoogleMapCoordinate *> *> *)AIRGoogleMapCoordinateArrayArray:(id)json;
17
+ + (AIRGoogleMapCoordinate *)AIRGoogleMapCoordinate:(id)json;
15
18
  @end
16
19
 
17
20
  #endif
@@ -10,13 +10,13 @@
10
10
 
11
11
  #import <React/RCTViewComponentView.h>
12
12
  #import <UIKit/UIKit.h>
13
+ #import "RNMapsHostVewDelegate.h"
14
+
13
15
  @class AIRGoogleMap;
14
16
 
15
17
  NS_ASSUME_NONNULL_BEGIN
16
18
 
17
- @interface RNMapsGoogleMapView : RCTViewComponentView
18
-
19
- - (AIRGoogleMap *) mapView;
19
+ @interface RNMapsGoogleMapView : RCTViewComponentView<RNMapsHostVewDelegate>
20
20
 
21
21
  @end
22
22
 
@@ -34,7 +34,7 @@ using namespace facebook::react;
34
34
  }
35
35
 
36
36
 
37
- - (AIRGoogleMap *) mapView {
37
+ - (id<RNMapsAirModuleDelegate>) mapView {
38
38
  return _view;
39
39
  }
40
40
 
@@ -73,10 +73,14 @@ using namespace facebook::react;
73
73
  }
74
74
  - (void)fitToCoordinates:(NSString *)coordinatesJSON edgePaddingJSON:(NSString *)edgePaddingJSON animated:(BOOL)animated {
75
75
  NSArray* coordinatesArr = [RCTConvert arrayFromString:coordinatesJSON];
76
+ NSMutableArray<AIRGoogleMapCoordinate*>* coordinatesArray = [NSMutableArray new];
77
+ for (id json : coordinatesArr){
78
+ [coordinatesArray addObject:[RCTConvert AIRGoogleMapCoordinate:json]];
79
+ }
76
80
 
77
81
  NSDictionary* edgePadding = [RCTConvert dictonaryFromString:edgePaddingJSON];
78
82
 
79
- // [_view fitToCoordinates:coordinatesArr withEdgePadding:edgePadding animated:animated];
83
+ [_view fitToCoordinates:coordinatesArray withEdgePadding:edgePadding animated:animated];
80
84
  }
81
85
 
82
86
  #pragma mark - Native commands
@@ -128,7 +132,6 @@ using namespace facebook::react;
128
132
 
129
133
  _view.onMapReady = [self](NSDictionary* dictionary) {
130
134
  if (_eventEmitter) {
131
- NSLog(@"mapReady");
132
135
  auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
133
136
  facebook::react::RNMapsGoogleMapViewEventEmitter::OnMapReady data = {};
134
137
  mapViewEventEmitter->onMapReady(data);
@@ -137,7 +140,6 @@ using namespace facebook::react;
137
140
 
138
141
  _view.onMapLoaded = [self](NSDictionary* dictionary) {
139
142
  if (_eventEmitter) {
140
- NSLog(@"mapLoaded");
141
143
  auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
142
144
  facebook::react::RNMapsGoogleMapViewEventEmitter::OnMapLoaded data = {};
143
145
  mapViewEventEmitter->onMapLoaded(data);
@@ -14,14 +14,16 @@
14
14
  #import "SMCalloutView.h"
15
15
  #import "RCTConvert+AirMap.h"
16
16
  #import "AIRMapCalloutSubview.h"
17
+ #import "RNMapsAirModuleDelegate.h"
17
18
 
19
+ @class AIRMapCoordinate;
18
20
  @class AIRMapMarker;
19
21
 
20
22
  extern const NSTimeInterval AIRMapRegionChangeObserveInterval;
21
23
  extern const CGFloat AIRMapZoomBoundBuffer;
22
24
  extern const NSInteger AIRMapMaxZoomLevel;
23
25
 
24
- @interface AIRMap: MKMapView<SMCalloutViewDelegate>
26
+ @interface AIRMap: MKMapView<SMCalloutViewDelegate, RNMapsAirModuleDelegate>
25
27
 
26
28
  @property (nonatomic, strong) SMCalloutView *calloutView;
27
29
  @property (nonatomic, strong) UIImageView *cacheImageView;
@@ -80,5 +82,5 @@ extern const NSInteger AIRMapMaxZoomLevel;
80
82
  - (AIRMapMarker*) markerAtPoint:(CGPoint)point;
81
83
  - (NSDictionary*) getMarkersFramesWithOnlyVisible:(BOOL)onlyVisible;
82
84
  - (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex;
83
-
85
+ -(void) fitToCoordinates:(NSArray<AIRMapCoordinate*>*) coordinates edgePadding:(UIEdgeInsets) edgeInsets animated:(Boolean) animated;
84
86
  @end
@@ -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;
@@ -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
  {
@@ -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
  }
@@ -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;
@@ -16,4 +18,6 @@
16
18
  + (MKMapType)MKMapType:(id)json;
17
19
  + (NSDictionary*) dictonaryFromString:(NSString *) str;
18
20
  + (NSArray*) arrayFromString:(NSString *) str;
21
+ + (NSArray<NSArray<AIRMapCoordinate *> *> *)AIRMapCoordinateArrayArray:(id)json;
22
+ + (AIRMapCoordinate*) AIRMapCoordinate:(id)json;
19
23
  @end
@@ -27,6 +27,7 @@
27
27
  };
28
28
  }
29
29
 
30
+
30
31
  + (MKMapCamera*)MKMapCamera:(id)json
31
32
  {
32
33
  json = [self NSDictionary:json];
@@ -49,6 +50,7 @@
49
50
  error:&jsonError];
50
51
  }
51
52
 
53
+
52
54
  + (MKMapCamera*)MKMapCameraWithDefaults:(id)json existingCamera:(MKMapCamera*)camera
53
55
  {
54
56
  json = [self NSDictionary:json];
@@ -20,15 +20,15 @@
20
20
  @synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED;
21
21
 
22
22
  - (void)executeWithMapView:(double)tag
23
- success:(void (^)(AIRMap *mapView))success
23
+ success:(void (^)(id<RNMapsAirModuleDelegate> mapView))success
24
24
  reject:(RCTPromiseRejectBlock)reject {
25
25
  dispatch_async(dispatch_get_main_queue(), ^{
26
26
  id view = [_viewRegistry_DEPRECATED viewForReactTag:[NSNumber numberWithDouble:tag]];
27
- if (![view isKindOfClass:[RNMapsMapView class]]) {
28
- reject(@"Invalid argument", [NSString stringWithFormat:@"Invalid view returned from registry, expecting RNMapsMapView, got: %@", view], NULL);
27
+ if ([view conformsToProtocol:@protocol(RNMapsHostVewDelegate)]) {
28
+ id<RNMapsAirModuleDelegate> mapViewDelegate = [view mapView];
29
+ success(mapViewDelegate);
29
30
  } else {
30
- AIRMap *mapView = [view mapView];
31
- success(mapView);
31
+ reject(@"Invalid argument", [NSString stringWithFormat:@"Invalid view returned from registry, expecting RNMapsMapView, got: %@", view], NULL);
32
32
  }
33
33
  });
34
34
  }
@@ -36,17 +36,8 @@
36
36
  - (void)getCamera:(double)tag
37
37
  resolve:(RCTPromiseResolveBlock)resolve
38
38
  reject:(RCTPromiseRejectBlock)reject {
39
- [self executeWithMapView:tag success:^(AIRMap *mapView) {
40
- MKMapCamera *camera = [mapView camera];
41
- resolve(@{
42
- @"center": @{
43
- @"latitude": @(camera.centerCoordinate.latitude),
44
- @"longitude": @(camera.centerCoordinate.longitude),
45
- },
46
- @"pitch": @(camera.pitch),
47
- @"heading": @(camera.heading),
48
- @"altitude": @(camera.altitude),
49
- });
39
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
40
+ resolve([mapView getCamera]);
50
41
  } reject:reject];
51
42
 
52
43
  }
@@ -56,7 +47,7 @@
56
47
  resolve:(RCTPromiseResolveBlock)resolve
57
48
  reject:(RCTPromiseRejectBlock)reject
58
49
  {
59
- [self executeWithMapView:tag success:^(AIRMap *mapView) {
50
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
60
51
  resolve([mapView getMarkersFramesWithOnlyVisible:onlyVisible]);
61
52
  } reject:reject];
62
53
  }
@@ -64,7 +55,7 @@
64
55
  resolve:(RCTPromiseResolveBlock)resolve
65
56
  reject:(RCTPromiseRejectBlock)reject
66
57
  {
67
- [self executeWithMapView:tag success:^(AIRMap *mapView) {
58
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
68
59
  resolve([mapView getMapBoundaries]);
69
60
  } reject:reject];
70
61
  }
@@ -73,42 +64,11 @@
73
64
  resolve:(RCTPromiseResolveBlock)resolve
74
65
  reject:(RCTPromiseRejectBlock)reject
75
66
  {
76
-
77
- [self executeWithMapView:tag success:^(AIRMap *mapView) {
78
-
79
- MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
80
-
81
- options.mapType = mapView.mapType;
82
- NSNumber *width = config[@"width"];
83
- NSNumber *height = config[@"height"];
84
- NSNumber *quality = config[@"quality"];
85
- NSString*format =config[@"format"];
86
- NSString*result =config[@"result"];
87
- MKCoordinateRegion region = [RCTConvert MKCoordinateRegion:config[@"region"]];
88
-
89
-
90
- options.region = (region.center.latitude && region.center.longitude) ? region : mapView.region;
91
- options.size = CGSizeMake(
92
- ([width floatValue] == 0) ? mapView.bounds.size.width : [width floatValue],
93
- ([height floatValue] == 0) ? mapView.bounds.size.height : [height floatValue]
94
- );
95
-
96
- options.scale = [[UIScreen mainScreen] scale];
97
-
98
-
99
- MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
100
-
101
- [self takeMapSnapshot:mapView
102
- snapshotter:snapshotter
103
- format:format
104
- quality:[quality floatValue]
105
- result:result
106
- callback:resolve];
107
-
67
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
68
+ [mapView takeSnapshotWithConfig:config callback:resolve];
108
69
  } reject:reject];
109
-
110
-
111
70
  }
71
+
112
72
  - (void)getAddressFromCoordinates:(double)tag
113
73
  coordinate:(JS::NativeAirMapsModule::LatLng &)coordinate
114
74
  resolve:(RCTPromiseResolveBlock)resolve
@@ -117,32 +77,30 @@
117
77
  double latitude = coordinate.latitude();
118
78
  double longitude = coordinate.longitude();
119
79
 
120
- [self executeWithMapView:tag success:^(AIRMap *mapView) {
121
- CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude
80
+
81
+ CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude
122
82
  longitude:longitude];
123
- CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
124
- [geoCoder reverseGeocodeLocation:location
83
+ CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
84
+ [geoCoder reverseGeocodeLocation:location
125
85
  completionHandler:^(NSArray *placemarks, NSError *error) {
126
- if (error == nil && [placemarks count] > 0){
127
- CLPlacemark *placemark = placemarks[0];
128
- resolve(@{
129
- @"name" : [NSString stringWithFormat:@"%@", placemark.name],
130
- @"thoroughfare" : [NSString stringWithFormat:@"%@", placemark.thoroughfare],
131
- @"subThoroughfare" : [NSString stringWithFormat:@"%@", placemark.subThoroughfare],
132
- @"locality" : [NSString stringWithFormat:@"%@", placemark.locality],
133
- @"subLocality" : [NSString stringWithFormat:@"%@", placemark.subLocality],
134
- @"administrativeArea" : [NSString stringWithFormat:@"%@", placemark.administrativeArea],
135
- @"subAdministrativeArea" : [NSString stringWithFormat:@"%@", placemark.subAdministrativeArea],
136
- @"postalCode" : [NSString stringWithFormat:@"%@", placemark.postalCode],
137
- @"countryCode" : [NSString stringWithFormat:@"%@", placemark.ISOcountryCode],
138
- @"country" : [NSString stringWithFormat:@"%@", placemark.country],
139
- });
140
- } else {
141
- reject(@"Invalid argument", [NSString stringWithFormat:@"Can not get address location"], NULL);
142
- }
143
- }];
144
-
145
- } reject:reject];
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
+ }];
146
104
  }
147
105
 
148
106
  - (void)getPointForCoordinate:(double)tag
@@ -153,16 +111,10 @@
153
111
  double latitude = coordinate.latitude();
154
112
  double longitude = coordinate.longitude();
155
113
 
156
- [self executeWithMapView:tag success:^(AIRMap *mapView) {
114
+ CLLocationCoordinate2D location = CLLocationCoordinate2DMake(latitude,longitude);
157
115
 
158
- CGPoint touchPoint = [mapView convertCoordinate:
159
- CLLocationCoordinate2DMake(latitude,longitude)
160
- toPointToView:mapView];
161
-
162
- resolve(@{
163
- @"x": @(touchPoint.x),
164
- @"y": @(touchPoint.y),
165
- });
116
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
117
+ resolve([mapView getPointForCoordinates:location]);
166
118
 
167
119
  } reject:reject];
168
120
 
@@ -174,20 +126,10 @@
174
126
  {
175
127
  double x = point.x();
176
128
  double y = point.y();
177
-
178
- [self executeWithMapView:tag success:^(AIRMap *mapView) {
179
-
180
-
181
- CLLocationCoordinate2D coordinate = [mapView convertPoint:CGPointMake(x,y)
182
- toCoordinateFromView:mapView];
183
-
184
- resolve(@{
185
- @"latitude": @(coordinate.latitude),
186
- @"longitude": @(coordinate.longitude),
187
- });
188
-
129
+ CGPoint pt = CGPointMake(x,y);
130
+ [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
131
+ resolve([mapView getCoordinatesForPoint:pt]);
189
132
  } reject:reject];
190
-
191
133
 
192
134
  }
193
135
 
@@ -201,80 +143,7 @@
201
143
  return nil;
202
144
  }
203
145
 
204
- #pragma mark Take Snapshot
205
- - (void)takeMapSnapshot:(AIRMap *)mapView
206
- snapshotter:(MKMapSnapshotter *) snapshotter
207
- format:(NSString *)format
208
- quality:(CGFloat) quality
209
- result:(NSString *)result
210
- callback:(RCTPromiseResolveBlock) callback {
211
- NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
212
- NSString *pathComponent = [NSString stringWithFormat:@"Documents/snapshot-%.20lf.%@", timeStamp, format];
213
- NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent: pathComponent];
214
-
215
- [snapshotter startWithQueue:dispatch_get_main_queue()
216
- completionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
217
- if (error) {
218
- callback(@[error]);
219
- return;
220
- }
221
- MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:nil];
222
-
223
- UIImage *image = snapshot.image;
224
- UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale);
225
- {
226
- [image drawAtPoint:CGPointMake(0.0f, 0.0f)];
227
-
228
- CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
229
146
 
230
- for (id <AIRMapSnapshot> overlay in mapView.overlays) {
231
- if ([overlay respondsToSelector:@selector(drawToSnapshot:context:)]) {
232
- [overlay drawToSnapshot:snapshot context:UIGraphicsGetCurrentContext()];
233
- }
234
- }
235
-
236
- for (id <MKAnnotation> annotation in mapView.annotations) {
237
- CGPoint point = [snapshot pointForCoordinate:annotation.coordinate];
238
-
239
- MKAnnotationView* anView = [mapView viewForAnnotation: annotation];
240
-
241
- if (anView){
242
- pin = anView;
243
- }
244
-
245
- if (CGRectContainsPoint(rect, point)) {
246
- point.x = point.x + pin.centerOffset.x - (pin.bounds.size.width / 2.0f);
247
- point.y = point.y + pin.centerOffset.y - (pin.bounds.size.height / 2.0f);
248
- if (pin.image) {
249
- [pin.image drawAtPoint:point];
250
- } else {
251
- CGRect pinRect = CGRectMake(point.x, point.y, pin.bounds.size.width, pin.bounds.size.height);
252
- [pin drawViewHierarchyInRect:pinRect afterScreenUpdates:NO];
253
- }
254
- }
255
- }
256
-
257
- UIImage *compositeImage = UIGraphicsGetImageFromCurrentImageContext();
258
-
259
- NSData *data;
260
- if ([format isEqualToString:@"png"]) {
261
- data = UIImagePNGRepresentation(compositeImage);
262
- }
263
- else if([format isEqualToString:@"jpg"]) {
264
- data = UIImageJPEGRepresentation(compositeImage, quality);
265
- }
266
-
267
- if ([result isEqualToString:@"file"]) {
268
- [data writeToFile:filePath atomically:YES];
269
- callback(filePath);
270
- }
271
- else if ([result isEqualToString:@"base64"]) {
272
- callback([data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]);
273
- }
274
- }
275
- UIGraphicsEndImageContext();
276
- }];
277
- }
278
147
 
279
148
  @end
280
149
 
@@ -9,13 +9,13 @@
9
9
 
10
10
  #import <React/RCTViewComponentView.h>
11
11
  #import <UIKit/UIKit.h>
12
+ #import "RNMapsHostVewDelegate.h"
13
+
12
14
  @class AIRMap;
13
15
 
14
16
  NS_ASSUME_NONNULL_BEGIN
15
17
 
16
- @interface RNMapsMapView : RCTViewComponentView
17
-
18
- - (AIRMap *) mapView;
18
+ @interface RNMapsMapView : RCTViewComponentView<RNMapsHostVewDelegate>
19
19
 
20
20
  @end
21
21
 
@@ -29,7 +29,7 @@ using namespace facebook::react;
29
29
  }
30
30
 
31
31
 
32
- - (AIRMap *) mapView {
32
+ - (id<RNMapsAirModuleDelegate>) mapView {
33
33
  return _view;
34
34
  }
35
35
 
@@ -76,6 +76,16 @@ using namespace facebook::react;
76
76
 
77
77
  }
78
78
  - (void)fitToCoordinates:(NSString *)coordinatesJSON edgePaddingJSON:(NSString *)edgePaddingJSON animated:(BOOL)animated {
79
+ NSArray* coordinatesArr = [RCTConvert arrayFromString:coordinatesJSON];
80
+ NSMutableArray<AIRMapCoordinate*>* mutableArray = [NSMutableArray new];
81
+ for (id json : coordinatesArr){
82
+ [mutableArray addObject:[RCTConvert AIRMapCoordinate:json]];
83
+ }
84
+
85
+ NSDictionary* edgePadding = [RCTConvert dictonaryFromString:edgePaddingJSON];
86
+
87
+ UIEdgeInsets edgeInsets = [RCTConvert UIEdgeInsets:edgePadding];
88
+ [_view fitToCoordinates:mutableArray edgePadding:edgeInsets animated:animated];
79
89
 
80
90
  }
81
91
 
package/lib/MapView.js CHANGED
@@ -31,7 +31,11 @@ const React = __importStar(require("react"));
31
31
  const react_native_1 = require("react-native");
32
32
  const decorateMapComponent_1 = require("./decorateMapComponent");
33
33
  const MapViewNativeComponent_1 = require("./MapViewNativeComponent");
34
- const FabricMapView_1 = __importDefault(require("./FabricMapView"));
34
+ const NativeComponentMapView_1 = __importStar(require("./specs/NativeComponentMapView"));
35
+ const NativeComponentGoogleMapView_1 = __importStar(require("./specs/NativeComponentGoogleMapView"));
36
+ const createFabricMap_1 = __importDefault(require("./createFabricMap"));
37
+ const FabricMap = (0, createFabricMap_1.default)(NativeComponentMapView_1.default, NativeComponentMapView_1.Commands);
38
+ const FabricGoogleMap = (0, createFabricMap_1.default)(NativeComponentGoogleMapView_1.default, NativeComponentGoogleMapView_1.Commands);
35
39
  exports.MAP_TYPES = {
36
40
  STANDARD: 'standard',
37
41
  SATELLITE: 'satellite',
@@ -342,10 +346,9 @@ class MapView extends React.Component {
342
346
  };
343
347
  render() {
344
348
  if (react_native_1.Platform.OS === 'ios') {
345
- const AIRMap = FabricMapView_1.default;
346
349
  // Define props specifically for MapFabricNativeProps
347
350
  /* eslint-disable @typescript-eslint/no-unused-vars */
348
- const { onCalloutPress, onIndoorBuildingFocused, onKmlReady, onLongPress, onMarkerDeselect, onMarkerPress, onMarkerSelect, onRegionChangeStart, onRegionChange, onRegionChangeComplete, onPress, minZoomLevel, maxZoomLevel, region, ...restProps } = this.props;
351
+ const { onCalloutPress, onIndoorBuildingFocused, onKmlReady, onLongPress, onMarkerDeselect, onMarkerPress, onMarkerSelect, onRegionChangeStart, onRegionChange, onRegionChangeComplete, onPress, minZoomLevel, maxZoomLevel, region, provider, ...restProps } = this.props;
349
352
  /* eslint-enable @typescript-eslint/no-unused-vars */
350
353
  const userInterfaceStyle = this.props.userInterfaceStyle || 'system';
351
354
  const props = {
@@ -376,10 +379,16 @@ class MapView extends React.Component {
376
379
  props.initialCamera = this.props.initialCamera;
377
380
  props.onLayout = this.props.onLayout;
378
381
  }
379
- // Render AIRMap with MapFabricNativeProps
380
- return (<decorateMapComponent_1.ProviderContext.Provider value={this.props.provider}>
381
- <AIRMap {...props} ref={this.fabricMap}/>
382
- </decorateMapComponent_1.ProviderContext.Provider>);
382
+ if (provider === 'google') {
383
+ return (<decorateMapComponent_1.ProviderContext.Provider value={this.props.provider}>
384
+ <FabricGoogleMap {...props} ref={this.fabricMap}/>
385
+ </decorateMapComponent_1.ProviderContext.Provider>);
386
+ }
387
+ else {
388
+ return (<decorateMapComponent_1.ProviderContext.Provider value={this.props.provider}>
389
+ <FabricMap {...props} ref={this.fabricMap}/>
390
+ </decorateMapComponent_1.ProviderContext.Provider>);
391
+ }
383
392
  }
384
393
  else {
385
394
  const AIRMap = getNativeMapComponent(this.props.provider);
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
- import type { MapBoundaries } from './specs/NativeAirMapsModule';
3
- import type { MapFabricNativeProps, Camera, Point } from './specs/NativeComponentMapView';
4
- import { LatLng, Provider, Region } from './sharedTypes';
5
- import { Address, EdgePadding, SnapshotOptions } from './MapView.types';
2
+ import type { LatLng, Point, Region } from './sharedTypes';
3
+ import type { Address, Camera, EdgePadding, SnapshotOptions } from './MapView.types';
4
+ import { MapBoundaries } from './specs/NativeAirMapsModule';
5
+ import { MapFabricNativeProps } from './specs/NativeComponentMapView';
6
+ export type FabricMapViewProps = MapFabricNativeProps;
6
7
  export interface FabricMapHandle {
7
8
  getCamera: () => Promise<Camera>;
8
9
  setCamera: (camera: Partial<Camera>) => void;
@@ -18,10 +19,5 @@ export interface FabricMapHandle {
18
19
  getPointForCoordinate: (coordinate: LatLng) => Promise<Point>;
19
20
  getCoordinateForPoint: (point: Point) => Promise<LatLng>;
20
21
  }
21
- export type FabricMapViewProps = MapFabricNativeProps & {
22
- provider?: Provider;
23
- };
24
- export declare const FabricMap: React.ForwardRefExoticComponent<MapFabricNativeProps & {
25
- provider?: Provider;
26
- } & React.RefAttributes<FabricMapHandle>>;
27
- export default FabricMap;
22
+ declare const createFabricMap: (ViewComponent: React.ComponentType, Commands: any) => React.ForwardRefExoticComponent<MapFabricNativeProps & React.RefAttributes<FabricMapHandle>>;
23
+ export default createFabricMap;
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const react_1 = __importStar(require("react"));
30
+ const react_native_1 = require("react-native");
31
+ const NativeAirMapsModule_1 = __importDefault(require("./specs/NativeAirMapsModule"));
32
+ const createFabricMap = (ViewComponent, Commands) => {
33
+ return (0, react_1.forwardRef)((props, ref) => {
34
+ const fabricRef = (0, react_1.useRef)(null);
35
+ (0, react_1.useImperativeHandle)(ref, () => ({
36
+ async getMarkersFrames(onlyVisible) {
37
+ if (fabricRef.current) {
38
+ return NativeAirMapsModule_1.default.getMarkersFrames((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, onlyVisible);
39
+ }
40
+ else {
41
+ throw new Error('getMarkersFrames is only supported on iOS with Fabric.');
42
+ }
43
+ },
44
+ async getCoordinateForPoint(point) {
45
+ if (fabricRef.current) {
46
+ return NativeAirMapsModule_1.default.getCoordinateForPoint((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, point);
47
+ }
48
+ else {
49
+ throw new Error('getCoordinateForPoint is only supported on iOS with Fabric.');
50
+ }
51
+ },
52
+ async getPointForCoordinate(coordinate) {
53
+ if (fabricRef.current) {
54
+ return NativeAirMapsModule_1.default.getPointForCoordinate((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, coordinate);
55
+ }
56
+ else {
57
+ throw new Error('getPointForCoordinate is only supported on iOS with Fabric.');
58
+ }
59
+ },
60
+ async getAddressFromCoordinates(coordinate) {
61
+ if (fabricRef.current) {
62
+ return NativeAirMapsModule_1.default.getAddressFromCoordinates((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, coordinate);
63
+ }
64
+ else {
65
+ throw new Error('getAddressFromCoordinates is only supported on iOS with Fabric.');
66
+ }
67
+ },
68
+ async takeSnapshot(config) {
69
+ if (fabricRef.current) {
70
+ return NativeAirMapsModule_1.default.takeSnapshot((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, config);
71
+ }
72
+ else {
73
+ throw new Error('takeSnapshot is only supported on iOS with Fabric.');
74
+ }
75
+ },
76
+ async getCamera() {
77
+ if (fabricRef.current) {
78
+ return NativeAirMapsModule_1.default.getCamera((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1);
79
+ }
80
+ else {
81
+ throw new Error('getCamera is only supported on iOS with Fabric.');
82
+ }
83
+ },
84
+ async getMapBoundaries() {
85
+ if (fabricRef.current) {
86
+ return NativeAirMapsModule_1.default.getMapBoundaries((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1);
87
+ }
88
+ else {
89
+ throw new Error('getMapBoundaries is only supported on iOS with Fabric.');
90
+ }
91
+ },
92
+ animateToRegion(region, duration) {
93
+ if (fabricRef.current) {
94
+ try {
95
+ Commands.animateToRegion(fabricRef.current, JSON.stringify(region), duration);
96
+ }
97
+ catch (error) {
98
+ throw new Error('Failed to animateToRegion');
99
+ }
100
+ }
101
+ else {
102
+ throw new Error('animateToRegion is only supported on iOS with Fabric.');
103
+ }
104
+ },
105
+ fitToElements(edgePadding, animated) {
106
+ if (fabricRef.current) {
107
+ try {
108
+ Commands.fitToElements(fabricRef.current, JSON.stringify(edgePadding), animated);
109
+ }
110
+ catch (error) {
111
+ throw new Error('Failed to fitToElements');
112
+ }
113
+ }
114
+ else {
115
+ throw new Error('fitToElements is only supported on iOS with Fabric.');
116
+ }
117
+ },
118
+ fitToSuppliedMarkers(markers, edgePadding, animated) {
119
+ if (fabricRef.current) {
120
+ try {
121
+ Commands.fitToSuppliedMarkers(fabricRef.current, JSON.stringify(markers), JSON.stringify(edgePadding), animated);
122
+ }
123
+ catch (error) {
124
+ throw new Error('Failed to fitToSuppliedMarkers');
125
+ }
126
+ }
127
+ else {
128
+ throw new Error('fitToSuppliedMarkers is only supported on iOS with Fabric.');
129
+ }
130
+ },
131
+ animateCamera(camera, duration) {
132
+ if (fabricRef.current) {
133
+ try {
134
+ Commands.animateCamera(fabricRef.current, JSON.stringify(camera), duration);
135
+ }
136
+ catch (error) {
137
+ throw new Error('Failed to animateCamera');
138
+ }
139
+ }
140
+ else {
141
+ throw new Error('animateCamera is only supported on iOS with Fabric.');
142
+ }
143
+ },
144
+ fitToCoordinates(coordinates, edgePadding, animated) {
145
+ if (fabricRef.current) {
146
+ try {
147
+ Commands.fitToCoordinates(fabricRef.current, JSON.stringify(coordinates), JSON.stringify(edgePadding), animated);
148
+ }
149
+ catch (error) {
150
+ throw new Error('Failed to fitToCoordinates');
151
+ }
152
+ }
153
+ else {
154
+ throw new Error('fitToCoordinates is only supported on iOS with Fabric.');
155
+ }
156
+ },
157
+ setCamera(camera) {
158
+ if (fabricRef.current) {
159
+ try {
160
+ Commands.setCamera(fabricRef.current, JSON.stringify(camera));
161
+ }
162
+ catch (error) {
163
+ console.error('Failed to set camera:', error);
164
+ }
165
+ }
166
+ else {
167
+ console.warn('setCamera is only supported on iOS with Fabric.');
168
+ }
169
+ },
170
+ }));
171
+ // @ts-ignore
172
+ return <ViewComponent {...props} ref={fabricRef}/>;
173
+ });
174
+ };
175
+ exports.default = createFabricMap;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "main": "lib/index.js",
6
6
  "author": "Leland Richardson <leland.m.richardson@gmail.com>",
7
7
  "homepage": "https://github.com/react-native-maps/react-native-maps#readme",
8
- "version": "1.21.0-alpha.7",
8
+ "version": "1.21.0-alpha.9",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",
@@ -1,181 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.FabricMap = void 0;
30
- const react_1 = __importStar(require("react"));
31
- const NativeAirMapsModule_1 = __importDefault(require("./specs/NativeAirMapsModule"));
32
- const NativeComponentMapView_1 = __importStar(require("./specs/NativeComponentMapView"));
33
- const NativeComponentGoogleMapView_1 = __importDefault(require("./specs/NativeComponentGoogleMapView"));
34
- const react_native_1 = require("react-native");
35
- exports.FabricMap = (0, react_1.forwardRef)((props, ref) => {
36
- const fabricRef = (0, react_1.useRef)(null);
37
- // Use Imperative Handle to expose commands
38
- (0, react_1.useImperativeHandle)(ref, () => ({
39
- async getMarkersFrames(onlyVisible) {
40
- if (fabricRef.current) {
41
- return NativeAirMapsModule_1.default.getMarkersFrames((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, onlyVisible);
42
- }
43
- else {
44
- throw new Error('getMarkersFrames is only supported on iOS with Fabric.');
45
- }
46
- },
47
- async getCoordinateForPoint(point) {
48
- if (fabricRef.current) {
49
- return NativeAirMapsModule_1.default.getCoordinateForPoint((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, point);
50
- }
51
- else {
52
- throw new Error('getCoordinateForPoint is only supported on iOS with Fabric.');
53
- }
54
- },
55
- async getPointForCoordinate(coordinate) {
56
- if (fabricRef.current) {
57
- return NativeAirMapsModule_1.default.getPointForCoordinate((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, coordinate);
58
- }
59
- else {
60
- throw new Error('getPointForCoordinate is only supported on iOS with Fabric.');
61
- }
62
- },
63
- async getAddressFromCoordinates(coordinate) {
64
- if (fabricRef.current) {
65
- return NativeAirMapsModule_1.default.getAddressFromCoordinates((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, coordinate);
66
- }
67
- else {
68
- throw new Error('getAddressFromCoordinates is only supported on iOS with Fabric.');
69
- }
70
- },
71
- async takeSnapshot(config) {
72
- if (fabricRef.current) {
73
- return NativeAirMapsModule_1.default.takeSnapshot((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, config);
74
- }
75
- else {
76
- throw new Error('takeSnapshot is only supported on iOS with Fabric.');
77
- }
78
- },
79
- async getCamera() {
80
- if (fabricRef.current) {
81
- return NativeAirMapsModule_1.default.getCamera((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1);
82
- }
83
- else {
84
- throw new Error('getCamera is only supported on iOS with Fabric.');
85
- }
86
- },
87
- async getMapBoundaries() {
88
- if (fabricRef.current) {
89
- return NativeAirMapsModule_1.default.getMapBoundaries((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1);
90
- }
91
- else {
92
- throw new Error('getMapBoundaries is only supported on iOS with Fabric.');
93
- }
94
- },
95
- animateToRegion(region, duration) {
96
- if (fabricRef.current) {
97
- try {
98
- NativeComponentMapView_1.Commands.animateToRegion(fabricRef.current, JSON.stringify(region), duration);
99
- }
100
- catch (error) {
101
- throw new Error('Failed to animateToRegion');
102
- }
103
- }
104
- else {
105
- throw new Error('animateToRegion is only supported on iOS with Fabric.');
106
- }
107
- },
108
- fitToElements(edgePadding, animated) {
109
- if (fabricRef.current) {
110
- try {
111
- NativeComponentMapView_1.Commands.fitToElements(fabricRef.current, JSON.stringify(edgePadding), animated);
112
- }
113
- catch (error) {
114
- throw new Error('Failed to fitToElements');
115
- }
116
- }
117
- else {
118
- throw new Error('fitToElements is only supported on iOS with Fabric.');
119
- }
120
- },
121
- fitToSuppliedMarkers(markers, edgePadding, animated) {
122
- if (fabricRef.current) {
123
- try {
124
- NativeComponentMapView_1.Commands.fitToSuppliedMarkers(fabricRef.current, JSON.stringify(markers), JSON.stringify(edgePadding), animated);
125
- }
126
- catch (error) {
127
- throw new Error('Failed to fitToSuppliedMarkers');
128
- }
129
- }
130
- else {
131
- throw new Error('fitToSuppliedMarkers is only supported on iOS with Fabric.');
132
- }
133
- },
134
- animateCamera(camera, duration) {
135
- if (fabricRef.current) {
136
- try {
137
- NativeComponentMapView_1.Commands.animateCamera(fabricRef.current, JSON.stringify(camera), duration);
138
- }
139
- catch (error) {
140
- throw new Error('Failed to animateCamera');
141
- }
142
- }
143
- else {
144
- throw new Error('animateCamera is only supported on iOS with Fabric.');
145
- }
146
- },
147
- fitToCoordinates(coordinates, edgePadding, animated) {
148
- if (fabricRef.current) {
149
- try {
150
- NativeComponentMapView_1.Commands.fitToCoordinates(fabricRef.current, JSON.stringify(coordinates), JSON.stringify(edgePadding), animated);
151
- }
152
- catch (error) {
153
- throw new Error('Failed to fitToCoordinates');
154
- }
155
- }
156
- else {
157
- throw new Error('fitToCoordinates is only supported on iOS with Fabric.');
158
- }
159
- },
160
- setCamera(camera) {
161
- if (fabricRef.current) {
162
- try {
163
- NativeComponentMapView_1.Commands.setCamera(fabricRef.current, JSON.stringify(camera));
164
- }
165
- catch (error) {
166
- console.error('Failed to set camera:', error);
167
- }
168
- }
169
- else {
170
- console.warn('setCamera is only supported on iOS with Fabric.');
171
- }
172
- },
173
- }));
174
- if (props.provider === 'google') {
175
- return <NativeComponentGoogleMapView_1.default {...props} ref={fabricRef}/>;
176
- }
177
- else {
178
- return <NativeComponentMapView_1.default {...props} ref={fabricRef}/>;
179
- }
180
- });
181
- exports.default = exports.FabricMap;