-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' of github.com:motosharpley/googleMaps-offl…
…ine-navigator into preact-skeleton
- Loading branch information
Showing
34 changed files
with
725 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { h, Component } from 'preact'; | ||
import leafletStyle from '../../../node_modules/leaflet/dist/leaflet.css'; | ||
import L from '../../js/leaflet-tileLayer-pouchdb-cached'; | ||
|
||
// // TODO - remove this module from dependencies | ||
// import Map, { GoogleApiWrapper, Marker, InfoWindow } from 'google-maps-react'; | ||
|
||
/** | ||
* TIle layer configuration and attribution constants | ||
*/ | ||
const OSM_URL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; | ||
const OSM_ATTRIB = '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'; | ||
const TILE_LAYER = new L.TileLayer(OSM_URL, { | ||
attribution: OSM_ATTRIB, | ||
useCache: true, | ||
crossOrigin: true, | ||
}); | ||
|
||
// redirect marker icon path to assets directory | ||
L.Icon.Default.imagePath = '../../assets/icons/leaflet/'; | ||
|
||
export default class MapContainer extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
map: null, | ||
lat: null, | ||
lng: null, | ||
watchID: null, | ||
} | ||
this.initMap = this.initMap.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
// continuously track users position | ||
const watchID = navigator.geolocation.watchPosition(this.initMap); | ||
this.setState({ | ||
watchID: watchID, | ||
}); | ||
} | ||
|
||
initMap(position) { | ||
const map = new L.Map('map'); | ||
|
||
this.setState({ | ||
map: map, | ||
lat: position.coords.latitude || 51.3, | ||
lng: position.coords.longitude || 0.7, | ||
}); | ||
|
||
map.setView(L.latLng(this.state.lat, this.state.lng), 15); | ||
map.addLayer(TILE_LAYER); | ||
|
||
L.marker([this.state.lat, this.state.lng]) | ||
.addTo(map).bindPopup('Current Location').openPopup(); | ||
} | ||
|
||
render() { | ||
const styles = { | ||
leaflet: leafletStyle, | ||
height: 500, // HAVE TO SET HEIGHT TO RENDER MAP | ||
} | ||
return ( | ||
<div id="map" style={styles}/> | ||
) | ||
}; | ||
|
||
componentWillUnmount() { | ||
console.log('begin - componentWillUnmount() ', this.state.map); | ||
// stop watching user position when map is unmounted | ||
navigator.geolocation.clearWatch(this.state.watchID); | ||
this.state.map.remove(); | ||
console.log('begin - componentWillUnmount() ', this.state.map); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#map { | ||
height: 100%; | ||
} | ||
/* Optional: Makes the sample page fill the window. */ | ||
html, body { | ||
height: 100%; | ||
margin: 0; | ||
padding: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { h, Component } from 'preact'; | ||
import style from './style'; | ||
|
||
import Map, { GoogleApiWrapper, Marker, InfoWindow, Listing } from 'google-maps-react'; | ||
const { GOOGLE_API_KEY } = require('../../../config'); | ||
|
||
class PlacesContainer extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
showingInfoWindow: false, | ||
activeMarker: {}, | ||
selectedPlace: {}, | ||
places: [], | ||
lat: null, | ||
lng: null, | ||
} | ||
this.onMarkerClick = this.onMarkerClick.bind(this); | ||
this.onMapClicked = this.onMapClicked.bind(this); | ||
this.geolocatonSuccess = this.geolocatonSuccess.bind(this); | ||
navigator.geolocation.getCurrentPosition(this.geolocatonSuccess); | ||
this.fetchPlaces = this.fetchPlaces.bind(this); | ||
this.update = this.update.bind(this); | ||
} | ||
|
||
geolocatonSuccess(position) { | ||
this.setState({ | ||
lat: position.coords.latitude, | ||
lng: position.coords.longitude, | ||
}); | ||
} | ||
|
||
onMarkerClick = (props, marker, e) => { | ||
this.setState({ | ||
selectedPlace: props, | ||
activeMarker: marker, | ||
showingInfoWindow: true | ||
}); | ||
}; | ||
|
||
onMapClicked = (props) => { | ||
if (this.state.showingInfoWindow) { | ||
this.setState({ | ||
showingInfoWindow: false, | ||
activeMarker: null | ||
}) | ||
} | ||
}; | ||
|
||
fetchPlaces(mapProps, map) { | ||
const {google} = mapProps; | ||
console.log(mapProps); | ||
let curr = new google.maps.LatLng(this.state.lat,this.state.lng); | ||
let request = { | ||
location: curr, | ||
radius: '2000', | ||
type: ['food'] | ||
} | ||
let service = new google.maps.places.PlacesService(map); | ||
service.nearbySearch(request, function(results, status, res) { | ||
if (status == google.maps.places.PlacesServiceStatus.OK) { | ||
for (var i = 0; i < results.length; i++) { | ||
var place = results[i]; | ||
addToArr(place); | ||
// console.log(place); | ||
} | ||
} | ||
}); | ||
const addToArr = (place) => this.update(place); | ||
} | ||
|
||
update(place) { | ||
var arrayvar = this.state.places.slice(); | ||
arrayvar.push(place); | ||
this.setState({ places: arrayvar }) | ||
} | ||
|
||
render() { | ||
const markers = this.state.places.map(place => | ||
<Marker | ||
name={place.name} | ||
position={{ | ||
lat: place.geometry.location.lat(), | ||
lng: place.geometry.location.lng() | ||
}} | ||
onClick={this.onMarkerClick} | ||
/> | ||
); | ||
|
||
return ( | ||
<Map | ||
google={this.props.google} | ||
zoom={14} | ||
center={{ | ||
lat: this.state.lat, | ||
lng: this.state.lng, | ||
}} | ||
onClick={this.fetchPlaces} | ||
> | ||
{markers} | ||
<InfoWindow | ||
marker={this.state.activeMarker} | ||
visible={this.state.showingInfoWindow} | ||
> | ||
<h1> | ||
{this.state.selectedPlace.name} | ||
</h1> | ||
</InfoWindow> | ||
</Map> | ||
); | ||
} | ||
} | ||
|
||
export default GoogleApiWrapper({ | ||
apiKey: GOOGLE_API_KEY, | ||
})(PlacesContainer) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.