Created
July 12, 2014 16:10
-
-
Save Sigmus/6ea7836c66726575d6a6 to your computer and use it in GitHub Desktop.
A React Google Maps Component
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
var GmapComponent = require('./google-maps-component'); | |
var component = GmapComponent({ | |
lat: -23.5348644, lng: -46.6718231 | |
}); | |
var node = document.getElementById('main'); | |
React.renderComponent(component, node); |
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
/* | |
* 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 | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ola.