@@ -85,6 +85,64 @@ - (UIView *)view
85
85
}];
86
86
}
87
87
88
+ RCT_EXPORT_METHOD (fitToSuppliedMarkers:(nonnull NSNumber *)reactTag
89
+ markers:(nonnull NSArray *)markers
90
+ animated:(BOOL )animated)
91
+ {
92
+ [self .bridge.uiManager addUIBlock: ^(__unused RCTUIManager *uiManager, NSDictionary <NSNumber *, UIView *> *viewRegistry) {
93
+ id view = viewRegistry[reactTag];
94
+ if (![view isKindOfClass: [AIRGoogleMap class ]]) {
95
+ RCTLogError (@" Invalid view returned from registry, expecting AIRGoogleMap, got: %@ " , view);
96
+ } else {
97
+ AIRGoogleMap *mapView = (AIRGoogleMap *)view;
98
+
99
+ NSPredicate *filterMarkers = [NSPredicate predicateWithBlock: ^BOOL (id evaluatedObject, NSDictionary *bindings) {
100
+ AIRGoogleMapMarker *marker = (AIRGoogleMapMarker *)evaluatedObject;
101
+ return [marker isKindOfClass: [AIRGoogleMapMarker class ]] && [markers containsObject: marker.identifier];
102
+ }];
103
+
104
+ NSArray *filteredMarkers = [mapView.markers filteredArrayUsingPredicate: filterMarkers];
105
+
106
+ CLLocationCoordinate2D myLocation = ((AIRGoogleMapMarker *)(filteredMarkers.firstObject )).realMarker .position ;
107
+ GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc ] initWithCoordinate: myLocation coordinate: myLocation];
108
+
109
+ for (AIRGoogleMapMarker *marker in filteredMarkers)
110
+ bounds = [bounds includingCoordinate: marker.realMarker.position];
111
+
112
+ [mapView animateWithCameraUpdate: [GMSCameraUpdate fitBounds: bounds withPadding: 55 .0f ]];
113
+ }
114
+ }];
115
+ }
116
+
117
+ RCT_EXPORT_METHOD (fitToCoordinates:(nonnull NSNumber *)reactTag
118
+ coordinates:(nonnull NSArray <AIRMapCoordinate *> *)coordinates
119
+ edgePadding:(nonnull NSDictionary *)edgePadding
120
+ animated:(BOOL )animated)
121
+ {
122
+ [self .bridge.uiManager addUIBlock: ^(__unused RCTUIManager *uiManager, NSDictionary <NSNumber *, UIView *> *viewRegistry) {
123
+ id view = viewRegistry[reactTag];
124
+ if (![view isKindOfClass: [AIRGoogleMap class ]]) {
125
+ RCTLogError (@" Invalid view returned from registry, expecting AIRGoogleMap, got: %@ " , view);
126
+ } else {
127
+ AIRGoogleMap *mapView = (AIRGoogleMap *)view;
128
+
129
+ CLLocationCoordinate2D myLocation = coordinates.firstObject .coordinate ;
130
+ GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc ] initWithCoordinate: myLocation coordinate: myLocation];
131
+
132
+ for (AIRMapCoordinate *coordinate in coordinates)
133
+ bounds = [bounds includingCoordinate: coordinate.coordinate];
134
+
135
+ // Set Map viewport
136
+ CGFloat top = [RCTConvert CGFloat: edgePadding[@" top" ]];
137
+ CGFloat right = [RCTConvert CGFloat: edgePadding[@" right" ]];
138
+ CGFloat bottom = [RCTConvert CGFloat: edgePadding[@" bottom" ]];
139
+ CGFloat left = [RCTConvert CGFloat: edgePadding[@" left" ]];
140
+
141
+ [mapView animateWithCameraUpdate: [GMSCameraUpdate fitBounds: bounds withEdgeInsets: UIEdgeInsetsMake (top, left, bottom, right)]];
142
+ }
143
+ }];
144
+ }
145
+
88
146
RCT_EXPORT_METHOD (takeSnapshot:(nonnull NSNumber *)reactTag
89
147
withWidth:(nonnull NSNumber *)width
90
148
withHeight:(nonnull NSNumber *)height
0 commit comments