Skip to content

Commit

Permalink
Merge pull request #114 from pecheriere/add-setVisibleCoordinateBounds
Browse files Browse the repository at this point in the history
add setVisibleCoordinateBounds to js module.
  • Loading branch information
Bobby Sudekum committed Oct 26, 2015
2 parents 3c12340 + c7f0ed6 commit 6b6e007
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
1 change: 1 addition & 0 deletions ios/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions ios/RCTMapboxGL/RCTMapboxGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions ios/RCTMapboxGL/RCTMapboxGL.m
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions ios/RCTMapboxGL/RCTMapboxGLManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 6b6e007

Please sign in to comment.