diff --git a/GoogleMap.jsx b/GoogleMap.jsx
index ed56ae2..64f24a2 100644
--- a/GoogleMap.jsx
+++ b/GoogleMap.jsx
@@ -37,27 +37,28 @@ class GoogleMap extends Component {
onChange = (e) => {
e.preventDefault()
- if (e.target.name === 'title'){
- title = e.target.value}
- else if (e.target.name === 'tags'){
+ if (e.target.name === 'title') {
+ title = e.target.value
+ }
+ else if (e.target.name === 'tags') {
tags = e.target.value
- }
+ }
}
onCreateClick(e) {
e.preventDefault()
- this.setState({openNewForm: !this.state.openNewForm})
+ this.setState({ openNewForm: !this.state.openNewForm })
}
mapInput(event) {
event.preventDefault();
- }
+ }
createNewMap() {
let center = {
lat: this.map.getCenter().lat(),
lng: this.map.getCenter().lng()
- };
+ };
db.collection('maps').add({
center: this.state.center,
@@ -81,10 +82,10 @@ class GoogleMap extends Component {
geocode({ address: input.value }, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
const center = {
- lat: results[0].geometry.location.lat(),
- lng: results[0].geometry.location.lng()
+ lat: results[0].geometry.location.lat(),
+ lng: results[0].geometry.location.lng()
}
- holder.setState({center});
+ holder.setState({ center });
holder.map.setCenter(center);
holder.map.setZoom(15);
} else {
@@ -107,14 +108,14 @@ class GoogleMap extends Component {
}
loadMap() {
- if (this.props && this.props.google) {
+ if (this.props && this.props.google) {
const { google } = this.props;
const maps = google.maps;
const mapRef = this.refs.map;
const node = ReactDOM.findDOMNode(mapRef);
let defaultCenter;
let zoom;
-
+
if (this.state.center.lat) {
defaultCenter = this.state.center;
zoom = 15;
@@ -138,7 +139,7 @@ class GoogleMap extends Component {
const input = document.getElementById('center-point'); // use a ref instead
const options = {
bounds: defaultBounds,
- // types: ['establishment']
+ // types: ['establishment']
};
const autocomplete = new google.maps.places.Autocomplete(input, options);
}
@@ -148,15 +149,15 @@ class GoogleMap extends Component {
const { classes } = this.props;
const { openNewForm, centerMap } = this.state;
- const style = {
+ const style = {
width: '100vw',
height: '100vh'
};
return (
-
- { (!openNewForm) &&
+
+ { (!openNewForm) &&
@@ -165,14 +166,14 @@ class GoogleMap extends Component {
}
}
-
+
{ (openNewForm) &&
+
}
diff --git a/NewMap.jsx b/NewMap.jsx
index 2459330..20b1f5a 100644
--- a/NewMap.jsx
+++ b/NewMap.jsx
@@ -2,17 +2,16 @@ import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import firebase from '~/fire';
import { withRouter } from "react-router-dom";
-import ResultList from './ResultList'
-import GoogleMapButton from './GoogleMapButton';
+//import ResultList from './ResultList'
const db = firebase.firestore();
var searchMarkersArray = [];
var addedMarkersArr = [];
-
function clearOverlays(arr) {
for (var i = 0; i < arr.length; i++) {
arr[i].setMap(null);
+
}
arr.length = 0;
}
@@ -42,7 +41,6 @@ class NewMap extends Component {
marker.id = place.place_id
addedMarkersArr.push(marker)
marker.setMap(null)
- console.log(place);
obj[place.place_id] = {
lat: place.geometry.location.lat(),
lng: place.geometry.location.lng(),
@@ -90,8 +88,9 @@ class NewMap extends Component {
onClick = (event) => {
event.preventDefault()
+ var placeArr = []
if (searchMarkersArray.length) {
- clearOverlays()
+ clearOverlays(searchMarkersArray)
}
const { google } = this.props
@@ -101,7 +100,7 @@ class NewMap extends Component {
var request = {
location: center,
- radius: '1000',
+ bounds: this.map.getBounds(),
name: event.target.search.value
}
var infowindow = new google.maps.InfoWindow();
@@ -127,10 +126,11 @@ class NewMap extends Component {
position: place.geometry.location
});
searchMarkersArray.push(marker)
+ placeArr.push(place)
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent('
' + place.name + '' +
'Place ID: ' + place.place_id + '
' +
- place.formatted_address + '
');
+ place.formatted_address + '
{ holder.addPlace(marker, place, infowindow) })
@@ -142,7 +142,9 @@ class NewMap extends Component {
}
else { console.log('no results') }
}
- service.nearbySearch(request, callback);
+
+
+ service.nearbySearch(request, callback)
}
componentDidMount() {
@@ -170,15 +172,16 @@ class NewMap extends Component {
this.map = new maps.Map(node, mapConfig)
var isthis = this
const service1 = new this.props.google.maps.places.PlacesService(this.map);
- const defaultBounds = new google.maps.LatLngBounds(
- new google.maps.LatLng(-33.8902, 151.1759),
- new google.maps.LatLng(-33.8474, 151.2631)
- );
+ let options = {
+ bounds: this.map.getBounds(),
+ }
const input = document.getElementById('center'); // use a ref instead
- const options = {
- bounds: defaultBounds,
- };
- const autocomplete = new google.maps.places.Autocomplete(input, options);
+
+ const autocomplete = new google.maps.places.Autocomplete(input, options)
+
+ google.maps.event.addListener(this.map, 'idle', function () {
+ autocomplete.setBounds(isthis.map.getBounds())
+ });
var checkedMap = db.collection('maps').doc(this.props.match.params.id).onSnapshot(function (doc) {
var infowindow = new google.maps.InfoWindow();
@@ -190,7 +193,7 @@ class NewMap extends Component {
(() => {
var latLng = { lat: arr[keysArr[i]].lat, lng: arr[keysArr[i]].lng }
var placeName = keysArr[i]
- var placeInfo=arr[placeName];
+ var placeInfo = arr[placeName];
var marker = new google.maps.Marker({
map: isthis.map,
position: latLng,
@@ -200,7 +203,7 @@ class NewMap extends Component {
addedMarkersArr.push(marker)
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent('Work in Progress' +
- 'Place:' + placeInfo.name + 'Address' + placeInfo.address + '
');
+ 'Place:' + placeInfo.name + 'Address' + placeInfo.address + '