Last active
September 17, 2016 21:37
-
-
Save MicheleBertoli/321d28c7103359e53592c9deec19dfe4 to your computer and use it in GitHub Desktop.
Gmaps set center
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, InfoWindow} from 'react-gmaps'; | |
const points = [{ | |
lat: 51.5258541, | |
lng: -0.09040660000006028 | |
}, { | |
lat: 51.5258541, | |
lng: -0.08040660000006028 | |
}, { | |
lat: 51.5258541, | |
lng: -0.07040660000006028 | |
}]; | |
const App = React.createClass({ | |
getInitialState() { | |
return { | |
index: 1 | |
}; | |
}, | |
selecMarker(index) { | |
this.setState({ index }); | |
}, | |
renderMarkers() { | |
return points.map((coords, index) => | |
<Marker | |
key={index} | |
lat={coords.lat} | |
lng={coords.lng} | |
onClick={() => this.selecMarker(index)} | |
/> | |
); | |
}, | |
render() { | |
const { index } = this.state; | |
return ( | |
<Gmaps | |
ref="gmaps" | |
width={400} | |
height={300} | |
lat={points[index].lat} | |
lng={points[index].lng} | |
zoom={12} | |
> | |
{this.renderMarkers()} | |
</Gmaps> | |
); | |
} | |
}); | |
ReactDOM.render(<App />, document.getElementById('gmaps')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment