diff --git a/index.ios.js b/index.ios.js index d4a62419f..2070d0552 100644 --- a/index.ios.js +++ b/index.ios.js @@ -24,6 +24,9 @@ var MapMixins = { }, removeAnnotation(mapRef, annotationInArray) { NativeModules.MapboxGLManager.removeAnnotation(React.findNodeHandle(this.refs[mapRef]), annotationInArray); + }, + setVisibleCoordinateBoundsAnimated(mapRef, latitudeSW, longitudeSW, latitudeNE, longitudeNE, edge) { + NativeModules.MapboxGLManager.setVisibleCoordinateBoundsAnimated(React.findNodeHandle(this.refs[mapRef]), latitudeSW, longitudeSW, latitudeNE, longitudeNE, edge); } }; diff --git a/ios/API.md b/ios/API.md index 09f653e6d..d2d389f2e 100644 --- a/ios/API.md +++ b/ios/API.md @@ -41,6 +41,7 @@ These methods require you to use `MapboxGLMap.Mixin` to access the methods. Each | `addAnnotations` | `mapViewRef`, `` (array of annotation objects, see [#annotations](https://github.com/bsudekum/react-native-mapbox-gl/blob/master/API.md#annotations)) | Adds annotation(s) to the map without redrawing the map. Note, this will remove all previous annotations from the map. | `selectAnnotationAnimated` | `mapViewRef`, `annotationPlaceInArray` | Open the callout of the selected annotation. This method works with the current annotations on the map. `annotationPlaceInArray` starts at 0 and refers to the first annotation. | `removeAnnotation` | `mapViewRef`, `annotationPlaceInArray` | Removes the selected annotation from the map. This method works with the current annotations on the map. `annotationPlaceInArray` starts at 0 and refers to the first annotation. +| `setVisibleCoordinateBoundsAnimated` | `mapViewRef`, `latitude1`, `longitude1`, `latitude2`, `longitude2`, `edgePadding` | Changes the viewport to fit the given coordinate bounds and some additional padding on each side. ## GL Styles diff --git a/ios/RCTMapboxGL/RCTMapboxGL.h b/ios/RCTMapboxGL/RCTMapboxGL.h index db43bb1f4..c76171bea 100644 --- a/ios/RCTMapboxGL/RCTMapboxGL.h +++ b/ios/RCTMapboxGL/RCTMapboxGL.h @@ -34,6 +34,7 @@ - (void)setCenterCoordinateZoomLevelAnimated:(CLLocationCoordinate2D)coordinates zoomLevel:(double)zoomLevel; - (void)selectAnnotationAnimated:(NSUInteger)annotationInArray; - (void)removeAnnotation:(NSUInteger)annotationInArray; +- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)padding animated:(BOOL)animated; @end diff --git a/ios/RCTMapboxGL/RCTMapboxGL.m b/ios/RCTMapboxGL/RCTMapboxGL.m index b4ca8620f..cb371121d 100644 --- a/ios/RCTMapboxGL/RCTMapboxGL.m +++ b/ios/RCTMapboxGL/RCTMapboxGL.m @@ -242,6 +242,11 @@ -(void)setCenterCoordinateZoomLevelAnimated:(CLLocationCoordinate2D)coordinates [_map setCenterCoordinate:coordinates zoomLevel:zoomLevel animated:YES]; } +- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)padding animated:(BOOL)animated +{ + [_map setVisibleCoordinateBounds:bounds edgePadding:padding animated:animated]; +} + - (void)mapView:(MGLMapView *)mapView didUpdateUserLocation:(MGLUserLocation *)userLocation; { NSDictionary *event = @{ @"target": self.reactTag, diff --git a/ios/RCTMapboxGL/RCTMapboxGLManager.m b/ios/RCTMapboxGL/RCTMapboxGLManager.m index eed4f10d0..d6c08c81b 100644 --- a/ios/RCTMapboxGL/RCTMapboxGLManager.m +++ b/ios/RCTMapboxGL/RCTMapboxGLManager.m @@ -100,6 +100,22 @@ - (NSArray *)customDirectEventTypes }]; } +RCT_EXPORT_METHOD(setVisibleCoordinateBoundsAnimated:(nonnull NSNumber *)reactTag + latitudeSW:(float) latitudeSW + longitudeSW:(float) longitudeSW + latitudeNE:(float) latitudeNE + longitudeNE:(float) longitudeNE + edgePadding:(double) edgePadding) +{ + [_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + RCTMapboxGL *mapView = viewRegistry[reactTag]; + if ([mapView isKindOfClass:[RCTMapboxGL class]]) { + MGLCoordinateBounds coordinatesBounds = MGLCoordinateBoundsMake(CLLocationCoordinate2DMake(latitudeSW, longitudeSW), CLLocationCoordinate2DMake(latitudeNE, longitudeNE)); + [mapView setVisibleCoordinateBounds:coordinatesBounds edgePadding:UIEdgeInsetsMake(edgePadding, edgePadding, edgePadding, edgePadding) animated:YES]; + } + }]; +} + RCT_EXPORT_METHOD(selectAnnotationAnimated:(nonnull NSNumber *) reactTag annotationInArray:(NSUInteger)annotationInArray) {