@@ -2,17 +2,16 @@ import React, { Component } from 'react';
22import ReactDOM from 'react-dom' ;
33import firebase from '~/fire' ;
44import { withRouter } from "react-router-dom" ;
5- import ResultList from './ResultList'
6- import GoogleMapButton from './GoogleMapButton' ;
5+ //import ResultList from './ResultList'
76
87const db = firebase . firestore ( ) ;
98
109var searchMarkersArray = [ ] ;
1110var addedMarkersArr = [ ] ;
12-
1311function 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 }
0 commit comments