Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Created August 12, 2016 10:47
Show Gist options
  • Save MicheleBertoli/70eef44bcd607bef94a7b8197f86b68e to your computer and use it in GitHub Desktop.
Save MicheleBertoli/70eef44bcd607bef94a7b8197f86b68e to your computer and use it in GitHub Desktop.
Gmaps setIcon
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