react-native-maps 1.21.0-alpha.25 → 1.21.0-alpha.27

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.
@@ -783,8 +783,7 @@ id regionAsJSON(MKCoordinateRegion region) {
783
783
  };
784
784
  }
785
785
 
786
- -(void) takeSnapshotWithConfig:(NSDictionary *)config callback:(RCTPromiseResolveBlock) callback
787
- {
786
+ -(void) takeSnapshotWithConfig:(NSDictionary *)config success:(RCTPromiseResolveBlock)success error:(RCTPromiseRejectBlock)error {
788
787
  /* unused
789
788
  NSNumber *width = [config objectForKey:@"width"];
790
789
  NSNumber *height = [config objectForKey:@"height"];
@@ -793,8 +792,9 @@ id regionAsJSON(MKCoordinateRegion region) {
793
792
 
794
793
  NSString *format = [config objectForKey:@"format"];
795
794
  NSString *result = [config objectForKey:@"result"];
796
- NSString *filePath = [config objectForKey:@"filePath"];
797
-
795
+ NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
796
+ NSString *pathComponent = [NSString stringWithFormat:@"Documents/snapshot-%.20lf.%@", timeStamp, format];
797
+ NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent: pathComponent];
798
798
 
799
799
  // TODO: currently we are ignoring width, height, region
800
800
 
@@ -812,9 +812,9 @@ id regionAsJSON(MKCoordinateRegion region) {
812
812
 
813
813
  if ([result isEqualToString:@"file"]) {
814
814
  [data writeToFile:filePath atomically:YES];
815
- callback(filePath);
815
+ success(filePath);
816
816
  } else if ([result isEqualToString:@"base64"]) {
817
- callback([data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]);
817
+ success([data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]);
818
818
  }
819
819
 
820
820
  UIGraphicsEndImageContext();
@@ -267,7 +267,9 @@ RCT_EXPORT_METHOD(takeSnapshot:(nonnull NSNumber *)reactTag
267
267
  AIRGoogleMap *mapView = (AIRGoogleMap *)view;
268
268
  NSMutableDictionary* config = [NSMutableDictionary new];
269
269
 
270
- [mapView takeSnapshotWithConfig:config callback:callback];
270
+ [mapView takeSnapshotWithConfig:config success:callback error:^(NSString *code, NSString *message, NSError *error) {
271
+ callback(@[error]);
272
+ }];
271
273
 
272
274
  [config setObject:width forKey:@"width"];
273
275
  [config setObject:height forKey:@"height"];
@@ -46,7 +46,11 @@ using namespace facebook::react;
46
46
  NSDictionary* regionDic = [RCTConvert dictonaryFromString:regionJSON];
47
47
  MKCoordinateRegion region = [RCTConvert MKCoordinateRegion:regionDic];
48
48
  GMSCameraPosition *camera = [AIRGoogleMap makeGMSCameraPositionFromMap:_view andMKCoordinateRegion:region];
49
- [_view animateToCameraPosition:camera];
49
+ if (duration == 0){
50
+ [_view setRegion:region];
51
+ } else {
52
+ [_view animateToCameraPosition:camera];
53
+ }
50
54
  }
51
55
  - (void)setCamera:(NSString *)cameraJSON{
52
56
  NSDictionary* cameraDic = [RCTConvert dictonaryFromString:cameraJSON];
@@ -51,7 +51,7 @@ const NSInteger AIRMapMaxZoomLevel = 20;
51
51
  BOOL _initialRegionSet;
52
52
  BOOL _initialCameraSet;
53
53
  BOOL _initialized;
54
-
54
+
55
55
  // Array to manually track RN subviews
56
56
  //
57
57
  // AIRMap implicitly creates subviews that aren't regular RN children
@@ -69,7 +69,7 @@ const NSInteger AIRMapMaxZoomLevel = 20;
69
69
  if ((self = [super init])) {
70
70
  _hasStartedRendering = NO;
71
71
  _reactSubviews = [NSMutableArray new];
72
-
72
+
73
73
  // Find Apple link label
74
74
  for (UIView *subview in self.subviews) {
75
75
  if ([NSStringFromClass(subview.class) isEqualToString:@"MKAttributionLabel"]) {
@@ -79,12 +79,12 @@ const NSInteger AIRMapMaxZoomLevel = 20;
79
79
  break;
80
80
  }
81
81
  }
82
-
82
+
83
83
  // 3rd-party callout view for MapKit that has more options than the built-in. It's painstakingly built to
84
84
  // be identical to the built-in callout view (which has a private API)
85
85
  self.calloutView = [SMCalloutView platformCalloutView];
86
86
  self.calloutView.delegate = self;
87
-
87
+
88
88
  self.minZoom = 0;
89
89
  self.maxZoom = AIRMapMaxZoomLevel;
90
90
  self.compassOffset = CGPointMake(0, 0);
@@ -205,16 +205,16 @@ const NSInteger AIRMapMaxZoomLevel = 20;
205
205
  }
206
206
  // Create Polyline with coordinates
207
207
  -(void) fitToCoordinates:(NSArray<AIRMapCoordinate*>*) coordinates edgePadding:(UIEdgeInsets) edgeInsets animated:(Boolean) animated {
208
- CLLocationCoordinate2D coords[coordinates.count];
209
- for(int i = 0; i < coordinates.count; i++)
210
- {
211
- coords[i] = coordinates[i].coordinate;
212
- }
213
- MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordinates.count];
214
-
215
- // Set Map viewport
216
-
217
- [self setVisibleMapRect:[polyline boundingMapRect] edgePadding:edgeInsets animated:animated];
208
+ CLLocationCoordinate2D coords[coordinates.count];
209
+ for(int i = 0; i < coordinates.count; i++)
210
+ {
211
+ coords[i] = coordinates[i].coordinate;
212
+ }
213
+ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordinates.count];
214
+
215
+ // Set Map viewport
216
+
217
+ [self setVisibleMapRect:[polyline boundingMapRect] edgePadding:edgeInsets animated:animated];
218
218
  }
219
219
  - (CGRect) frameForMarker:(AIRMapMarker*) mrkAnn {
220
220
  MKAnnotationView* mrkView = [self viewForAnnotation: mrkAnn];
@@ -250,16 +250,16 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
250
250
  // Allow touches to be sent to our calloutview.
251
251
  // See this for some discussion of why we need to override this: https://github.com/nfarina/calloutview/pull/9
252
252
  - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
253
-
253
+
254
254
  CGPoint touchPoint = [self.calloutView convertPoint:point fromView:self];
255
255
  UIView *touchedView = [self.calloutView hitTest:touchPoint withEvent:event];
256
-
256
+
257
257
  if (touchedView) {
258
258
  UIWindow* win = [[[UIApplication sharedApplication] windows] firstObject];
259
259
  AIRMapCalloutSubview* calloutSubview = nil;
260
260
  AIRMapCallout* callout = nil;
261
261
  AIRMapMarker* marker = nil;
262
-
262
+
263
263
  UIView* tmp = touchedView;
264
264
  while (tmp && tmp != win && tmp != self.calloutView) {
265
265
  if ([tmp respondsToSelector:@selector(onPress)]) {
@@ -271,7 +271,7 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
271
271
  }
272
272
  tmp = tmp.superview;
273
273
  }
274
-
274
+
275
275
  if (callout) {
276
276
  marker = [self markerForCallout:callout];
277
277
  if (marker) {
@@ -281,36 +281,36 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
281
281
  }
282
282
  }
283
283
  }
284
-
284
+
285
285
  return calloutSubview ? calloutSubview : touchedView;
286
286
  }
287
-
287
+
288
288
  return [super hitTest:point withEvent:event];
289
289
  }
290
290
 
291
291
  #pragma mark SMCalloutViewDelegate
292
292
 
293
293
  - (NSTimeInterval)calloutView:(SMCalloutView *)calloutView delayForRepositionWithSize:(CGSize)offset {
294
-
294
+
295
295
  // When the callout is being asked to present in a way where it or its target will be partially offscreen, it asks us
296
296
  // if we'd like to reposition our surface first so the callout is completely visible. Here we scroll the map into view,
297
297
  // but it takes some math because we have to deal in lon/lat instead of the given offset in pixels.
298
-
298
+
299
299
  CLLocationCoordinate2D coordinate = self.region.center;
300
-
300
+
301
301
  // where's the center coordinate in terms of our view?
302
302
  CGPoint center = [self convertCoordinate:coordinate toPointToView:self];
303
-
303
+
304
304
  // move it by the requested offset
305
305
  center.x -= offset.width;
306
306
  center.y -= offset.height;
307
-
307
+
308
308
  // and translate it back into map coordinates
309
309
  coordinate = [self convertPoint:center toCoordinateFromView:self];
310
-
310
+
311
311
  // move the map!
312
312
  [self setCenterCoordinate:coordinate animated:YES];
313
-
313
+
314
314
  // tell the callout to wait for a while while we scroll (we assume the scroll delay for MKMapView matches UIScrollView)
315
315
  return kSMCalloutViewRepositionDelayForUIScrollView;
316
316
  }
@@ -320,10 +320,10 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
320
320
  - (NSArray *)getMapBoundaries
321
321
  {
322
322
  MKMapRect mapRect = self.visibleMapRect;
323
-
323
+
324
324
  CLLocationCoordinate2D northEast = MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMaxX(mapRect), mapRect.origin.y));
325
325
  CLLocationCoordinate2D southWest = MKCoordinateForMapPoint(MKMapPointMake(mapRect.origin.x, MKMapRectGetMaxY(mapRect)));
326
-
326
+
327
327
  return @[
328
328
  @[
329
329
  [NSNumber numberWithDouble:northEast.longitude],
@@ -338,20 +338,20 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
338
338
  - (NSDictionary *) getPointForCoordinates:(CLLocationCoordinate2D) location
339
339
  {
340
340
  CGPoint touchPoint = [self convertCoordinate:location toPointToView:self];
341
-
341
+
342
342
  return @{
343
- @"x": @(touchPoint.x),
344
- @"y": @(touchPoint.y),
343
+ @"x": @(touchPoint.x),
344
+ @"y": @(touchPoint.y),
345
345
  };
346
346
  }
347
347
  - (NSDictionary *) getCoordinatesForPoint:(CGPoint)point
348
348
  {
349
349
  CLLocationCoordinate2D coordinate = [self convertPoint:point toCoordinateFromView:self];
350
350
  return @{
351
- @"latitude": @(coordinate.latitude),
352
- @"longitude": @(coordinate.longitude),
351
+ @"latitude": @(coordinate.latitude),
352
+ @"longitude": @(coordinate.longitude),
353
353
  };
354
-
354
+
355
355
  }
356
356
 
357
357
  - (NSDictionary*) getMarkersFramesWithOnlyVisible:(BOOL)onlyVisible {
@@ -381,120 +381,125 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
381
381
  - (NSDictionary *) getCamera {
382
382
  MKMapCamera *camera = [self camera];
383
383
  return @{
384
- @"center": @{
385
- @"latitude": @(camera.centerCoordinate.latitude),
386
- @"longitude": @(camera.centerCoordinate.longitude),
387
- },
388
- @"pitch": @(camera.pitch),
389
- @"heading": @(camera.heading),
390
- @"altitude": @(camera.altitude),
384
+ @"center": @{
385
+ @"latitude": @(camera.centerCoordinate.latitude),
386
+ @"longitude": @(camera.centerCoordinate.longitude),
387
+ },
388
+ @"pitch": @(camera.pitch),
389
+ @"heading": @(camera.heading),
390
+ @"altitude": @(camera.altitude),
391
391
  };
392
392
  }
393
393
  - (void)takeSnapshotWithConfig:(NSDictionary *)config
394
- callback:(RCTPromiseResolveBlock) callback
394
+ success:(RCTPromiseResolveBlock)success error:(RCTPromiseRejectBlock)error
395
395
  {
396
-
397
- MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
398
-
399
- options.mapType = self.mapType;
400
- NSNumber *width = config[@"width"];
401
- NSNumber *height = config[@"height"];
402
- NSNumber *quality = config[@"quality"];
403
- NSString*format =config[@"format"];
404
- NSString*result =config[@"result"];
405
- MKCoordinateRegion region = [RCTConvert MKCoordinateRegion:config[@"region"]];
406
-
407
-
408
- options.region = (region.center.latitude && region.center.longitude) ? region : self.region;
409
- options.size = CGSizeMake(
410
- ([width floatValue] == 0) ? self.bounds.size.width : [width floatValue],
411
- ([height floatValue] == 0) ? self.bounds.size.height : [height floatValue]
412
- );
413
-
414
- options.scale = [[UIScreen mainScreen] scale];
415
-
416
-
417
- MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
418
-
419
- [self takeMapSnapshot:snapshotter
420
- format:format
421
- quality:[quality floatValue]
422
- result:result
423
- callback:callback];
396
+
397
+ MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
398
+
399
+ options.mapType = self.mapType;
400
+ NSNumber *width = config[@"width"];
401
+ NSNumber *height = config[@"height"];
402
+ NSNumber *quality = config[@"quality"];
403
+ NSString*format =config[@"format"];
404
+ NSString*result =config[@"result"];
405
+ if (config[@"region"]){
406
+ MKCoordinateRegion region = [RCTConvert MKCoordinateRegion:config[@"region"]];
407
+ options.region = region;
408
+ } else
409
+ {
410
+ options.region = self.region;
411
+ }
412
+ options.size = CGSizeMake(
413
+ ([width floatValue] == 0) ? self.bounds.size.width : [width floatValue],
414
+ ([height floatValue] == 0) ? self.bounds.size.height : [height floatValue]
415
+ );
416
+
417
+ options.scale = [[UIScreen mainScreen] scale];
418
+
419
+
420
+ MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
421
+
422
+ [self takeMapSnapshot:snapshotter
423
+ format:format
424
+ quality:[quality floatValue]
425
+ result:result
426
+ success:success error:error];
424
427
  }
425
428
 
426
429
  #pragma mark Take Snapshot
427
430
  - (void)takeMapSnapshot:(MKMapSnapshotter *) snapshotter
428
- format:(NSString *)format
429
- quality:(CGFloat) quality
430
- result:(NSString *)result
431
- callback:(RCTPromiseResolveBlock) callback {
431
+ format:(NSString *)format
432
+ quality:(CGFloat) quality
433
+ result:(NSString *)result
434
+ success:(RCTPromiseResolveBlock) success
435
+ error:(RCTPromiseRejectBlock) errorCallback {
432
436
  NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
433
437
  NSString *pathComponent = [NSString stringWithFormat:@"Documents/snapshot-%.20lf.%@", timeStamp, format];
434
438
  NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent: pathComponent];
435
-
439
+
436
440
  [snapshotter startWithQueue:dispatch_get_main_queue()
437
441
  completionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
438
- if (error) {
439
- callback(@[error]);
440
- return;
441
- }
442
- MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:nil];
443
-
444
- UIImage *image = snapshot.image;
445
- UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale);
446
- {
447
- [image drawAtPoint:CGPointMake(0.0f, 0.0f)];
448
-
449
- CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
450
-
451
- for (id <AIRMapSnapshot> overlay in self.overlays) {
452
- if ([overlay respondsToSelector:@selector(drawToSnapshot:context:)]) {
453
- [overlay drawToSnapshot:snapshot context:UIGraphicsGetCurrentContext()];
454
- }
455
- }
456
-
457
- for (id <MKAnnotation> annotation in self.annotations) {
458
- CGPoint point = [snapshot pointForCoordinate:annotation.coordinate];
459
-
460
- MKAnnotationView* anView = [self viewForAnnotation: annotation];
461
-
462
- if (anView){
463
- pin = anView;
464
- }
465
-
466
- if (CGRectContainsPoint(rect, point)) {
467
- point.x = point.x + pin.centerOffset.x - (pin.bounds.size.width / 2.0f);
468
- point.y = point.y + pin.centerOffset.y - (pin.bounds.size.height / 2.0f);
469
- if (pin.image) {
470
- [pin.image drawAtPoint:point];
471
- } else {
472
- CGRect pinRect = CGRectMake(point.x, point.y, pin.bounds.size.width, pin.bounds.size.height);
473
- [pin drawViewHierarchyInRect:pinRect afterScreenUpdates:NO];
474
- }
475
- }
476
- }
477
-
478
- UIImage *compositeImage = UIGraphicsGetImageFromCurrentImageContext();
479
-
480
- NSData *data;
481
- if ([format isEqualToString:@"png"]) {
482
- data = UIImagePNGRepresentation(compositeImage);
483
- }
484
- else if([format isEqualToString:@"jpg"]) {
485
- data = UIImageJPEGRepresentation(compositeImage, quality);
486
- }
487
-
488
- if ([result isEqualToString:@"file"]) {
489
- [data writeToFile:filePath atomically:YES];
490
- callback(filePath);
491
- }
492
- else if ([result isEqualToString:@"base64"]) {
493
- callback([data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]);
494
- }
495
- }
496
- UIGraphicsEndImageContext();
497
- }];
442
+ if (error) {
443
+ errorCallback(@"snapshotterError", @"failed", error);
444
+ return;
445
+ }
446
+ MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:nil];
447
+
448
+ UIImage *image = snapshot.image;
449
+ UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale);
450
+ {
451
+ [image drawAtPoint:CGPointMake(0.0f, 0.0f)];
452
+
453
+ CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
454
+
455
+ for (id <AIRMapSnapshot> overlay in self.overlays) {
456
+ if ([overlay respondsToSelector:@selector(drawToSnapshot:context:)]) {
457
+ [overlay drawToSnapshot:snapshot context:UIGraphicsGetCurrentContext()];
458
+ }
459
+ }
460
+
461
+
462
+ for (id <MKAnnotation> annotation in self.annotations) {
463
+ CGPoint point = [snapshot pointForCoordinate:annotation.coordinate];
464
+
465
+ MKAnnotationView* anView = [self viewForAnnotation: annotation];
466
+
467
+ if (anView){
468
+ pin = anView;
469
+ }
470
+
471
+ if (CGRectContainsPoint(rect, point)) {
472
+ point.x = point.x + pin.centerOffset.x - (pin.bounds.size.width / 2.0f);
473
+ point.y = point.y + pin.centerOffset.y - (pin.bounds.size.height / 2.0f);
474
+ if (pin.image) {
475
+ [pin.image drawAtPoint:point];
476
+ } else {
477
+ CGRect pinRect = CGRectMake(point.x, point.y, pin.bounds.size.width, pin.bounds.size.height);
478
+ [pin drawViewHierarchyInRect:pinRect afterScreenUpdates:NO];
479
+ }
480
+ }
481
+ }
482
+
483
+ UIImage *compositeImage = UIGraphicsGetImageFromCurrentImageContext();
484
+
485
+ NSData *data;
486
+ if ([format isEqualToString:@"png"]) {
487
+ data = UIImagePNGRepresentation(compositeImage);
488
+ }
489
+ else if([format isEqualToString:@"jpg"]) {
490
+ data = UIImageJPEGRepresentation(compositeImage, quality);
491
+ }
492
+
493
+ if ([result isEqualToString:@"file"]) {
494
+ [data writeToFile:filePath atomically:YES];
495
+ success(filePath);
496
+ }
497
+ else if ([result isEqualToString:@"base64"]) {
498
+ success([data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]);
499
+ }
500
+ }
501
+ UIGraphicsEndImageContext();
502
+ }];
498
503
  }
499
504
 
500
505
 
@@ -552,7 +557,7 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
552
557
  if (!CLLocationCoordinate2DIsValid(region.center)) {
553
558
  return;
554
559
  }
555
-
560
+
556
561
  // If new span values are nil, use old values instead
557
562
  if (!region.span.latitudeDelta) {
558
563
  region.span.latitudeDelta = self.region.span.latitudeDelta;
@@ -560,7 +565,7 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
560
565
  if (!region.span.longitudeDelta) {
561
566
  region.span.longitudeDelta = self.region.span.longitudeDelta;
562
567
  }
563
-
568
+
564
569
  // Animate/move to new position
565
570
  [super setRegion:region animated:animated];
566
571
  }
@@ -631,25 +636,25 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
631
636
 
632
637
  - (void)setCameraZoomRange:(NSDictionary *)cameraZoomRange {
633
638
  if (@available(iOS 13.0, *)) {
634
-
639
+
635
640
  if (cameraZoomRange == nil) {
636
641
  cameraZoomRange = @{};
637
642
  }
638
-
643
+
639
644
  NSNumber *minValue = cameraZoomRange[@"minCenterCoordinateDistance"];
640
645
  NSNumber *maxValue = cameraZoomRange[@"maxCenterCoordinateDistance"];
641
-
646
+
642
647
  if (minValue == nil && maxValue == nil) {
643
648
  self.legacyZoomConstraintsEnabled = YES;
644
-
649
+
645
650
  MKMapCameraZoomRange *defaultZoomRange = [[MKMapCameraZoomRange alloc] initWithMinCenterCoordinateDistance:MKMapCameraZoomDefault maxCenterCoordinateDistance:MKMapCameraZoomDefault];
646
651
  [super setCameraZoomRange:defaultZoomRange animated:NO];
647
-
652
+
648
653
  return;
649
654
  }
650
-
655
+
651
656
  MKMapCameraZoomRange *zoomRange = nil;
652
-
657
+
653
658
  if (minValue != nil && maxValue != nil) {
654
659
  zoomRange = [[MKMapCameraZoomRange alloc] initWithMinCenterCoordinateDistance:[minValue doubleValue] maxCenterCoordinateDistance:[maxValue doubleValue]];
655
660
  } else if (minValue != nil) {
@@ -657,9 +662,9 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
657
662
  } else if (maxValue != nil) {
658
663
  zoomRange = [[MKMapCameraZoomRange alloc] initWithMaxCenterCoordinateDistance:[maxValue doubleValue]];
659
664
  }
660
-
665
+
661
666
  BOOL animated = [cameraZoomRange[@"animated"] boolValue];
662
-
667
+
663
668
  self.legacyZoomConstraintsEnabled = NO;
664
669
  [super setCameraZoomRange:zoomRange animated:animated];
665
670
  }
@@ -710,7 +715,7 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
710
715
  else {
711
716
  self.cacheImageView.image = nil;
712
717
  self.cacheImageView.hidden = YES;
713
-
718
+
714
719
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
715
720
  self.cacheImageView.image = nil;
716
721
  self.cacheImageView.hidden = YES;
@@ -718,12 +723,12 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
718
723
  [self.layer renderInContext:UIGraphicsGetCurrentContext()];
719
724
  UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
720
725
  UIGraphicsEndImageContext();
721
-
726
+
722
727
  self.cacheImageView.image = image;
723
728
  self.cacheImageView.hidden = NO;
724
729
  });
725
730
  }
726
-
731
+
727
732
  [self updateScrollEnabled];
728
733
  [self updateZoomEnabled];
729
734
  [self updateLegalLabelInsets];
@@ -824,22 +829,22 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
824
829
  // based on https://medium.com/@dmytrobabych/getting-actual-rotation-and-zoom-level-for-mapkit-mkmapview-e7f03f430aa9
825
830
  - (CGFloat)getZoomLevel {
826
831
  CGFloat cameraAngle = self.camera.heading;
827
-
832
+
828
833
  if (cameraAngle > 270) {
829
834
  cameraAngle = 360 - cameraAngle;
830
835
  } else if (cameraAngle > 90) {
831
836
  cameraAngle = fabs(cameraAngle - 180);
832
837
  }
833
-
838
+
834
839
  CGFloat angleRad = M_PI * cameraAngle / 180; // map rotation in radians
835
840
  CGFloat width = self.frame.size.width;
836
841
  CGFloat height = self.frame.size.height;
837
842
  CGFloat heightOffset = 20; // the offset (status bar height) which is taken by MapKit into consideration to calculate visible area height
838
-
843
+
839
844
  // calculating Longitude span corresponding to normal (non-rotated) width
840
845
  CGFloat spanStraight = width * self.region.span.longitudeDelta / (width * cos(angleRad) + (height - heightOffset) * sin(angleRad));
841
846
  int normalizingFactor = 512;
842
-
847
+
843
848
  return log2(360 * ((width / normalizingFactor) / spanStraight));
844
849
  }
845
850
 
@@ -935,6 +935,9 @@ static int kDragCenterContext;
935
935
  {
936
936
  // Don't send region did change events until map has
937
937
  // started rendering, as these won't represent the final location
938
+ if (animated && mapView.ignoreRegionChanges){
939
+ mapView.ignoreRegionChanges = false;
940
+ }
938
941
  if(mapView.hasStartedRendering){
939
942
  [self _regionChanged:mapView];
940
943
  }
@@ -60,12 +60,13 @@
60
60
  } reject:reject];
61
61
  }
62
62
  - (void)takeSnapshot:(double)tag
63
- config:(NSDictionary *)config
63
+ config:(NSString *)configStr
64
64
  resolve:(RCTPromiseResolveBlock)resolve
65
65
  reject:(RCTPromiseRejectBlock)reject
66
66
  {
67
+ NSDictionary* config = [RCTConvert dictonaryFromString:configStr];
67
68
  [self executeWithMapView:tag success:^(id<RNMapsAirModuleDelegate> mapView) {
68
- [mapView takeSnapshotWithConfig:config callback:resolve];
69
+ [mapView takeSnapshotWithConfig:config success:resolve error:reject];
69
70
  } reject:reject];
70
71
  }
71
72
 
@@ -14,7 +14,7 @@
14
14
  @required
15
15
 
16
16
  - (void)takeSnapshotWithConfig:(NSDictionary *)config
17
- callback:(RCTPromiseResolveBlock) callback;
17
+ success:(RCTPromiseResolveBlock) success error:(RCTPromiseRejectBlock) error;
18
18
 
19
19
  - (NSDictionary *) getCamera;
20
20
  - (NSDictionary*) getMarkersFramesWithOnlyVisible:(BOOL)onlyVisible;
@@ -47,8 +47,9 @@ using namespace facebook::react;
47
47
  - (void)animateToRegion:(NSString *)regionJSON duration:(NSInteger)duration{
48
48
  NSDictionary* regionDic = [RCTConvert dictonaryFromString:regionJSON];
49
49
  MKCoordinateRegion region = [RCTConvert MKCoordinateRegion:regionDic];
50
- _view.ignoreRegionChanges = YES;
51
- [_view setRegion:region animated:YES];
50
+ Boolean animated = duration == 0 ? NO :YES;
51
+ _view.ignoreRegionChanges = animated;
52
+ [_view setRegion:region animated:animated];
52
53
  }
53
54
  - (void)setCamera:(NSString *)cameraJSON{
54
55
  NSDictionary* cameraDic = [RCTConvert dictonaryFromString:cameraJSON];
package/lib/MapView.d.ts CHANGED
@@ -608,6 +608,7 @@ declare class MapView extends React.Component<MapViewProps, State> {
608
608
  duration?: number;
609
609
  }): void;
610
610
  animateToRegion(region: Region, duration?: number): void;
611
+ setRegion(region: Region): void;
611
612
  fitToElements(options?: FitToOptions): void;
612
613
  fitToSuppliedMarkers(markers: string[], options?: FitToOptions): void;
613
614
  fitToCoordinates(coordinates?: LatLng[], options?: FitToOptions): void;
package/lib/MapView.js CHANGED
@@ -119,6 +119,12 @@ class MapView extends React.Component {
119
119
  MapViewNativeComponent_1.Commands.animateToRegion(this.map.current, region, duration);
120
120
  }
121
121
  }
122
+ setRegion(region) {
123
+ if (this.fabricMap.current) {
124
+ this.fabricMap.current.animateToRegion(region, 0);
125
+ }
126
+ //TODO fix for android
127
+ }
122
128
  fitToElements(options = {}) {
123
129
  const { edgePadding = { top: 0, right: 0, bottom: 0, left: 0 }, animated = true, } = options;
124
130
  if (this.fabricMap.current) {
@@ -67,7 +67,7 @@ const createFabricMap = (ViewComponent, Commands) => {
67
67
  },
68
68
  async takeSnapshot(config) {
69
69
  if (fabricRef.current) {
70
- return NativeAirMapsModule_1.default.takeSnapshot((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, config);
70
+ return NativeAirMapsModule_1.default.takeSnapshot((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, JSON.stringify(config));
71
71
  }
72
72
  else {
73
73
  throw new Error('takeSnapshot is only supported on iOS with Fabric.');
@@ -1,5 +1,5 @@
1
1
  import type { TurboModule } from 'react-native';
2
- import type { Double, UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
2
+ import type { Double } from 'react-native/Libraries/Types/CodegenTypes';
3
3
  import type { Camera } from './NativeComponentMapView';
4
4
  import { Address } from 'react-native-maps';
5
5
  type LatLng = {
@@ -22,7 +22,7 @@ export interface Spec extends TurboModule {
22
22
  getCamera(tag: Double): Promise<Camera>;
23
23
  getMarkersFrames(tag: Double, onlyVisible: boolean): Promise<unknown>;
24
24
  getMapBoundaries(tag: Double): Promise<MapBoundaries>;
25
- takeSnapshot(tag: Double, config: UnsafeObject): Promise<string>;
25
+ takeSnapshot(tag: Double, config: string): Promise<string>;
26
26
  getAddressFromCoordinates(tag: Double, coordinate: LatLng): Promise<Address>;
27
27
  getPointForCoordinate(tag: Double, coordinate: LatLng): Promise<Point>;
28
28
  getCoordinateForPoint(tag: Double, point: Point): Promise<LatLng>;
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.25",
8
+ "version": "1.21.0-alpha.27",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",