Last active
February 16, 2016 21:13
-
-
Save MicheleBertoli/cb00b7cadf06f8701610 to your computer and use it in GitHub Desktop.
Get Map instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import {Gmaps} from 'react-gmaps'; | |
const App = React.createClass({ | |
getInitialState() { | |
return { | |
isMapCreated: false | |
}; | |
}, | |
onMapCreated(map) { | |
this.setState({ | |
isMapCreated: true, | |
map | |
}); | |
}, | |
handleClick() { | |
console.log(this.state.map.fitBounds); | |
console.log(this.refs.gmaps.getMap().fitBounds); | |
}, | |
render() { | |
return ( | |
<div> | |
<Gmaps | |
ref="gmaps" | |
width={400} | |
height={300} | |
lat={51.5258541} | |
lng={-0.08040660000006028} | |
zoom={12} | |
onMapCreated={this.onMapCreated}/> | |
{this.state.isMapCreated && | |
<button onClick={this.handleClick}>fitBounds</button> | |
} | |
</div> | |
); | |
} | |
}); | |
ReactDOM.render(<App />, document.getElementById('gmaps')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment