react-native-maps 1.21.0-alpha.1 → 1.21.0-alpha.11

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 (47) hide show
  1. package/android/build.gradle +19 -4
  2. package/android/src/main/java/com/rnmaps/fabric/NativeAirMapsModule.java +51 -0
  3. package/android/src/main/java/com/rnmaps/maps/MapAirModulePackage.java +46 -0
  4. package/ios/AirGoogleMaps/AIRGMSMarker.h +1 -1
  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 +572 -0
  24. package/ios/AirGoogleMaps/RNMapsGoogleMapViewManager.mm +25 -0
  25. package/ios/AirMaps/AIRMap.h +6 -4
  26. package/ios/AirMaps/AIRMap.m +179 -26
  27. package/ios/AirMaps/AIRMapManager.m +6 -21
  28. package/ios/AirMaps/RCTConvert+AirMap.h +4 -0
  29. package/ios/AirMaps/RCTConvert+AirMap.m +2 -0
  30. package/ios/AirMaps/RNMapsAirModule.h +3 -0
  31. package/ios/AirMaps/RNMapsAirModule.mm +40 -171
  32. package/ios/AirMaps/RNMapsAirModuleDelegate.h +24 -0
  33. package/ios/AirMaps/RNMapsHostVewDelegate.h +17 -0
  34. package/ios/AirMaps/RNMapsMapView.h +6 -3
  35. package/ios/AirMaps/RNMapsMapView.mm +20 -38
  36. package/ios/AirMaps/UIView +AirMap.m +20 -0
  37. package/ios/AirMaps/UIView+AirMap.h +11 -0
  38. package/lib/MapOverlay.d.ts +1 -1
  39. package/lib/MapView.d.ts +2 -2
  40. package/lib/MapView.js +20 -18
  41. package/lib/{FabricMapView.d.ts → createFabricMap.d.ts} +7 -6
  42. package/lib/createFabricMap.js +175 -0
  43. package/lib/specs/NativeComponentGoogleMapView.d.ts +713 -0
  44. package/lib/specs/NativeComponentGoogleMapView.js +21 -0
  45. package/lib/specs/NativeComponentMapView.d.ts +4 -11
  46. package/package.json +10 -7
  47. package/lib/FabricMapView.js +0 -175
@@ -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
  {
@@ -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
  }
@@ -1175,11 +1160,11 @@ static int kDragCenterContext;
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
 
@@ -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];
@@ -1,5 +1,6 @@
1
1
  // RCTNativeLocalStorage.h
2
2
  // TurboModuleExample
3
+ #ifdef RCT_NEW_ARCH_ENABLED
3
4
 
4
5
  #import <Foundation/Foundation.h>
5
6
  #import <RNMapsSpecs/RNMapsSpecs.h>
@@ -11,3 +12,5 @@ NS_ASSUME_NONNULL_BEGIN
11
12
  @end
12
13
 
13
14
  NS_ASSUME_NONNULL_END
15
+
16
+ #endif
@@ -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
 
@@ -0,0 +1,24 @@
1
+ //
2
+ // AIRUrlTileOverlay.h
3
+ // AirMaps
4
+ //
5
+ // Created by cascadian on 3/19/16.
6
+ // Copyright © 2016. All rights reserved.
7
+ //
8
+
9
+ #import <Foundation/Foundation.h>
10
+ #import <CoreLocation/CoreLocation.h>
11
+ #import <React/RCTBridge.h>
12
+
13
+ @protocol RNMapsAirModuleDelegate <NSObject>
14
+ @required
15
+
16
+ - (void)takeSnapshotWithConfig:(NSDictionary *)config
17
+ callback:(RCTPromiseResolveBlock) callback;
18
+
19
+ - (NSDictionary *) getCamera;
20
+ - (NSDictionary*) getMarkersFramesWithOnlyVisible:(BOOL)onlyVisible;
21
+ - (NSArray *) getMapBoundaries;
22
+ - (NSDictionary *) getPointForCoordinates:(CLLocationCoordinate2D) location;
23
+ - (NSDictionary *) getCoordinatesForPoint:(CGPoint) point;
24
+ @end
@@ -0,0 +1,17 @@
1
+ //
2
+ // AIRUrlTileOverlay.h
3
+ // AirMaps
4
+ //
5
+ // Created by cascadian on 3/19/16.
6
+ // Copyright © 2016. All rights reserved.
7
+ //
8
+
9
+ #import <Foundation/Foundation.h>
10
+ #import "RNMapsAirModuleDelegate.h"
11
+
12
+ @protocol RNMapsHostVewDelegate <NSObject>
13
+ @required
14
+
15
+ - (id<RNMapsAirModuleDelegate>) mapView;
16
+
17
+ @end