Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Created July 12, 2014 16:10
Show Gist options
  • Save Sigmus/6ea7836c66726575d6a6 to your computer and use it in GitHub Desktop.
Save Sigmus/6ea7836c66726575d6a6 to your computer and use it in GitHub Desktop.
A React Google Maps Component
var GmapComponent = require('./google-maps-component');
var component = GmapComponent({
lat: -23.5348644, lng: -46.6718231
});
var node = document.getElementById('main');
React.renderComponent(component, node);
/*
* A React Google Maps Component.
* This is a Browserify Module.
* http://twitter.com/flavioatas
*
* "window.google.maps" must be loaded beforehand.
*/
var React = require('react');
module.exports = React.createClass({
getDefaultProps: function() {
return {
tagName: 'div',
className: 'map',
zoom: 12
}
},
render: function() {
return React.DOM[this.props.tagName]({
className: this.props.className
});
},
componentDidMount: function() {
var node = this.getDOMNode();
var options = {
center: this.getLatLng(),
zoom: this.props.zoom
};
var map = new window.google.maps.Map(node, options);
this.setState({map: map});
},
componentDidUpdate: function() {
this.state.map.panTo(this.getLatLng());
},
getLatLng: function() {
return new google.maps.LatLng(
this.props.lat,
this.props.lng
);
}
});
@Sigmus
Copy link
Author

Sigmus commented Jul 15, 2014

Ola.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment