Created
August 12, 2016 10:47
-
-
Save MicheleBertoli/70eef44bcd607bef94a7b8197f86b68e to your computer and use it in GitHub Desktop.
Gmaps setIcon
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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { Gmaps, Marker } from 'react-gmaps'; | |
const coords = { | |
lat: 51.5258541, | |
lng: -0.08040660000006028 | |
}; | |
const beach = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'; | |
const kitten = 'https://placekitten.com/100/100'; | |
const App = React.createClass({ | |
handleClick() { | |
this.refs.Gmaps.refs.Marker.getEntity().setIcon(kitten); | |
}, | |
render() { | |
return ( | |
<div> | |
<Gmaps | |
height={300} | |
lat={coords.lat} | |
lng={coords.lng} | |
ref="Gmaps" | |
width={400} | |
zoom={12} | |
> | |
<Marker | |
ref="Marker" | |
lat={coords.lat} | |
lng={coords.lng} | |
icon={beach} | |
/> | |
</Gmaps> | |
<button onClick={this.handleClick}>Kitten</button> | |
</div> | |
); | |
} | |
}); | |
ReactDOM.render(<App />, document.getElementById('gmaps')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment