Created
April 14, 2016 14:15
-
-
Save SeanRoberts/2180951be99d3d9bfe7d6be54c038821 to your computer and use it in GitHub Desktop.
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
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