Skip to content

Commit 66a0798

Browse files
committed
set zoom from atitudeDelta
1 parent b61672f commit 66a0798

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

docs/stories/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ storiesOf('MapView', module)
2727
.add('options', () => (
2828
<View style={styles.container}>
2929
<MapView
30-
initialRegion={{ latitude: 48.86, longitude: 2.34 }}
30+
initialRegion={{
31+
latitude: 48.86,
32+
longitude: 2.34,
33+
latitudeDelta: 0.1,
34+
longitudeDelta: 0.1,
35+
}}
3136
options={{
3237
zoomControlOptions: {
3338
position: window.google.maps.ControlPosition.RIGHT_CENTER,

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ class MapView extends Component {
5454
lng: initialRegion.longitude,
5555
},
5656
};
57-
57+
const zoom =
58+
region && region.latitudeDelta
59+
? Math.round(Math.log(360 / region.latitudeDelta) / Math.LN2)
60+
: initialRegion && initialRegion.latitudeDelta
61+
? Math.round(Math.log(360 / initialRegion.latitudeDelta) / Math.LN2)
62+
: 15;
5863
return (
5964
<View style={style}>
6065
<GoogleMapContainer
@@ -64,7 +69,7 @@ class MapView extends Component {
6469
{...centerProps}
6570
onDragStart={onRegionChange}
6671
onIdle={this.onDragEnd}
67-
defaultZoom={15}
72+
defaultZoom={zoom}
6873
onClick={onPress}
6974
options={options}>
7075
{this.props.children}

0 commit comments

Comments
 (0)