Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Last active February 16, 2016 21:13
Show Gist options
  • Save MicheleBertoli/cb00b7cadf06f8701610 to your computer and use it in GitHub Desktop.
Save MicheleBertoli/cb00b7cadf06f8701610 to your computer and use it in GitHub Desktop.
Get Map instance
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