react-native-maps 2.0.0-beta.6 → 2.0.0-beta.8

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.
@@ -122,163 +122,6 @@ RCT_EXPORT_METHOD(setCamera:(nonnull NSNumber *)reactTag
122
122
  }];
123
123
  }
124
124
 
125
-
126
- RCT_EXPORT_METHOD(animateCamera:(nonnull NSNumber *)reactTag
127
- withCamera:(id)json
128
- withDuration:(CGFloat)duration)
129
- {
130
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
131
- id view = viewRegistry[reactTag];
132
- if (![view isKindOfClass:[RNMGoogleMap class]]) {
133
- RCTLogError(@"Invalid view returned from registry, expecting RNMGoogleMap, got: %@", view);
134
- } else {
135
- [CATransaction begin];
136
- [CATransaction setAnimationDuration:duration/1000];
137
- RNMGoogleMap *mapView = (RNMGoogleMap *)view;
138
- GMSCameraPosition *camera = [RCTConvert GMSCameraPositionWithDefaults:json existingCamera:[mapView camera]];
139
- [mapView animateToCameraPosition:camera];
140
- [CATransaction commit];
141
- }
142
- }];
143
- }
144
-
145
- RCT_EXPORT_METHOD(animateToRegion:(nonnull NSNumber *)reactTag
146
- withRegion:(MKCoordinateRegion)region
147
- withDuration:(CGFloat)duration)
148
- {
149
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
150
- id view = viewRegistry[reactTag];
151
- if (![view isKindOfClass:[RNMGoogleMap class]]) {
152
- RCTLogError(@"Invalid view returned from registry, expecting RNMGoogleMap, got: %@", view);
153
- } else {
154
- // Core Animation must be used to control the animation's duration
155
- // See http://stackoverflow.com/a/15663039/171744
156
- [CATransaction begin];
157
- [CATransaction setAnimationDuration:duration/1000];
158
- RNMGoogleMap *mapView = (RNMGoogleMap *)view;
159
- GMSCameraPosition *camera = [RNMGoogleMap makeGMSCameraPositionFromMap:mapView andMKCoordinateRegion:region];
160
- [mapView animateToCameraPosition:camera];
161
- [CATransaction commit];
162
- }
163
- }];
164
- }
165
-
166
- RCT_EXPORT_METHOD(fitToElements:(nonnull NSNumber *)reactTag
167
- edgePadding:(nonnull NSDictionary *)edgePadding
168
- animated:(BOOL)animated)
169
- {
170
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
171
- id view = viewRegistry[reactTag];
172
- if (![view isKindOfClass:[RNMGoogleMap class]]) {
173
- RCTLogError(@"Invalid view returned from registry, expecting RNMGoogleMap, got: %@", view);
174
- } else {
175
- RNMGoogleMap *mapView = (RNMGoogleMap *)view;
176
-
177
- CLLocationCoordinate2D myLocation = ((RNMGoogleMapMarker *)(mapView.markers.firstObject)).realMarker.position;
178
- GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
179
-
180
- for (RNMGoogleMapMarker *marker in mapView.markers)
181
- bounds = [bounds includingCoordinate:marker.realMarker.position];
182
-
183
- GMSCameraUpdate* cameraUpdate;
184
-
185
- if ([edgePadding count] != 0) {
186
- // Set Map viewport
187
- CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
188
- CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
189
- CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
190
- CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
191
-
192
- cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
193
- } else {
194
- cameraUpdate = [GMSCameraUpdate fitBounds:bounds withPadding:55.0f];
195
- }
196
- if (animated) {
197
- [mapView animateWithCameraUpdate: cameraUpdate];
198
- } else {
199
- [mapView moveCamera: cameraUpdate];
200
- }
201
- }
202
- }];
203
- }
204
-
205
- RCT_EXPORT_METHOD(fitToSuppliedMarkers:(nonnull NSNumber *)reactTag
206
- markers:(nonnull NSArray *)markers
207
- edgePadding:(nonnull NSDictionary *)edgePadding
208
- animated:(BOOL)animated)
209
- {
210
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
211
- id view = viewRegistry[reactTag];
212
- if (![view isKindOfClass:[RNMGoogleMap class]]) {
213
- RCTLogError(@"Invalid view returned from registry, expecting RNMGoogleMap, got: %@", view);
214
- } else {
215
- RNMGoogleMap *mapView = (RNMGoogleMap *)view;
216
-
217
- NSPredicate *filterMarkers = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
218
- RNMGoogleMapMarker *marker = (RNMGoogleMapMarker *)evaluatedObject;
219
- return [marker isKindOfClass:[RNMGoogleMapMarker class]] && [markers containsObject:marker.identifier];
220
- }];
221
-
222
- NSArray *filteredMarkers = [mapView.markers filteredArrayUsingPredicate:filterMarkers];
223
-
224
- CLLocationCoordinate2D myLocation = ((RNMGoogleMapMarker *)(filteredMarkers.firstObject)).realMarker.position;
225
- GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
226
-
227
- for (RNMGoogleMapMarker *marker in filteredMarkers)
228
- bounds = [bounds includingCoordinate:marker.realMarker.position];
229
-
230
- // Set Map viewport
231
- CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
232
- CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
233
- CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
234
- CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
235
-
236
- GMSCameraUpdate* cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
237
- if (animated) {
238
- [mapView animateWithCameraUpdate:cameraUpdate
239
- ];
240
- } else {
241
- [mapView moveCamera: cameraUpdate];
242
- }
243
- }
244
- }];
245
- }
246
-
247
- RCT_EXPORT_METHOD(fitToCoordinates:(nonnull NSNumber *)reactTag
248
- coordinates:(nonnull NSArray<RNMMapCoordinate *> *)coordinates
249
- edgePadding:(nonnull NSDictionary *)edgePadding
250
- animated:(BOOL)animated)
251
- {
252
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
253
- id view = viewRegistry[reactTag];
254
- if (![view isKindOfClass:[RNMGoogleMap class]]) {
255
- RCTLogError(@"Invalid view returned from registry, expecting RNMGoogleMap, got: %@", view);
256
- } else {
257
- RNMGoogleMap *mapView = (RNMGoogleMap *)view;
258
-
259
- CLLocationCoordinate2D myLocation = coordinates.firstObject.coordinate;
260
- GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
261
-
262
- for (RNMMapCoordinate *coordinate in coordinates)
263
- bounds = [bounds includingCoordinate:coordinate.coordinate];
264
-
265
- // Set Map viewport
266
- CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
267
- CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
268
- CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
269
- CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
270
-
271
- GMSCameraUpdate *cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
272
-
273
- if (animated) {
274
- [mapView animateWithCameraUpdate: cameraUpdate];
275
- } else {
276
- [mapView moveCamera: cameraUpdate];
277
- }
278
- }
279
- }];
280
- }
281
-
282
125
  RCT_EXPORT_METHOD(setMapBoundaries:(nonnull NSNumber *)reactTag
283
126
  northEast:(CLLocationCoordinate2D)northEast
284
127
  southWest:(CLLocationCoordinate2D)southWest)
@@ -1,5 +1,8 @@
1
1
  #import "RNMGoogleMapViewModule.h"
2
2
  #import "RNMGoogleMap.h"
3
+ #import "RNMGoogleMapMarker.h"
4
+ #import "RNMMapCoordinate.h"
5
+ #import "RCTConvert+GMSMapViewType.h"
3
6
  #import <React/RCTUIManager.h>
4
7
  #import <React/RCTUIManagerUtils.h>
5
8
 
@@ -180,4 +183,198 @@ RCT_EXPORT_METHOD(getMapBoundaries:(nonnull NSNumber *)reactTag
180
183
  }];
181
184
  }
182
185
 
186
+ RCT_EXPORT_METHOD(animateToRegion:(nonnull NSNumber *)reactTag
187
+ withRegion:(NSDictionary *)region
188
+ withDuration:(CGFloat)duration
189
+ resolver: (RCTPromiseResolveBlock)resolve
190
+ rejecter:(RCTPromiseRejectBlock)reject)
191
+ {
192
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
193
+ id view = viewRegistry[reactTag];
194
+ if (![view isKindOfClass:[RNMGoogleMap class]]) {
195
+ RCTLogError(@"Invalid view returned from registry, expecting RNMGoogleMap, got: %@", view);
196
+ } else {
197
+ RNMGoogleMap *mapView = (RNMGoogleMap *)view;
198
+ MKCoordinateRegion mkRegion = [RCTConvert MKCoordinateRegion:region];
199
+ GMSCameraPosition *camera = [RNMGoogleMap makeGMSCameraPositionFromMap:mapView andMKCoordinateRegion:mkRegion];
200
+ // Core Animation must be used to control the animation's duration
201
+ // See http://stackoverflow.com/a/15663039/171744
202
+ [CATransaction begin];
203
+ [CATransaction setCompletionBlock:^{
204
+ resolve(nil);
205
+ }];
206
+ [CATransaction setAnimationDuration:duration/1000];
207
+ [mapView animateToCameraPosition:camera];
208
+ [CATransaction commit];
209
+ }
210
+ }];
211
+ }
212
+
213
+ RCT_EXPORT_METHOD(animateCamera:(nonnull NSNumber *)reactTag
214
+ withCamera:(id)json
215
+ withDuration:(CGFloat)duration
216
+ resolver: (RCTPromiseResolveBlock)resolve
217
+ rejecter:(RCTPromiseRejectBlock)reject)
218
+ {
219
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
220
+ id view = viewRegistry[reactTag];
221
+ if (![view isKindOfClass:[RNMGoogleMap class]]) {
222
+ RCTLogError(@"Invalid view returned from registry, expecting RNMGoogleMap, got: %@", view);
223
+ } else {
224
+ RNMGoogleMap *mapView = (RNMGoogleMap *)view;
225
+ GMSCameraPosition *camera = [RCTConvert GMSCameraPositionWithDefaults:json existingCamera:[mapView camera]];
226
+
227
+ [CATransaction begin];
228
+ [CATransaction setCompletionBlock:^{
229
+ resolve(nil);
230
+ }];
231
+ [CATransaction setAnimationDuration:duration/1000];
232
+ [mapView animateToCameraPosition:camera];
233
+ [CATransaction commit];
234
+ }
235
+ }];
236
+ }
237
+
238
+ RCT_EXPORT_METHOD(fitToElements:(nonnull NSNumber *)reactTag
239
+ edgePadding:(nonnull NSDictionary *)edgePadding
240
+ withDuration:(CGFloat)duration
241
+ resolver: (RCTPromiseResolveBlock)resolve
242
+ rejecter:(RCTPromiseRejectBlock)reject)
243
+ {
244
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
245
+ id view = viewRegistry[reactTag];
246
+ if (![view isKindOfClass:[RNMGoogleMap class]]) {
247
+ RCTLogError(@"Invalid view returned from registry, expecting RNMGoogleMap, got: %@", view);
248
+ } else {
249
+ RNMGoogleMap *mapView = (RNMGoogleMap *)view;
250
+
251
+ CLLocationCoordinate2D myLocation = ((RNMGoogleMapMarker *)(mapView.markers.firstObject)).realMarker.position;
252
+ GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
253
+
254
+ for (RNMGoogleMapMarker *marker in mapView.markers)
255
+ bounds = [bounds includingCoordinate:marker.realMarker.position];
256
+
257
+ GMSCameraUpdate* cameraUpdate;
258
+
259
+ if ([edgePadding count] != 0) {
260
+ // Set Map viewport
261
+ CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
262
+ CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
263
+ CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
264
+ CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
265
+
266
+ cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
267
+ } else {
268
+ cameraUpdate = [GMSCameraUpdate fitBounds:bounds withPadding:55.0f];
269
+ }
270
+ if (duration > 0.0f) {
271
+ [CATransaction begin];
272
+ [CATransaction setCompletionBlock:^{
273
+ resolve(nil);
274
+ }];
275
+ [CATransaction setAnimationDuration:duration/1000];
276
+ [mapView animateWithCameraUpdate:cameraUpdate];
277
+ [CATransaction commit];
278
+ } else {
279
+ [mapView moveCamera:cameraUpdate];
280
+ resolve(nil);
281
+ }
282
+ }
283
+ }];
284
+ }
285
+
286
+ RCT_EXPORT_METHOD(fitToSuppliedMarkers:(nonnull NSNumber *)reactTag
287
+ markers:(nonnull NSArray *)markers
288
+ edgePadding:(nonnull NSDictionary *)edgePadding
289
+ withDuration:(CGFloat)duration
290
+ resolver: (RCTPromiseResolveBlock)resolve
291
+ rejecter:(RCTPromiseRejectBlock)reject)
292
+ {
293
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
294
+ id view = viewRegistry[reactTag];
295
+ if (![view isKindOfClass:[RNMGoogleMap class]]) {
296
+ RCTLogError(@"Invalid view returned from registry, expecting RNMGoogleMap, got: %@", view);
297
+ } else {
298
+ RNMGoogleMap *mapView = (RNMGoogleMap *)view;
299
+
300
+ NSPredicate *filterMarkers = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
301
+ RNMGoogleMapMarker *marker = (RNMGoogleMapMarker *)evaluatedObject;
302
+ return [marker isKindOfClass:[RNMGoogleMapMarker class]] && [markers containsObject:marker.identifier];
303
+ }];
304
+
305
+ NSArray *filteredMarkers = [mapView.markers filteredArrayUsingPredicate:filterMarkers];
306
+
307
+ CLLocationCoordinate2D myLocation = ((RNMGoogleMapMarker *)(filteredMarkers.firstObject)).realMarker.position;
308
+ GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
309
+
310
+ for (RNMGoogleMapMarker *marker in filteredMarkers)
311
+ bounds = [bounds includingCoordinate:marker.realMarker.position];
312
+
313
+ // Set Map viewport
314
+ CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
315
+ CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
316
+ CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
317
+ CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
318
+
319
+ GMSCameraUpdate* cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
320
+ if (duration > 0.0f) {
321
+ [CATransaction begin];
322
+ [CATransaction setCompletionBlock:^{
323
+ resolve(nil);
324
+ }];
325
+ [CATransaction setAnimationDuration:duration/1000];
326
+ [mapView animateWithCameraUpdate:cameraUpdate];
327
+ [CATransaction commit];
328
+ } else {
329
+ [mapView moveCamera:cameraUpdate];
330
+ resolve(nil);
331
+ }
332
+ }
333
+ }];
334
+ }
335
+
336
+ RCT_EXPORT_METHOD(fitToCoordinates:(nonnull NSNumber *)reactTag
337
+ coordinates:(nonnull NSArray<RNMMapCoordinate *> *)coordinates
338
+ edgePadding:(nonnull NSDictionary *)edgePadding
339
+ withDuration:(CGFloat)duration
340
+ resolver: (RCTPromiseResolveBlock)resolve
341
+ rejecter:(RCTPromiseRejectBlock)reject)
342
+ {
343
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
344
+ id view = viewRegistry[reactTag];
345
+ if (![view isKindOfClass:[RNMGoogleMap class]]) {
346
+ RCTLogError(@"Invalid view returned from registry, expecting RNMGoogleMap, got: %@", view);
347
+ } else {
348
+ RNMGoogleMap *mapView = (RNMGoogleMap *)view;
349
+
350
+ CLLocationCoordinate2D myLocation = coordinates.firstObject.coordinate;
351
+ GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];
352
+
353
+ for (RNMMapCoordinate *coordinate in coordinates)
354
+ bounds = [bounds includingCoordinate:coordinate.coordinate];
355
+
356
+ // Set Map viewport
357
+ CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
358
+ CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
359
+ CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
360
+ CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
361
+
362
+ GMSCameraUpdate *cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
363
+
364
+ if (duration > 0.0f) {
365
+ [CATransaction begin];
366
+ [CATransaction setCompletionBlock:^{
367
+ resolve(nil);
368
+ }];
369
+ [CATransaction setAnimationDuration:duration/1000];
370
+ [mapView animateWithCameraUpdate:cameraUpdate];
371
+ [CATransaction commit];
372
+ } else {
373
+ [mapView moveCamera: cameraUpdate];
374
+ resolve(nil);
375
+ }
376
+ }
377
+ }];
378
+ }
379
+
183
380
  @end
@@ -197,125 +197,6 @@ RCT_EXPORT_METHOD(setCamera:(nonnull NSNumber *)reactTag
197
197
  }];
198
198
  }
199
199
 
200
- RCT_EXPORT_METHOD(animateCamera:(nonnull NSNumber *)reactTag
201
- withCamera:(id)json
202
- withDuration:(CGFloat)duration)
203
- {
204
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
205
- id view = viewRegistry[reactTag];
206
- if (![view isKindOfClass:[RNMMap class]]) {
207
- RCTLogError(@"Invalid view returned from registry, expecting RNMMap, got: %@", view);
208
- } else {
209
- RNMMap *mapView = (RNMMap *)view;
210
-
211
- // Merge the changes given with the current camera
212
- MKMapCamera *camera = [RCTConvert MKMapCameraWithDefaults:json existingCamera:[mapView camera]];
213
-
214
- // don't emit region change events when we are setting the camera
215
- BOOL originalIgnore = mapView.ignoreRegionChanges;
216
- mapView.ignoreRegionChanges = YES;
217
- [RNMMap animateWithDuration:duration/1000 animations:^{
218
- [mapView setCamera:camera animated:YES];
219
- } completion:^(BOOL finished){
220
- mapView.ignoreRegionChanges = originalIgnore;
221
- }];
222
- }
223
- }];
224
- }
225
-
226
- RCT_EXPORT_METHOD(animateToRegion:(nonnull NSNumber *)reactTag
227
- withRegion:(MKCoordinateRegion)region
228
- withDuration:(CGFloat)duration)
229
- {
230
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
231
- id view = viewRegistry[reactTag];
232
- if (![view isKindOfClass:[RNMMap class]]) {
233
- RCTLogError(@"Invalid view returned from registry, expecting RNMMap, got: %@", view);
234
- } else {
235
- [RNMMap animateWithDuration:duration/1000 animations:^{
236
- [(RNMMap *)view setRegion:region animated:YES];
237
- }];
238
- }
239
- }];
240
- }
241
-
242
- RCT_EXPORT_METHOD(fitToElements:(nonnull NSNumber *)reactTag
243
- edgePadding:(nonnull NSDictionary *)edgePadding
244
- animated:(BOOL)animated)
245
- {
246
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
247
- id view = viewRegistry[reactTag];
248
- if (![view isKindOfClass:[RNMMap class]]) {
249
- RCTLogError(@"Invalid view returned from registry, expecting RNMMap, got: %@", view);
250
- } else {
251
- RNMMap *mapView = (RNMMap *)view;
252
- // TODO(lmr): we potentially want to include overlays here... and could concat the two arrays together.
253
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
254
- [mapView showAnnotations:mapView.annotations animated:animated];
255
- });
256
- }
257
- }];
258
- }
259
-
260
- RCT_EXPORT_METHOD(fitToSuppliedMarkers:(nonnull NSNumber *)reactTag
261
- markers:(nonnull NSArray *)markers
262
- edgePadding:(nonnull NSDictionary *)edgePadding
263
- animated:(BOOL)animated)
264
- {
265
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
266
- id view = viewRegistry[reactTag];
267
- if (![view isKindOfClass:[RNMMap class]]) {
268
- RCTLogError(@"Invalid view returned from registry, expecting RNMMap, got: %@", view);
269
- } else {
270
- RNMMap *mapView = (RNMMap *)view;
271
- // TODO(lmr): we potentially want to include overlays here... and could concat the two arrays together.
272
- // id annotations = mapView.annotations;
273
-
274
- NSPredicate *filterMarkers = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
275
- RNMMapMarker *marker = (RNMMapMarker *)evaluatedObject;
276
- return [marker isKindOfClass:[RNMMapMarker class]] && [markers containsObject:marker.identifier];
277
- }];
278
-
279
- NSArray *filteredMarkers = [mapView.annotations filteredArrayUsingPredicate:filterMarkers];
280
-
281
- [mapView showAnnotations:filteredMarkers animated:animated];
282
-
283
- }
284
- }];
285
- }
286
-
287
- RCT_EXPORT_METHOD(fitToCoordinates:(nonnull NSNumber *)reactTag
288
- coordinates:(nonnull NSArray<RNMMapCoordinate *> *)coordinates
289
- edgePadding:(nonnull NSDictionary *)edgePadding
290
- animated:(BOOL)animated)
291
- {
292
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
293
- id view = viewRegistry[reactTag];
294
- if (![view isKindOfClass:[RNMMap class]]) {
295
- RCTLogError(@"Invalid view returned from registry, expecting RNMMap, got: %@", view);
296
- } else {
297
- RNMMap *mapView = (RNMMap *)view;
298
-
299
- // Create Polyline with coordinates
300
- CLLocationCoordinate2D coords[coordinates.count];
301
- for(int i = 0; i < coordinates.count; i++)
302
- {
303
- coords[i] = coordinates[i].coordinate;
304
- }
305
- MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordinates.count];
306
-
307
- // Set Map viewport
308
- CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
309
- CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
310
- CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
311
- CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
312
-
313
- [mapView setVisibleMapRect:[polyline boundingMapRect] edgePadding:UIEdgeInsetsMake(top, left, bottom, right) animated:animated];
314
-
315
- }
316
- }];
317
- }
318
-
319
200
  #pragma mark Gesture Recognizer Handlers
320
201
 
321
202
  #define MAX_DISTANCE_PX 10.0f
@@ -1,6 +1,8 @@
1
1
  #import "RNMMapViewModule.h"
2
2
  #import "RNMMap.h"
3
+ #import "RNMMapMarker.h"
3
4
  #import "RNMMapSnapshot.h"
5
+ #import "RNMMapCoordinate.h"
4
6
  #import <React/RCTUIManager.h>
5
7
  #import <React/RCTUIManagerUtils.h>
6
8
 
@@ -217,6 +219,166 @@ RCT_EXPORT_METHOD(getAddressFromCoordinates:(nonnull NSNumber *)reactTag
217
219
  }];
218
220
  }
219
221
 
222
+ RCT_EXPORT_METHOD(animateToRegion:(nonnull NSNumber *)reactTag
223
+ withRegion:(NSDictionary *)region
224
+ withDuration:(CGFloat)duration
225
+ resolver: (RCTPromiseResolveBlock)resolve
226
+ rejecter:(RCTPromiseRejectBlock)reject)
227
+ {
228
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
229
+ id view = viewRegistry[reactTag];
230
+ if (![view isKindOfClass:[RNMMap class]]) {
231
+ RCTLogError(@"Invalid view returned from registry, expecting RNMMap, got: %@", view);
232
+ } else {
233
+ MKCoordinateRegion mkRegion = [RCTConvert MKCoordinateRegion:region];
234
+ [RNMMap animateWithDuration:duration/1000 animations:^{
235
+ [(RNMMap *)view setRegion:mkRegion animated:YES];
236
+ } completion:^(BOOL finished){
237
+ resolve(nil);
238
+ }];
239
+ }
240
+ }];
241
+ }
242
+
243
+ RCT_EXPORT_METHOD(animateCamera:(nonnull NSNumber *)reactTag
244
+ withCamera:(id)json
245
+ withDuration:(CGFloat)duration
246
+ resolver: (RCTPromiseResolveBlock)resolve
247
+ rejecter:(RCTPromiseRejectBlock)reject)
248
+ {
249
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
250
+ id view = viewRegistry[reactTag];
251
+ if (![view isKindOfClass:[RNMMap class]]) {
252
+ RCTLogError(@"Invalid view returned from registry, expecting RNMMap, got: %@", view);
253
+ } else {
254
+ RNMMap *mapView = (RNMMap *)view;
255
+
256
+ // Merge the changes given with the current camera
257
+ MKMapCamera *camera = [RCTConvert MKMapCameraWithDefaults:json existingCamera:[mapView camera]];
258
+
259
+ // don't emit region change events when we are setting the camera
260
+ BOOL originalIgnore = mapView.ignoreRegionChanges;
261
+ mapView.ignoreRegionChanges = YES;
262
+ [RNMMap animateWithDuration:duration/1000 animations:^{
263
+ [mapView setCamera:camera animated:YES];
264
+ } completion:^(BOOL finished){
265
+ mapView.ignoreRegionChanges = originalIgnore;
266
+ resolve(nil);
267
+ }];
268
+ }
269
+ }];
270
+ }
271
+
272
+ RCT_EXPORT_METHOD(fitToElements:(nonnull NSNumber *)reactTag
273
+ edgePadding:(nonnull NSDictionary *)edgePadding
274
+ withDuration:(CGFloat)duration
275
+ resolver: (RCTPromiseResolveBlock)resolve
276
+ rejecter:(RCTPromiseRejectBlock)reject)
277
+ {
278
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
279
+ id view = viewRegistry[reactTag];
280
+ if (![view isKindOfClass:[RNMMap class]]) {
281
+ RCTLogError(@"Invalid view returned from registry, expecting RNMMap, got: %@", view);
282
+ } else {
283
+ RNMMap *mapView = (RNMMap *)view;
284
+
285
+ // TODO(lmr): we potentially want to include overlays here... and could concat the two arrays together.
286
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
287
+ if(duration > 0.0f) {
288
+ [RNMMap animateWithDuration:duration/1000 animations:^{
289
+ [mapView showAnnotations:mapView.annotations animated:YES];
290
+ } completion:^(BOOL finished){
291
+ resolve(nil);
292
+ }];
293
+ } else {
294
+ [mapView showAnnotations:mapView.annotations animated:NO];
295
+ resolve(nil);
296
+ }
297
+
298
+ });
299
+ }
300
+ }];
301
+ }
302
+
303
+ RCT_EXPORT_METHOD(fitToSuppliedMarkers:(nonnull NSNumber *)reactTag
304
+ markers:(nonnull NSArray *)markers
305
+ edgePadding:(nonnull NSDictionary *)edgePadding
306
+ withDuration:(CGFloat)duration
307
+ resolver:(RCTPromiseResolveBlock)resolve
308
+ rejecter:(RCTPromiseRejectBlock)reject)
309
+ {
310
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
311
+ id view = viewRegistry[reactTag];
312
+ if (![view isKindOfClass:[RNMMap class]]) {
313
+ RCTLogError(@"Invalid view returned from registry, expecting RNMMap, got: %@", view);
314
+ } else {
315
+ RNMMap *mapView = (RNMMap *)view;
316
+ // TODO(lmr): we potentially want to include overlays here... and could concat the two arrays together.
317
+ // id annotations = mapView.annotations;
318
+
319
+ NSPredicate *filterMarkers = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
320
+ RNMMapMarker *marker = (RNMMapMarker *)evaluatedObject;
321
+ return [marker isKindOfClass:[RNMMapMarker class]] && [markers containsObject:marker.identifier];
322
+ }];
323
+
324
+ NSArray *filteredMarkers = [mapView.annotations filteredArrayUsingPredicate:filterMarkers];
325
+
326
+ if(duration > 0.0f) {
327
+ [RNMMap animateWithDuration:duration/1000 animations:^{
328
+ [mapView showAnnotations:filteredMarkers animated:YES];
329
+ } completion:^(BOOL finished){
330
+ resolve(nil);
331
+ }];
332
+ } else {
333
+ [mapView showAnnotations:filteredMarkers animated:NO];
334
+ resolve(nil);
335
+ }
336
+ }
337
+ }];
338
+ }
339
+
340
+ RCT_EXPORT_METHOD(fitToCoordinates:(nonnull NSNumber *)reactTag
341
+ coordinates:(nonnull NSArray<RNMMapCoordinate *> *)coordinates
342
+ edgePadding:(nonnull NSDictionary *)edgePadding
343
+ withDuration:(CGFloat)duration
344
+ resolver:(RCTPromiseResolveBlock)resolve
345
+ rejecter:(RCTPromiseRejectBlock)reject)
346
+ {
347
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
348
+ id view = viewRegistry[reactTag];
349
+ if (![view isKindOfClass:[RNMMap class]]) {
350
+ RCTLogError(@"Invalid view returned from registry, expecting RNMMap, got: %@", view);
351
+ } else {
352
+ RNMMap *mapView = (RNMMap *)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
+ if(duration > 0.0f) {
369
+ [RNMMap animateWithDuration:duration/1000 animations:^{
370
+ [mapView setVisibleMapRect:[polyline boundingMapRect] edgePadding:UIEdgeInsetsMake(top, left, bottom, right) animated:YES];
371
+ } completion:^(BOOL finished){
372
+ resolve(nil);
373
+ }];
374
+ } else {
375
+ [mapView setVisibleMapRect:[polyline boundingMapRect] edgePadding:UIEdgeInsetsMake(top, left, bottom, right) animated:NO];
376
+ resolve(nil);
377
+ }
378
+ }
379
+ }];
380
+ }
381
+
220
382
  - (void)takeMapSnapshot:(RNMMap *)mapView
221
383
  snapshotter:(MKMapSnapshotter *) snapshotter
222
384
  format:(NSString *)format