Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 78 additions & 13 deletions src/components/MapContainer.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,85 @@
import React from 'react';
import { Map, GoogleApiWrapper, Marker } from 'google-maps-react';

const MapContainer = ({ google }) => {
return (
<Map
google={google}
zoom={5}
initialCenter={{ lat: 19.5943885, lng: -97.9526044 }}
>
<Marker
position={{ lat: 19.4267261, lng: -99.1718706 }}
/>
</Map>
);
import '../styles/components/MapContainer.styl';


class MapContainer extends React.Component {
constructor(props) {
super(props);
this.google = props.google;
this.state = {
data: [],
show: false,
};
}

componentDidMount() {
this.getData();
}

getData = () => {
fetch('http://localhost:3000/db')
.then(response => response.json())
.then(data => this.setState({ data: data }));
};

componentWillUnmount() {
clearImmediate(this.setStateShow);
clearImmediate(this.map);
}

handleClick = e => {
this.flipFlop();
};

flipFlop = () => {
const maps = document.getElementById('map');
if (!this.state.show) {
maps.classList.add('hire');
this.state.show = true;
} else {
maps.classList.remove('hire');
this.state.show = false;
}
};

render() {
console.log(this.state.data.db);

return (
<React.Fragment>
<div>
<button onClick={() => this.handleClick()} className="button">
Ocultar
</button>
</div>
<div id="map">
<Map
style={{ height: '95%' }}
google={this.google}
zoom={5}
initialCenter={{ lat: 19.5943885, lng: -97.9526044 }}
>
{data.locations.map((location, id) => {
return (
<Marker
key={id}
position={{ lat: location.venueLat, lng: location.venueLon }}
>
<InfoWindow>
<h1>{location.venueName}</h1>
</InfoWindow>
</Marker>
);
})}
</Map>
</div>
</React.Fragment>
);
}
}

export default GoogleApiWrapper({
apiKey: 'AIzaSyCmjvkXB_DMnBUNwxQztLMStyQmA_szbNw'
apiKey: 'AIzaSyCmjvkXB_DMnBUNwxQztLMStyQmA_szbNw',
})(MapContainer);
5 changes: 4 additions & 1 deletion src/styles/containers/App.styl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ body

section
margin 0
paddin 0
paddin 0

.hire
display none