Skip to content

Commit cd963c3

Browse files
merge
2 parents d2592f8 + f6c8080 commit cd963c3

File tree

4 files changed

+113
-118
lines changed

4 files changed

+113
-118
lines changed

GoogleMap.jsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,28 @@ class GoogleMap extends Component {
3737

3838
onChange = (e) => {
3939
e.preventDefault()
40-
if (e.target.name === 'title'){
41-
title = e.target.value}
42-
else if (e.target.name === 'tags'){
40+
if (e.target.name === 'title') {
41+
title = e.target.value
42+
}
43+
else if (e.target.name === 'tags') {
4344
tags = e.target.value
44-
}
45+
}
4546
}
4647

4748
onCreateClick(e) {
4849
e.preventDefault()
49-
this.setState({openNewForm: !this.state.openNewForm})
50+
this.setState({ openNewForm: !this.state.openNewForm })
5051
}
5152

5253
mapInput(event) {
5354
event.preventDefault();
54-
}
55+
}
5556

5657
createNewMap() {
5758
let center = {
5859
lat: this.map.getCenter().lat(),
5960
lng: this.map.getCenter().lng()
60-
};
61+
};
6162

6263
db.collection('maps').add({
6364
center: this.state.center,
@@ -81,10 +82,10 @@ class GoogleMap extends Component {
8182
geocode({ address: input.value }, function (results, status) {
8283
if (status === google.maps.GeocoderStatus.OK) {
8384
const center = {
84-
lat: results[0].geometry.location.lat(),
85-
lng: results[0].geometry.location.lng()
85+
lat: results[0].geometry.location.lat(),
86+
lng: results[0].geometry.location.lng()
8687
}
87-
holder.setState({center});
88+
holder.setState({ center });
8889
holder.map.setCenter(center);
8990
holder.map.setZoom(15);
9091
} else {
@@ -107,14 +108,14 @@ class GoogleMap extends Component {
107108
}
108109

109110
loadMap() {
110-
if (this.props && this.props.google) {
111+
if (this.props && this.props.google) {
111112
const { google } = this.props;
112113
const maps = google.maps;
113114
const mapRef = this.refs.map;
114115
const node = ReactDOM.findDOMNode(mapRef);
115116
let defaultCenter;
116117
let zoom;
117-
118+
118119
if (this.state.center.lat) {
119120
defaultCenter = this.state.center;
120121
zoom = 15;
@@ -138,7 +139,7 @@ class GoogleMap extends Component {
138139
const input = document.getElementById('center-point'); // use a ref instead
139140
const options = {
140141
bounds: defaultBounds,
141-
// types: ['establishment']
142+
// types: ['establishment']
142143
};
143144
const autocomplete = new google.maps.places.Autocomplete(input, options);
144145
}
@@ -148,15 +149,15 @@ class GoogleMap extends Component {
148149
const { classes } = this.props;
149150
const { openNewForm, centerMap } = this.state;
150151

151-
const style = {
152+
const style = {
152153
width: '100vw',
153154
height: '100vh'
154155
};
155156

156157
return (
157158
<div>
158-
159-
{ (!openNewForm) &&
159+
160+
{ (!openNewForm) &&
160161
<div className="google-map-buttons text-align-center">
161162
<input id='center-point' className='controls google-map-input' type='text' placeholder='Search Locations' />
162163
<Button variant="raised" color="primary" className={classes.button} onClick={this.onSearchClick}>Center Map</Button>
@@ -165,14 +166,14 @@ class GoogleMap extends Component {
165166
}
166167
</div>
167168
}
168-
169+
169170
{ (openNewForm) &&
170171
<div className="google-map-buttons-2 text-align-center">
171172
<form onSubmit={this.onSubmitMapInfo} onChange = {this.onChange}>
172173
<input name="title" className="google-map-input google-input-margin" placeholder="New Map Name" required />
173174
<input name="tags" className="google-map-input google-input-margin" placeholder="Enter Hashtags" required />
174175
<Button variant="raised" color="primary" className={classes.button} type="submit" >Submit</Button>
175-
</form>
176+
</form>
176177
<Button variant="raised" color="primary" className={classes.button} type="text" onClick={this.onCreateClick}>Back</Button>
177178
</div>
178179
}

NewMap.jsx

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import React, { Component } from 'react';
22
import ReactDOM from 'react-dom';
33
import firebase from '~/fire';
44
import { withRouter } from "react-router-dom";
5-
import ResultList from './ResultList'
6-
import GoogleMapButton from './GoogleMapButton';
5+
//import ResultList from './ResultList'
76

87
const db = firebase.firestore();
98

109
var searchMarkersArray = [];
1110
var addedMarkersArr = [];
12-
1311
function clearOverlays(arr) {
1412
for (var i = 0; i < arr.length; i++) {
1513
arr[i].setMap(null);
14+
1615
}
1716
arr.length = 0;
1817
}
@@ -42,7 +41,6 @@ class NewMap extends Component {
4241
marker.id = place.place_id
4342
addedMarkersArr.push(marker)
4443
marker.setMap(null)
45-
console.log(place);
4644
obj[place.place_id] = {
4745
lat: place.geometry.location.lat(),
4846
lng: place.geometry.location.lng(),
@@ -90,8 +88,9 @@ class NewMap extends Component {
9088

9189
onClick = (event) => {
9290
event.preventDefault()
91+
var placeArr = []
9392
if (searchMarkersArray.length) {
94-
clearOverlays()
93+
clearOverlays(searchMarkersArray)
9594
}
9695

9796
const { google } = this.props
@@ -101,7 +100,7 @@ class NewMap extends Component {
101100

102101
var request = {
103102
location: center,
104-
radius: '1000',
103+
bounds: this.map.getBounds(),
105104
name: event.target.search.value
106105
}
107106
var infowindow = new google.maps.InfoWindow();
@@ -127,10 +126,11 @@ class NewMap extends Component {
127126
position: place.geometry.location
128127
});
129128
searchMarkersArray.push(marker)
129+
placeArr.push(place)
130130
google.maps.event.addListener(marker, 'click', function () {
131131
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' +
132132
'Place ID: ' + place.place_id + '<br>' +
133-
place.formatted_address + '<div class="text-align-center"><button id="addPlaceButton">Add Place</button></div></div> ');
133+
place.formatted_address + '<button id="addPlaceButton">Add Place</button></div ');
134134
infowindow.open(holder.map, this);
135135
const getButton = document.getElementById('addPlaceButton');
136136
getButton.addEventListener('click', () => { holder.addPlace(marker, place, infowindow) })
@@ -142,7 +142,9 @@ class NewMap extends Component {
142142
}
143143
else { console.log('no results') }
144144
}
145-
service.nearbySearch(request, callback);
145+
146+
147+
service.nearbySearch(request, callback)
146148
}
147149

148150
componentDidMount() {
@@ -170,15 +172,16 @@ class NewMap extends Component {
170172
this.map = new maps.Map(node, mapConfig)
171173
var isthis = this
172174
const service1 = new this.props.google.maps.places.PlacesService(this.map);
173-
const defaultBounds = new google.maps.LatLngBounds(
174-
new google.maps.LatLng(-33.8902, 151.1759),
175-
new google.maps.LatLng(-33.8474, 151.2631)
176-
);
175+
let options = {
176+
bounds: this.map.getBounds(),
177+
}
177178
const input = document.getElementById('center'); // use a ref instead
178-
const options = {
179-
bounds: defaultBounds,
180-
};
181-
const autocomplete = new google.maps.places.Autocomplete(input, options);
179+
180+
const autocomplete = new google.maps.places.Autocomplete(input, options)
181+
182+
google.maps.event.addListener(this.map, 'idle', function () {
183+
autocomplete.setBounds(isthis.map.getBounds())
184+
});
182185
var checkedMap = db.collection('maps').doc(this.props.match.params.id).onSnapshot(function (doc) {
183186
var infowindow = new google.maps.InfoWindow();
184187

@@ -190,7 +193,7 @@ class NewMap extends Component {
190193
(() => {
191194
var latLng = { lat: arr[keysArr[i]].lat, lng: arr[keysArr[i]].lng }
192195
var placeName = keysArr[i]
193-
var placeInfo=arr[placeName];
196+
var placeInfo = arr[placeName];
194197
var marker = new google.maps.Marker({
195198
map: isthis.map,
196199
position: latLng,
@@ -200,7 +203,7 @@ class NewMap extends Component {
200203
addedMarkersArr.push(marker)
201204
google.maps.event.addListener(marker, 'click', function () {
202205
infowindow.setContent('<div><strong>Work in Progress</strong><br>' +
203-
'Place:' + placeInfo.name + 'Address' + placeInfo.address + '<br><div class="text-align-center"><button id="removePlaceButton">Remove Place</div></div> ');
206+
'Place:' + placeInfo.name + 'Address' + placeInfo.address + '<br><button id="removePlaceButton">Remove Place</div ');
204207
infowindow.open(isthis.map, this);
205208
const getButton = document.getElementById('removePlaceButton');
206209
getButton.addEventListener('click', () => { isthis.removePlace(marker) })
@@ -213,30 +216,19 @@ class NewMap extends Component {
213216

214217
render() {
215218
const style = {
216-
width: '100vw',
217-
height: '100vh'
219+
width: '90vw',
220+
height: '75vh'
218221
};
219-
220222
return (
221223
<div>
222-
<div className="google-map-buttons text-align-center">
223-
<form onSubmit={this.onClick}>
224-
<input ref="center" id="center" className="google-map-input google-input-margin" type="text" placeholder="Search For A Place" name="search" />
225-
{
226-
227-
}
228-
<GoogleMapButton type={`submit`} text={`Add to map`} />
229-
{
230-
231-
<GoogleMapButton onClick={this.clearSearch} text={`Clear Search`} />
232-
}
233-
</form>
234-
235-
</div>
236-
<div ref="newmap" className="google-map">
224+
<div ref="newmap" style={style}>
237225
Loading map...
238226
</div>
239-
227+
<form onSubmit={this.onClick}>
228+
<input ref='center' id='center' className='controls' type='text' placeholder='search for place' name='search' />
229+
<button type='submit' />
230+
</form>
231+
<button onClick={this.clearSearch}>Clear Search </button>
240232
</div>
241233
)
242234
}

ResultList.jsx

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,29 @@ export default class ResultList extends Component {
99
constructor(props){
1010
super(props)
1111
this.state = {results: []}
12-
this.onClick = this.onClick.bind(this)
1312
}
14-
onClick(event){
15-
event.preventDefault()
16-
var placeId = event.target.placeid.value
17-
var id = this.props.id
18-
var obj = {}
19-
obj[placeId] = true
20-
var mapRef = db.collection('maps').doc(id);
21-
var getDoc = mapRef.set({
22-
places: obj
23-
}, { merge: true })
24-
.then(doc => {
25-
if (!doc.exists) {
26-
console.log('No such document!');
27-
} else {
28-
console.log('Document data:', doc.data());
29-
}
30-
})
31-
.catch(err => {
32-
console.log('Error getting document', err);
33-
});
13+
componentWillReceiveProps(){
14+
console.log(this.props.arr.arr, this.props.arr.length)
15+
this.setState({results:this.props.arr})
16+
3417

3518
}
19+
3620
componentDidMount(){
3721
console.log(this.props)
38-
this.setState({results:this.props.results})
39-
console.log(this.state)
22+
//this.setState({results:this.props.arr})
4023
}
4124

4225
render(){
43-
var key = 0
44-
console.log(this.state.results)
26+
//console.log(this.props.arr[0])
27+
console.log(this.state)
28+
4529
return(
46-
<ul>{this.state.results && this.state.results.map(result =>{
47-
return <form key={key++} onSubmit = {this.onClick}><option type = 'submit'>{result.name}</option><button name='placeid' type='submit' value={result.place_id}>add to map</button></form>
48-
})}</ul> )
30+
this.state.results.length ? this.state.results.map((place)=>{
31+
return <div>{place.name}</div>
32+
})
33+
: <div>no results </div>
34+
)
4935
}
5036

5137
}

0 commit comments

Comments
 (0)