-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update Home.js * Update index.js * Create Heatmap.jsx * now generating random heatmap weights * Delete package-lock.json Project uses yarn * sorted the imports and routes according to path length * matching import of heatmap visualization library to autocomplete example * changed linebreaks to LF to pass eslint
- Loading branch information
1 parent
c64d673
commit 6bd00be
Showing
3 changed files
with
63 additions
and
0 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
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,58 @@ | ||
import React, { Component, Fragment } from 'react'; | ||
import isEmpty from 'lodash.isempty'; | ||
|
||
// examples: | ||
import GoogleMap from '../components/GoogleMap'; | ||
|
||
// consts | ||
import LOS_ANGELES_CENTER from '../const/la_center'; | ||
|
||
class Heatmap extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
places: [], | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
fetch('places.json') | ||
.then(response => response.json()) | ||
.then(data => this.setState({ places: data.results })); | ||
} | ||
|
||
render() { | ||
const { places } = this.state; | ||
const data = places.map(place => ({ | ||
lat: place.geometry.location.lat, | ||
lng: place.geometry.location.lng, | ||
weight: Math.floor(Math.random() * Math.floor(5)), | ||
})); | ||
const heatmapData = { | ||
positions: data, | ||
options: { | ||
radius: 20, | ||
opacity: 1, | ||
}, | ||
}; | ||
|
||
return ( | ||
<Fragment> | ||
{!isEmpty(places) && ( | ||
<GoogleMap | ||
defaultZoom={10} | ||
defaultCenter={LOS_ANGELES_CENTER} | ||
heatmap={heatmapData} | ||
bootstrapURLKeys={{ | ||
key: process.env.REACT_APP_MAP_KEY, | ||
libraries: ['visualization'], | ||
}} | ||
/> | ||
)} | ||
</Fragment> | ||
); | ||
} | ||
} | ||
|
||
export default Heatmap; |
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