Created
August 22, 2015 06:13
-
-
Save MicheleBertoli/76f782b37ad779bd81cb to your computer and use it in GitHub Desktop.
Gmaps Center on Resize
This file contains hidden or 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 {Gmaps} from 'react-gmaps'; | |
const coords = { | |
lat: 51.5258541, | |
lng: -0.08040660000006028 | |
}; | |
const App = React.createClass({ | |
onMapCreated() { | |
const {Gmaps} = this.refs; | |
google.maps.event.addDomListener(window, 'resize', function() { | |
Gmaps.getMap().setCenter(coords); | |
}); | |
}, | |
render() { | |
return ( | |
<Gmaps | |
ref='Gmaps' | |
width={'100%'} | |
height={'100%'} | |
lat={coords.lat} | |
lng={coords.lng} | |
zoom={12} | |
onMapCreated={this.onMapCreated} /> | |
); | |
} | |
}); | |
React.render(<App />, document.getElementById('gmaps')); |
It seems Google Maps is polluting global namespace.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where is that
google
variable on line 13 coming from?