Skip to content

Commit ccd4879

Browse files
radenorborn
authored andcommitted
Calculate bounding box from region (react-native-maps#2615)
* Add helper method for getting bounding box from region * Awaiting promise in async method, add typescript definition * Fix eslint
1 parent c68fadb commit ccd4879

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ declare module "react-native-maps" {
237237
fitToSuppliedMarkers(markers: string[], options?: { edgePadding?: EdgePadding, animated?: boolean }): void;
238238
fitToCoordinates(coordinates?: LatLng[], options?: { edgePadding?: EdgePadding, animated?: boolean }): void;
239239
setMapBoundaries(northEast: LatLng, southWest: LatLng): void;
240+
getMapBoundaries(): {northEast: LatLng; southWest: LatLng};
240241
takeSnapshot(options?: SnapshotOptions): Promise<string>;
241242
}
242243

lib/components/MapView.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,9 @@ class MapView extends React.Component {
665665
*/
666666
async getMapBoundaries() {
667667
if (Platform.OS === 'android') {
668-
return NativeModules.AirMapModule.getMapBoundaries(this._getHandle());
668+
return await NativeModules.AirMapModule.getMapBoundaries(this._getHandle());
669669
} else if (Platform.OS === 'ios') {
670-
return this._runCommand('getMapBoundaries', []);
670+
return await this._runCommand('getMapBoundaries', []);
671671
}
672672
return Promise.reject('getMapBoundaries not supported on this platform');
673673
}
@@ -791,6 +791,26 @@ class MapView extends React.Component {
791791
return Promise.reject('coordinateForPoint not supported on this platform');
792792
}
793793

794+
/**
795+
* Get bounding box from region
796+
*
797+
* @param region Region
798+
*
799+
* @return Object Object bounding box ({ northEast: <LatLng>, southWest: <LatLng> })
800+
*/
801+
boundingBoxForRegion(region) {
802+
return {
803+
northEast: {
804+
latitude: region.latitude + (region.latitudeDelta / 2),
805+
longitude: region.longitude + (region.longitudeDelta / 2),
806+
},
807+
southWest: {
808+
latitude: region.latitude - (region.latitudeDelta / 2),
809+
longitude: region.longitude - (region.longitudeDelta / 2),
810+
},
811+
};
812+
}
813+
794814
_uiManagerCommand(name) {
795815
return NativeModules.UIManager[getAirMapName(this.props.provider)].Commands[name];
796816
}

lib/ios/AirMaps/AIRMapManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ - (void)mapView:(AIRMap *)mapView regionDidChangeAnimated:(__unused BOOL)animate
939939
- (void)mapViewWillStartRenderingMap:(AIRMap *)mapView
940940
{
941941
if (!mapView.hasStartedRendering) {
942-
mapView.onMapReady(@{});
942+
mapView.onMapReady(@{});
943943
mapView.hasStartedRendering = YES;
944944
}
945945
[mapView beginLoading];

0 commit comments

Comments
 (0)