Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Last active September 17, 2016 21:37
Show Gist options
  • Save MicheleBertoli/321d28c7103359e53592c9deec19dfe4 to your computer and use it in GitHub Desktop.
Save MicheleBertoli/321d28c7103359e53592c9deec19dfe4 to your computer and use it in GitHub Desktop.
Gmaps set center
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