Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Created August 22, 2015 06:13
Show Gist options
  • Save MicheleBertoli/76f782b37ad779bd81cb to your computer and use it in GitHub Desktop.
Save MicheleBertoli/76f782b37ad779bd81cb to your computer and use it in GitHub Desktop.
Gmaps Center on Resize
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'));
@yantakus
Copy link

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