Skip to content

Commit 5e1a5ff

Browse files
committed
Add animateToRegion method support
1 parent 4aa3720 commit 5e1a5ff

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ const GoogleMapContainer = withGoogleMap(props => (
99
));
1010

1111
class MapView extends Component {
12+
state = {
13+
center: null,
14+
};
15+
1216
handleMapMounted = map => (this.map = map);
1317

18+
animateToRegion(coordinates) {
19+
this.setState({ center: { lat: coordinates.latitude, lng: coordinates.longitude } });
20+
}
21+
1422
onDragEnd = () => {
1523
const { onRegionChangeComplete } = this.props;
1624
if (this.map && onRegionChangeComplete) {
@@ -24,6 +32,7 @@ class MapView extends Component {
2432

2533
render() {
2634
const { region, initialRegion, onRegionChange, onPress, options } = this.props;
35+
const { center } = this.state;
2736
const style = this.props.style || styles.container;
2837

2938
const centerProps = region
@@ -33,6 +42,8 @@ class MapView extends Component {
3342
lng: region.longitude,
3443
},
3544
}
45+
: center
46+
? { center }
3647
: {
3748
defaultCenter: {
3849
lat: initialRegion.latitude,
@@ -48,7 +59,7 @@ class MapView extends Component {
4859
mapElement={<div style={{ height: '100%' }} />}
4960
{...centerProps}
5061
onDragStart={onRegionChange}
51-
onDragEnd={this.onDragEnd}
62+
onIdle={this.onDragEnd}
5263
defaultZoom={15}
5364
onClick={onPress}
5465
options={options}>

0 commit comments

Comments
 (0)