From d0d9820699b7a7c6e5153aa4ffeaea45e2720df8 Mon Sep 17 00:00:00 2001 From: Al Duncanson Date: Tue, 2 Oct 2018 14:51:26 -0400 Subject: [PATCH] map renders markers on click, sends lat and lng to firebase, yeet --- package-lock.json | 13 +- src/App.css | 1 + src/components/ReportForm.js | 252 ++++++++++++++++++++--------------- src/pages/Map.js | 48 +++---- src/pages/Report.js | 3 - 5 files changed, 171 insertions(+), 146 deletions(-) diff --git a/package-lock.json b/package-lock.json index fd17bd1..87e56ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4294,7 +4294,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -4659,7 +4660,8 @@ }, "safe-buffer": { "version": "5.1.1", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -4707,6 +4709,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4745,11 +4748,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.0.2", - "bundled": true + "bundled": true, + "optional": true } } }, diff --git a/src/App.css b/src/App.css index 2d57aaa..2134e4d 100644 --- a/src/App.css +++ b/src/App.css @@ -4,4 +4,5 @@ body { .google-map-container > div { height: 92% !important; + width: 50% !important; } \ No newline at end of file diff --git a/src/components/ReportForm.js b/src/components/ReportForm.js index 4dd046e..15e607f 100644 --- a/src/components/ReportForm.js +++ b/src/components/ReportForm.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {Fragment} from 'react'; import PropTypes from 'prop-types'; import Grid from '@material-ui/core/Grid'; import { withStyles } from '@material-ui/core/styles'; @@ -6,6 +6,7 @@ import MenuItem from '@material-ui/core/MenuItem'; import TextField from '@material-ui/core/TextField'; import Button from '@material-ui/core/Button'; import firebase from '../firebase.js'; +import MapContainer from '../pages/Map'; /** * Styles that the different @@ -138,7 +139,9 @@ class ReportForm extends React.Component { time: '00:00', type: 'visual', confidence: '1', - desc: '' + desc: '', + lat: '', + lng: '' }; /** @@ -151,6 +154,20 @@ class ReportForm extends React.Component { }); }; + /* + * Get the coordinates + * + */ + getCoordinates = (lat,lng) => { + let latitude = lat; + let longitude = lng; + + this.setState({ + lat: latitude, + lng: longitude + }); + } + /** * Event listener for form. * When the form is submitted, @@ -165,7 +182,9 @@ class ReportForm extends React.Component { confidence: this.state.confidence, date: this.state.date, time: this.state.time, - desc: this.state.desc + desc: this.state.desc, + lat: this.state.lat, + lng: this.state.lng } sightingsRef.push(sighting); this.setState({ @@ -173,7 +192,9 @@ class ReportForm extends React.Component { time: '00:00', type: 'visual', confidence: '1', - desc: '' + desc: '', + lat: '', + lng: '' }); }; @@ -188,118 +209,127 @@ class ReportForm extends React.Component { * The actual form. */ return ( -
- - - - {sightingTypes.map(option => ( - - {option.label} - - ))} - - + + + + + + + + {sightingTypes.map(option => ( + + {option.label} + + ))} + + - - - {confidenceLevels.map(option => ( - - {option.label} - - ))} - - + + + {confidenceLevels.map(option => ( + + {option.label} + + ))} + + - - - + + + - - - + + + - - + + + + + + + + + + + + - - - - - - + + ); } } diff --git a/src/pages/Map.js b/src/pages/Map.js index 58fbd06..806b961 100644 --- a/src/pages/Map.js +++ b/src/pages/Map.js @@ -63,12 +63,17 @@ export class MapContainer extends Component { }); } + this.setState({ + markerLatLng: { + lat: e.latLng.lat(), + lng: e.latLng.lng() + } + }) + let lat = e.latLng.lat(); - let lng = e.latLng.lng(); - console.log(` - latitude: ${lat} - longitude: ${lng} - `); + let lng = e.latLng.lng(); + + this.props.onClick(lat,lng); } // Set the state of the component to contain user coordinates and initial @@ -78,6 +83,10 @@ export class MapContainer extends Component { lat: 42.9634, lng: 85.6681 }, + markerLatLng: { + lat: 0, + lng: 0 + }, showingInfoWindow: false, activeMarker: {}, selectedPlace: {} @@ -99,11 +108,15 @@ export class MapContainer extends Component { defaultZoom = { 15 } onClick = { this.onMapClick } > + + - - - - - - diff --git a/src/pages/Report.js b/src/pages/Report.js index 8a7909d..c9042d9 100644 --- a/src/pages/Report.js +++ b/src/pages/Report.js @@ -1,13 +1,10 @@ import React, { Component } from 'react'; import ReportForm from '../components/ReportForm'; -import Typography from '@material-ui/core/Typography'; class Report extends Component { render() { return ( - - ); } }