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
@@ -17,16 +17,31 @@ buildscript {
17
17
  }
18
18
  }
19
19
 
20
- apply plugin: 'com.android.library'
20
+ def supportsNamespace() {
21
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
22
+ def major = parsed[0].toInteger()
23
+ def minor = parsed[1].toInteger()
24
+
25
+ // Namespace support was added in 7.3.0
26
+ if (major == 7 && minor >= 3) {
27
+ return true
28
+ }
29
+
30
+ return major >= 8
31
+ }
21
32
 
22
33
  def isNewArchitectureEnabled() {
23
34
  return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
24
35
  }
25
36
 
37
+ apply plugin: 'com.android.library'
38
+ if (isNewArchitectureEnabled()) {
39
+ apply plugin: 'com.facebook.react'
40
+ }
41
+ apply plugin: 'kotlin-android'
42
+
26
43
  android {
27
- namespace "com.rnmaps.maps"
28
- def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
29
- if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
44
+ if (supportsNamespace()) {
30
45
  namespace "com.rnmaps.maps"
31
46
  }
32
47
 
@@ -0,0 +1,51 @@
1
+ package com.rnmaps.fabric;
2
+
3
+ import com.facebook.react.bridge.Promise;
4
+ import com.facebook.react.bridge.ReactApplicationContext;
5
+ import com.facebook.react.bridge.ReadableMap;
6
+
7
+ public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
8
+ public NativeAirMapsModule(ReactApplicationContext reactContext) {
9
+ super(reactContext);
10
+ }
11
+
12
+ @Override
13
+ public String getName() {
14
+ return NAME;
15
+ }
16
+
17
+ @Override
18
+ public void getCamera(double tag, Promise promise) {
19
+
20
+ }
21
+
22
+ @Override
23
+ public void getMarkersFrames(double tag, boolean onlyVisible, Promise promise) {
24
+
25
+ }
26
+
27
+ @Override
28
+ public void getMapBoundaries(double tag, Promise promise) {
29
+
30
+ }
31
+
32
+ @Override
33
+ public void takeSnapshot(double tag, ReadableMap config, Promise promise) {
34
+
35
+ }
36
+
37
+ @Override
38
+ public void getAddressFromCoordinates(double tag, ReadableMap coordinate, Promise promise) {
39
+
40
+ }
41
+
42
+ @Override
43
+ public void getPointForCoordinate(double tag, ReadableMap coordinate, Promise promise) {
44
+
45
+ }
46
+
47
+ @Override
48
+ public void getCoordinateForPoint(double tag, ReadableMap point, Promise promise) {
49
+
50
+ }
51
+ }
@@ -0,0 +1,46 @@
1
+ package com.rnmaps.maps;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ import com.facebook.react.TurboReactPackage;
6
+ import com.facebook.react.bridge.NativeModule;
7
+ import com.facebook.react.bridge.ReactApplicationContext;
8
+ import com.facebook.react.module.model.ReactModuleInfo;
9
+ import com.facebook.react.module.model.ReactModuleInfoProvider;
10
+ import com.rnmaps.fabric.NativeAirMapsModule;
11
+ import com.rnmaps.fabric.NativeAirMapsModuleSpec;
12
+
13
+ import java.util.HashMap;
14
+ import java.util.Map;
15
+
16
+ public class MapAirModulePackage extends TurboReactPackage {
17
+
18
+ @Override
19
+ public NativeModule getModule(String name, ReactApplicationContext reactContext) {
20
+ if (name.equals(NativeAirMapsModuleSpec.NAME)) {
21
+ return new NativeAirMapsModule(reactContext);
22
+ } else {
23
+ return null;
24
+ }
25
+ }
26
+
27
+ @Override
28
+ public ReactModuleInfoProvider getReactModuleInfoProvider() {
29
+ return new ReactModuleInfoProvider() {
30
+ @NonNull
31
+ @Override
32
+ public Map<String, ReactModuleInfo> getReactModuleInfos() {
33
+ Map<String, ReactModuleInfo> map = new HashMap<>();
34
+ map.put(NativeAirMapsModuleSpec.NAME, new ReactModuleInfo(
35
+ NativeAirMapsModuleSpec.NAME, // name
36
+ NativeAirMapsModuleSpec.NAME, // className
37
+ false, // canOverrideExistingModule
38
+ false, // needsEagerInit
39
+ false, // isCXXModule
40
+ true // isTurboModule
41
+ ));
42
+ return map;
43
+ }
44
+ };
45
+ }
46
+ }
@@ -12,7 +12,7 @@
12
12
 
13
13
  @class AIRGoogleMapMarker;
14
14
 
15
- @interface AIRGMSMarker : GMSMarker
15
+ @interface AIRGMSMarker : GMSAdvancedMarker
16
16
  @property (nonatomic, strong) NSString *identifier;
17
17
  @property (nonatomic, weak) AIRGoogleMapMarker *fakeMarker;
18
18
  @property (nonatomic, copy) RCTBubblingEventBlock onPress;
@@ -13,9 +13,10 @@
13
13
  #import <GoogleMaps/GoogleMaps.h>
14
14
  #import <MapKit/MapKit.h>
15
15
  #import "AIRGMSMarker.h"
16
- #import "RCTConvert+AirMap.h"
16
+ #import "RNMapsAirModuleDelegate.h"
17
+ #import "AIRGoogleMapCoordinate.h"
17
18
 
18
- @interface AIRGoogleMap : GMSMapView
19
+ @interface AIRGoogleMap : GMSMapView <RNMapsAirModuleDelegate>
19
20
 
20
21
  // TODO: don't use MK region?
21
22
  @property (nonatomic, weak) RCTBridge *bridge;
@@ -66,6 +67,7 @@
66
67
  @property (nonatomic, assign) BOOL showsIndoorLevelPicker;
67
68
  @property (nonatomic, assign) NSString *kmlSrc;
68
69
 
70
+ - (BOOL) isReady;
69
71
  - (void)didPrepareMap;
70
72
  - (void)mapViewDidFinishTileRendering;
71
73
  - (BOOL)didTapMarker:(GMSMarker *)marker;
@@ -84,6 +86,10 @@
84
86
 
85
87
  - (NSDictionary*) getMarkersFramesWithOnlyVisible:(BOOL)onlyVisible;
86
88
  - (instancetype)initWithMapId:(NSString *)mapId initialCamera:(GMSCameraPosition*) camera backgroundColor:(UIColor *) backgroundColor andZoomTapEnabled:(BOOL)zoomTapEnabled;
89
+ -(void) fitToSuppliedMarkers:(NSArray*) markers withEdgePadding:(NSDictionary*) edgePadding animated:(BOOL)animated;
90
+ -(void) fitToCoordinates:(NSArray<AIRGoogleMapCoordinate *> *) coordinates withEdgePadding:(NSDictionary*) edgePadding animated:(BOOL)animated;
91
+ -(void) fitToElementsWithEdgePadding:(nonnull NSDictionary *)edgePadding
92
+ animated:(BOOL)animated;
87
93
  @end
88
94
 
89
95
  #endif
@@ -17,11 +17,12 @@
17
17
  #import "AIRGoogleMapUrlTile.h"
18
18
  #import "AIRGoogleMapWMSTile.h"
19
19
  #import "AIRGoogleMapOverlay.h"
20
+ #import "AIRGoogleMapCoordinate.h"
20
21
  #import <GoogleMaps/GoogleMaps.h>
21
22
  #import <MapKit/MapKit.h>
22
23
  #import <React/UIView+React.h>
23
24
  #import <React/RCTBridge.h>
24
- #import "RCTConvert+AirMap.h"
25
+ #import <React/RCTConvert.h>
25
26
  #import <objc/runtime.h>
26
27
 
27
28
  #ifdef HAVE_GOOGLE_MAPS_UTILS
@@ -86,7 +87,7 @@ id regionAsJSON(MKCoordinateRegion region) {
86
87
  [options setCamera:camera];
87
88
  }
88
89
  self = [super initWithOptions:options];
89
-
90
+
90
91
  if (self) {
91
92
  _reactSubviews = [NSMutableArray new];
92
93
  _markers = [NSMutableArray array];
@@ -145,6 +146,92 @@ id regionAsJSON(MKCoordinateRegion region) {
145
146
  };
146
147
  }
147
148
 
149
+ - (BOOL) isReady {
150
+ return _didPrepareMap;
151
+ }
152
+
153
+ -(void) fitToCoordinates:(NSArray<AIRGoogleMapCoordinate *> *) coordinates withEdgePadding:(NSDictionary*) edgePadding animated:(BOOL)animated
154
+ {
155
+ CLLocationCoordinate2D myLocation = coordinates.firstObject.coordinate;
156
+ GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
157
+
158
+ for (AIRGoogleMapCoordinate *coordinate in coordinates)
159
+ bounds = [bounds includingCoordinate:coordinate.coordinate];
160
+
161
+ // Set Map viewport
162
+ CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
163
+ CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
164
+ CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
165
+ CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
166
+
167
+ GMSCameraUpdate *cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
168
+
169
+ if (animated) {
170
+ [self animateWithCameraUpdate: cameraUpdate];
171
+ } else {
172
+ [self moveCamera: cameraUpdate];
173
+ }
174
+ }
175
+
176
+ -(void) fitToElementsWithEdgePadding:(nonnull NSDictionary *)edgePadding
177
+ animated:(BOOL)animated
178
+ {
179
+ CLLocationCoordinate2D myLocation = ((AIRGoogleMapMarker *)(self.markers.firstObject)).realMarker.position;
180
+ GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
181
+
182
+ for (AIRGoogleMapMarker *marker in self.markers)
183
+ bounds = [bounds includingCoordinate:marker.realMarker.position];
184
+
185
+ GMSCameraUpdate* cameraUpdate;
186
+
187
+ if ([edgePadding count] != 0) {
188
+ // Set Map viewport
189
+ CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
190
+ CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
191
+ CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
192
+ CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
193
+
194
+ cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
195
+ } else {
196
+ cameraUpdate = [GMSCameraUpdate fitBounds:bounds withPadding:55.0f];
197
+ }
198
+ if (animated) {
199
+ [self animateWithCameraUpdate: cameraUpdate];
200
+ } else {
201
+ [self moveCamera: cameraUpdate];
202
+ }
203
+ }
204
+
205
+ - (void) fitToSuppliedMarkers:(NSArray*) markers withEdgePadding:(NSDictionary*) edgePadding animated:(BOOL)animated
206
+ {
207
+ NSPredicate *filterMarkers = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
208
+ AIRGoogleMapMarker *marker = (AIRGoogleMapMarker *)evaluatedObject;
209
+ return [marker isKindOfClass:[AIRGoogleMapMarker class]] && [markers containsObject:marker.identifier];
210
+ }];
211
+
212
+ NSArray *filteredMarkers = [self.markers filteredArrayUsingPredicate:filterMarkers];
213
+
214
+ CLLocationCoordinate2D myLocation = ((AIRGoogleMapMarker *)(filteredMarkers.firstObject)).realMarker.position;
215
+ GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
216
+
217
+ for (AIRGoogleMapMarker *marker in filteredMarkers)
218
+ bounds = [bounds includingCoordinate:marker.realMarker.position];
219
+
220
+ // Set Map viewport
221
+ CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
222
+ CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
223
+ CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
224
+ CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
225
+
226
+ GMSCameraUpdate* cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
227
+ if (animated) {
228
+ [self animateWithCameraUpdate:cameraUpdate
229
+ ];
230
+ } else {
231
+ [self moveCamera: cameraUpdate];
232
+ }
233
+ }
234
+
148
235
  #pragma clang diagnostic push
149
236
  #pragma clang diagnostic ignored "-Wobjc-missing-super-calls"
150
237
  - (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex {
@@ -579,11 +666,11 @@ id regionAsJSON(MKCoordinateRegion region) {
579
666
  return self.settings.myLocationButton;
580
667
  }
581
668
 
582
- - (void)setMinZoomLevel:(CGFloat)minZoomLevel {
669
+ - (void)setMinZoom:(CGFloat)minZoomLevel {
583
670
  [self setMinZoom:minZoomLevel maxZoom:self.maxZoom ];
584
671
  }
585
672
 
586
- - (void)setMaxZoomLevel:(CGFloat)maxZoomLevel {
673
+ - (void)setMaxZoom:(CGFloat)maxZoomLevel {
587
674
  [self setMinZoom:self.minZoom maxZoom:maxZoomLevel ];
588
675
  }
589
676
 
@@ -610,7 +697,7 @@ id regionAsJSON(MKCoordinateRegion region) {
610
697
  AIRGMSMarker *airMarker = (AIRGMSMarker *) self.selectedMarker;
611
698
  AIRGoogleMapMarker *fakeAirMarker = (AIRGoogleMapMarker *) airMarker.fakeMarker;
612
699
  AIRGoogleMapMarker *fakeSelectedMarker = (AIRGoogleMapMarker *) selectedMarker.fakeMarker;
613
-
700
+
614
701
  if (airMarker && airMarker.onDeselect) {
615
702
  airMarker.onDeselect([fakeAirMarker makeEventData:@"marker-deselect"]);
616
703
  }
@@ -618,7 +705,7 @@ id regionAsJSON(MKCoordinateRegion region) {
618
705
  if (airMarker && self.onMarkerDeselect) {
619
706
  self.onMarkerDeselect([fakeAirMarker makeEventData:@"marker-deselect"]);
620
707
  }
621
-
708
+
622
709
  if (selectedMarker && selectedMarker.onSelect) {
623
710
  selectedMarker.onSelect([fakeSelectedMarker makeEventData:@"marker-select"]);
624
711
  }
@@ -665,6 +752,63 @@ id regionAsJSON(MKCoordinateRegion region) {
665
752
  return [map cameraForBounds:bounds insets:UIEdgeInsetsZero];
666
753
  }
667
754
 
755
+ #pragma mark - RNMapsAirModuleDelegate
756
+
757
+ - (NSDictionary *) getCoordinatesForPoint:(CGPoint)point
758
+ {
759
+ CLLocationCoordinate2D coordinate = [self.projection coordinateForPoint:point];
760
+ return @{
761
+ @"latitude": @(coordinate.latitude),
762
+ @"longitude": @(coordinate.longitude),
763
+ };
764
+ }
765
+
766
+ - (NSDictionary *) getPointForCoordinates:(CLLocationCoordinate2D)location
767
+ {
768
+ CGPoint touchPoint = [self.projection pointForCoordinate:location];
769
+ return @{
770
+ @"x": @(touchPoint.x),
771
+ @"y": @(touchPoint.y),
772
+ };
773
+ }
774
+
775
+ -(void) takeSnapshotWithConfig:(NSDictionary *)config callback:(RCTPromiseResolveBlock) callback
776
+ {
777
+ /* unused
778
+ NSNumber *width = [config objectForKey:@"width"];
779
+ NSNumber *height = [config objectForKey:@"height"];
780
+ */
781
+ NSNumber *quality = [config objectForKey:@"quality"];
782
+
783
+ NSString *format = [config objectForKey:@"format"];
784
+ NSString *result = [config objectForKey:@"result"];
785
+ NSString *filePath = [config objectForKey:@"filePath"];
786
+
787
+
788
+ // TODO: currently we are ignoring width, height, region
789
+
790
+ UIGraphicsBeginImageContextWithOptions(self.frame.size, YES, 0.0f);
791
+ [self.layer renderInContext:UIGraphicsGetCurrentContext()];
792
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
793
+
794
+ NSData *data;
795
+ if ([format isEqualToString:@"png"]) {
796
+ data = UIImagePNGRepresentation(image);
797
+
798
+ } else if([format isEqualToString:@"jpg"]) {
799
+ data = UIImageJPEGRepresentation(image, quality.floatValue);
800
+ }
801
+
802
+ if ([result isEqualToString:@"file"]) {
803
+ [data writeToFile:filePath atomically:YES];
804
+ callback(filePath);
805
+ } else if ([result isEqualToString:@"base64"]) {
806
+ callback([data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]);
807
+ }
808
+
809
+ UIGraphicsEndImageContext();
810
+ }
811
+
668
812
  #pragma mark - Utils
669
813
 
670
814
  - (CGRect) frameForMarker:(AIRGoogleMapMarker*) mrkView {
@@ -1034,7 +1178,7 @@ id regionAsJSON(MKCoordinateRegion region) {
1034
1178
  }
1035
1179
  // do nothing, passed as options on initialization
1036
1180
  - (void)setLoadingBackgroundColor:(UIColor *)loadingBackgroundColor {
1037
-
1181
+
1038
1182
  }
1039
1183
 
1040
1184
 
@@ -7,7 +7,6 @@
7
7
  #ifdef HAVE_GOOGLE_MAPS
8
8
 
9
9
  #import <GoogleMaps/GoogleMaps.h>
10
- #import "AIRMapCoordinate.h"
11
10
 
12
11
  @interface AIRGoogleMapCircle : UIView
13
12
 
@@ -0,0 +1,13 @@
1
+ //
2
+ // Created by Leland Richardson on 12/27/15.
3
+ // Copyright (c) 2015 Facebook. All rights reserved.
4
+ //
5
+
6
+ #import <Foundation/Foundation.h>
7
+ #import <MapKit/MapKit.h>
8
+
9
+ @interface AIRGoogleMapCoordinate : NSObject
10
+
11
+ @property (nonatomic, assign) CLLocationCoordinate2D coordinate;
12
+
13
+ @end
@@ -0,0 +1,10 @@
1
+ //
2
+ // Created by Leland Richardson on 12/27/15.
3
+ // Copyright (c) 2015 Facebook. All rights reserved.
4
+ //
5
+
6
+ #import "AIRGoogleMapCoordinate.h"
7
+
8
+
9
+ @implementation AIRGoogleMapCoordinate
10
+ @end
@@ -9,8 +9,15 @@
9
9
 
10
10
  #import <React/RCTViewManager.h>
11
11
 
12
+ @class GMSCameraPosition;
13
+
12
14
  @interface AIRGoogleMapManager : RCTViewManager
13
15
 
16
+ @property (nonatomic, strong) NSString* googleMapId;
17
+ @property (nonatomic) BOOL zoomTapEnabled;
18
+ @property (nonatomic, strong) UIColor* backgroundColor;
19
+ @property (nonatomic, strong) GMSCameraPosition* camera;
20
+
14
21
  @property (nonatomic, strong) NSDictionary *initialProps;
15
22
 
16
23
  @property (nonatomic) BOOL isGesture;
@@ -19,14 +19,9 @@
19
19
  #import <React/UIView+React.h>
20
20
  #import "RCTConvert+GMSMapViewType.h"
21
21
  #import "AIRGoogleMap.h"
22
- #import "AIRMapMarker.h"
23
- #import "AIRMapPolyline.h"
24
- #import "AIRMapPolygon.h"
25
- #import "AIRMapCircle.h"
26
- #import "SMCalloutView.h"
27
22
  #import "AIRGoogleMapMarker.h"
28
- #import "RCTConvert+AirMap.h"
29
-
23
+ #import "AIRGoogleMapCoordinate.h"
24
+ #import "RCTConvert+GMSMapViewType.h"
30
25
  #import <MapKit/MapKit.h>
31
26
  #import <QuartzCore/QuartzCore.h>
32
27
 
@@ -45,26 +40,22 @@ RCT_EXPORT_MODULE()
45
40
 
46
41
  - (UIView *)view
47
42
  {
48
- NSString* googleMapId = nil;
49
- BOOL zoomTapEnabled = YES;
50
- UIColor* backgroundColor = nil;
51
- GMSCameraPosition* camera = nil;
52
43
 
53
44
  if (self.initialProps){
54
45
  if (self.initialProps[@"googleMapId"]){
55
- googleMapId = self.initialProps[@"googleMapId"];
46
+ _googleMapId = self.initialProps[@"googleMapId"];
56
47
  }
57
48
  if (self.initialProps[@"zoomTapEnabled"]){
58
- zoomTapEnabled = self.initialProps[@"zoomTapEnabled"];
49
+ _zoomTapEnabled = self.initialProps[@"zoomTapEnabled"];
59
50
  }
60
51
  if (self.initialProps[@"loadingBackgroundColor"]){
61
- backgroundColor = [RCTConvert UIColor:self.initialProps[@"loadingBackgroundColor"]];
52
+ _backgroundColor = [RCTConvert UIColor:self.initialProps[@"loadingBackgroundColor"]];
62
53
  }
63
54
  if (self.initialProps[@"initialCamera"]){
64
- camera = [RCTConvert GMSCameraPositionWithDefaults:self.initialProps[@"initialCamera"] existingCamera:nil];
55
+ _camera = [RCTConvert GMSCameraPositionWithDefaults:self.initialProps[@"initialCamera"] existingCamera:nil];
65
56
  }
66
57
  }
67
- AIRGoogleMap *map = [[AIRGoogleMap alloc] initWithMapId:googleMapId initialCamera:camera backgroundColor:backgroundColor andZoomTapEnabled:zoomTapEnabled];
58
+ AIRGoogleMap *map = [[AIRGoogleMap alloc] initWithMapId:self.googleMapId initialCamera:self.camera backgroundColor:self.backgroundColor andZoomTapEnabled:self.zoomTapEnabled];
68
59
  map.bridge = self.bridge;
69
60
  map.delegate = self;
70
61
  map.isAccessibilityElement = NO;
@@ -217,32 +208,8 @@ RCT_EXPORT_METHOD(fitToElements:(nonnull NSNumber *)reactTag
217
208
  if (![view isKindOfClass:[AIRGoogleMap class]]) {
218
209
  RCTLogError(@"Invalid view returned from registry, expecting AIRGoogleMap, got: %@", view);
219
210
  } else {
220
- AIRGoogleMap *mapView = (AIRGoogleMap *)view;
221
-
222
- CLLocationCoordinate2D myLocation = ((AIRGoogleMapMarker *)(mapView.markers.firstObject)).realMarker.position;
223
- GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
224
-
225
- for (AIRGoogleMapMarker *marker in mapView.markers)
226
- bounds = [bounds includingCoordinate:marker.realMarker.position];
227
-
228
- GMSCameraUpdate* cameraUpdate;
229
-
230
- if ([edgePadding count] != 0) {
231
- // Set Map viewport
232
- CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
233
- CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
234
- CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
235
- CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
236
-
237
- cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
238
- } else {
239
- cameraUpdate = [GMSCameraUpdate fitBounds:bounds withPadding:55.0f];
240
- }
241
- if (animated) {
242
- [mapView animateWithCameraUpdate: cameraUpdate];
243
- } else {
244
- [mapView moveCamera: cameraUpdate];
245
- }
211
+ AIRGoogleMap *mapView = (AIRGoogleMap *)view;
212
+ [mapView fitToElementsWithEdgePadding:edgePadding animated:animated];
246
213
  }
247
214
  }];
248
215
  }
@@ -257,40 +224,14 @@ RCT_EXPORT_METHOD(fitToSuppliedMarkers:(nonnull NSNumber *)reactTag
257
224
  if (![view isKindOfClass:[AIRGoogleMap class]]) {
258
225
  RCTLogError(@"Invalid view returned from registry, expecting AIRGoogleMap, got: %@", view);
259
226
  } else {
260
- AIRGoogleMap *mapView = (AIRGoogleMap *)view;
261
-
262
- NSPredicate *filterMarkers = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
263
- AIRGoogleMapMarker *marker = (AIRGoogleMapMarker *)evaluatedObject;
264
- return [marker isKindOfClass:[AIRGoogleMapMarker class]] && [markers containsObject:marker.identifier];
265
- }];
266
-
267
- NSArray *filteredMarkers = [mapView.markers filteredArrayUsingPredicate:filterMarkers];
268
-
269
- CLLocationCoordinate2D myLocation = ((AIRGoogleMapMarker *)(filteredMarkers.firstObject)).realMarker.position;
270
- GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
271
-
272
- for (AIRGoogleMapMarker *marker in filteredMarkers)
273
- bounds = [bounds includingCoordinate:marker.realMarker.position];
274
-
275
- // Set Map viewport
276
- CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
277
- CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
278
- CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
279
- CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
280
-
281
- GMSCameraUpdate* cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
282
- if (animated) {
283
- [mapView animateWithCameraUpdate:cameraUpdate
284
- ];
285
- } else {
286
- [mapView moveCamera: cameraUpdate];
287
- }
227
+ AIRGoogleMap *mapView = (AIRGoogleMap *)view;
228
+ [mapView fitToSuppliedMarkers:markers withEdgePadding:edgePadding animated:animated];
288
229
  }
289
230
  }];
290
231
  }
291
232
 
292
233
  RCT_EXPORT_METHOD(fitToCoordinates:(nonnull NSNumber *)reactTag
293
- coordinates:(nonnull NSArray<AIRMapCoordinate *> *)coordinates
234
+ coordinates:(nonnull NSArray<AIRGoogleMapCoordinate *> *)coordinates
294
235
  edgePadding:(nonnull NSDictionary *)edgePadding
295
236
  animated:(BOOL)animated)
296
237
  {
@@ -300,26 +241,7 @@ RCT_EXPORT_METHOD(fitToCoordinates:(nonnull NSNumber *)reactTag
300
241
  RCTLogError(@"Invalid view returned from registry, expecting AIRGoogleMap, got: %@", view);
301
242
  } else {
302
243
  AIRGoogleMap *mapView = (AIRGoogleMap *)view;
303
-
304
- CLLocationCoordinate2D myLocation = coordinates.firstObject.coordinate;
305
- GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
306
-
307
- for (AIRMapCoordinate *coordinate in coordinates)
308
- bounds = [bounds includingCoordinate:coordinate.coordinate];
309
-
310
- // Set Map viewport
311
- CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
312
- CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
313
- CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
314
- CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
315
-
316
- GMSCameraUpdate *cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
317
-
318
- if (animated) {
319
- [mapView animateWithCameraUpdate: cameraUpdate];
320
- } else {
321
- [mapView moveCamera: cameraUpdate];
322
- }
244
+ [mapView fitToCoordinates:coordinates withEdgePadding:edgePadding animated:animated];
323
245
  }
324
246
  }];
325
247
  }
@@ -331,7 +253,7 @@ RCT_EXPORT_METHOD(takeSnapshot:(nonnull NSNumber *)reactTag
331
253
  format:(nonnull NSString *)format
332
254
  quality:(nonnull NSNumber *)quality
333
255
  result:(nonnull NSString *)result
334
- withCallback:(RCTResponseSenderBlock)callback)
256
+ withCallback:(RCTPromiseResolveBlock)callback)
335
257
  {
336
258
  NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
337
259
  NSString *pathComponent = [NSString stringWithFormat:@"Documents/snapshot-%.20lf.%@", timeStamp, format];
@@ -342,7 +264,17 @@ RCT_EXPORT_METHOD(takeSnapshot:(nonnull NSNumber *)reactTag
342
264
  if (![view isKindOfClass:[AIRGoogleMap class]]) {
343
265
  RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
344
266
  } else {
345
- 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"];
346
278
 
347
279
  // TODO: currently we are ignoring width, height, region
348
280
 
@@ -388,13 +320,7 @@ RCT_EXPORT_METHOD(pointForCoordinate:(nonnull NSNumber *)reactTag
388
320
  RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
389
321
  } else {
390
322
  AIRGoogleMap *mapView = (AIRGoogleMap *)view;
391
-
392
- CGPoint touchPoint = [mapView.projection pointForCoordinate:coord];
393
-
394
- resolve(@{
395
- @"x": @(touchPoint.x),
396
- @"y": @(touchPoint.y),
397
- });
323
+ resolve([mapView getPointForCoordinates:coord]);
398
324
  }
399
325
  }];
400
326
  }
@@ -415,13 +341,7 @@ RCT_EXPORT_METHOD(coordinateForPoint:(nonnull NSNumber *)reactTag
415
341
  RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
416
342
  } else {
417
343
  AIRGoogleMap *mapView = (AIRGoogleMap *)view;
418
-
419
- CLLocationCoordinate2D coordinate = [mapView.projection coordinateForPoint:pt];
420
-
421
- resolve(@{
422
- @"latitude": @(coordinate.latitude),
423
- @"longitude": @(coordinate.longitude),
424
- });
344
+ resolve([view getCoordinatesForPoint:pt]);
425
345
  }
426
346
  }];
427
347
  }
@@ -451,18 +371,7 @@ RCT_EXPORT_METHOD(getMapBoundaries:(nonnull NSNumber *)reactTag
451
371
  if (![view isKindOfClass:[AIRGoogleMap class]]) {
452
372
  RCTLogError(@"Invalid view returned from registry, expecting AIRGoogleMap, got: %@", view);
453
373
  } else {
454
- NSArray *boundingBox = [view getMapBoundaries];
455
-
456
- resolve(@{
457
- @"northEast" : @{
458
- @"longitude" : boundingBox[0][0],
459
- @"latitude" : boundingBox[0][1]
460
- },
461
- @"southWest" : @{
462
- @"longitude" : boundingBox[1][0],
463
- @"latitude" : boundingBox[1][1]
464
- }
465
- });
374
+ resolve([view getMapBoundaries]);
466
375
  }
467
376
  }];
468
377
  }
@@ -11,7 +11,6 @@
11
11
  #import "AIRGoogleMapMarker.h"
12
12
  #import <MapKit/MapKit.h>
13
13
  #import <React/RCTUIManager.h>
14
- #import "RCTConvert+AirMap.h"
15
14
 
16
15
  @implementation AIRGoogleMapMarkerManager
17
16