added images, added styles, record lat/lng onClick()

This commit is contained in:
Al Duncanson 2018-09-27 18:00:35 -04:00
parent a19b738c26
commit f8b998cf52
4 changed files with 47 additions and 21 deletions

View File

@ -1,3 +1,7 @@
body { body {
margin: 0; margin: 0;
} }
header + div > div {
height: 92% !important;
}

BIN
src/images/marten-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
src/images/tire-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React, { Component, Fragment } from 'react';
import { Map, InfoWindow, Marker, GoogleApiWrapper } from 'google-maps-react'; import { Map, InfoWindow, Marker, GoogleApiWrapper } from 'google-maps-react';
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
@ -55,13 +55,20 @@ export class MapContainer extends Component {
// When the user clicks on the map, if a info window is visible then close it // When the user clicks on the map, if a info window is visible then close it
// and 'unactive' that marker // and 'unactive' that marker
onMapClick = () => { onMapClick = (props, map, e) => {
if (this.state.showingInfoWindow) { if (this.state.showingInfoWindow) {
this.setState({ this.setState({
showingInfoWindow: false, showingInfoWindow: false,
activeMarker: null activeMarker: null
}); });
} }
let lat = e.latLng.lat();
let lng = e.latLng.lng();
console.log(`
latitude: ${lat}
longitude: ${lng}
`);
} }
// Set the state of the component to contain user coordinates and initial // Set the state of the component to contain user coordinates and initial
@ -77,6 +84,10 @@ export class MapContainer extends Component {
} }
render() { render() {
// TODO: This line is used by the custom marker icon
//const { google } = this.props;
return ( return (
// Render the Google Map, Marker, and InfoWindow components // Render the Google Map, Marker, and InfoWindow components
<Map <Map
@ -90,25 +101,36 @@ export class MapContainer extends Component {
<Marker <Marker
position = { this.state.myLatLng } position = { this.state.myLatLng }
onClick = { this.onMarkerClick } onClick = { this.onMarkerClick }
title = { 'Title 1!' } title = { 'Sighting Type: Roadkill' }
name = { 'Name 1!' } name = { 'blah blah blah' }
// FIXME: fix custom icon
// icon={{
// url: "../images/marten-icon.png",
// anchor: new google.maps.Point(32,32),
// scaledSize: new google.maps.Size(64,64)
// }}
/> />
<Marker <Marker
position = {{ lat: 46.5089994, lng: -122.8543421 }} position = {{ lat: 46.5089994, lng: -122.8543421 }}
onClick = { this.onMarkerClick } onClick = { this.onMarkerClick }
title = { 'Title 2!' } title = { 'Sighting Type: Alive' }
name = { 'Name 2!' } name = { 'blah' }
/> />
<InfoWindow <InfoWindow
marker = { this.state.activeMarker } marker = { this.state.activeMarker }
visible = { this.state.showingInfoWindow } > visible = { this.state.showingInfoWindow } >
<Fragment>
<Typography variant = "display1" gutterBottom> <Typography variant = "display1" gutterBottom>
{ this.state.selectedPlace.title } { this.state.selectedPlace.title }
</Typography> </Typography>
<Typography variant = "subheading" gutterBottom> <Typography variant = "subheading" gutterBottom>
{ this.state.selectedPlace.name } { this.state.selectedPlace.name }
</Typography> </Typography>
</Fragment>
</InfoWindow> </InfoWindow>
</Map> </Map>
); );