Skip to content

Instantly share code, notes, and snippets.

@SeanRoberts
Created April 14, 2016 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanRoberts/2180951be99d3d9bfe7d6be54c038821 to your computer and use it in GitHub Desktop.
Save SeanRoberts/2180951be99d3d9bfe7d6be54c038821 to your computer and use it in GitHub Desktop.
class Marker extends React.Component {
componentDidMount() {
const { lat, lng } = this.props.spot;
this.gMarker = new RichMarker({
position: new google.maps.LatLng(lat, lng),
map: this.props.gMap,
draggable: true,
content: ReactDOM.findDOMNode(this)
});
this.gMarker.addListener('click', () => {
this.props.onClick(this.props.spot);
});
}
componentDidUpdate() {
this.gMarker.setContent(ReactDOM.findDOMNode(this));
}
componentWillReceiveProps(nextProps) {
if (nextProps.gMap !== this.props.gMap) {
this.gMarker.setMap(nextProps.gMap);
}
}
componentWillUnmount() {
this.gMarker.setMap(null);
}
render() {
const className = classNames({
'map-marker': true,
'map-marker--spot': !this.props.isSelected,
'map-marker--spot-selected': this.props.isSelected
});
return (
<div className={className} />
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment