Skip to content

Commit 6bd00be

Browse files
barakplasmaitsmichaeldiego
authored andcommitted
Add Heatmap Example (#19)
* 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
1 parent c64d673 commit 6bd00be

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/Home.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const Home = () => (
5555
<ListItem>
5656
<StyledLink to={`${defaultPath}default`}>Default</StyledLink>
5757
</ListItem>
58+
<ListItem>
59+
<StyledLink to={`${defaultPath}heatmap`}>Heatmap</StyledLink>
60+
</ListItem>
5861
<ListItem>
5962
<StyledLink to={`${defaultPath}searchbox`}>SearchBox</StyledLink>
6063
</ListItem>

src/examples/Heatmap.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React, { Component, Fragment } from 'react';
2+
import isEmpty from 'lodash.isempty';
3+
4+
// examples:
5+
import GoogleMap from '../components/GoogleMap';
6+
7+
// consts
8+
import LOS_ANGELES_CENTER from '../const/la_center';
9+
10+
class Heatmap extends Component {
11+
constructor(props) {
12+
super(props);
13+
14+
this.state = {
15+
places: [],
16+
};
17+
}
18+
19+
componentDidMount() {
20+
fetch('places.json')
21+
.then(response => response.json())
22+
.then(data => this.setState({ places: data.results }));
23+
}
24+
25+
render() {
26+
const { places } = this.state;
27+
const data = places.map(place => ({
28+
lat: place.geometry.location.lat,
29+
lng: place.geometry.location.lng,
30+
weight: Math.floor(Math.random() * Math.floor(5)),
31+
}));
32+
const heatmapData = {
33+
positions: data,
34+
options: {
35+
radius: 20,
36+
opacity: 1,
37+
},
38+
};
39+
40+
return (
41+
<Fragment>
42+
{!isEmpty(places) && (
43+
<GoogleMap
44+
defaultZoom={10}
45+
defaultCenter={LOS_ANGELES_CENTER}
46+
heatmap={heatmapData}
47+
bootstrapURLKeys={{
48+
key: process.env.REACT_APP_MAP_KEY,
49+
libraries: ['visualization'],
50+
}}
51+
/>
52+
)}
53+
</Fragment>
54+
);
55+
}
56+
}
57+
58+
export default Heatmap;

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Route, Switch, Redirect, BrowserRouter as Router } from 'react-router-d
55
// examples:
66
import Home from './Home';
77
import Main from './examples/Main';
8+
import Heatmap from './examples/Heatmap';
89
import SearchBox from './examples/Searchbox';
910
import Autocomplete from './examples/Autocomplete';
1011

@@ -26,6 +27,7 @@ ReactDOM.render(
2627
<Route exact path={defaultPath} component={Home} />
2728
{/* New examples here */}
2829
<Route path={`${defaultPath}default`} component={Main} />
30+
<Route path={`${defaultPath}heatmap`} component={Heatmap} />
2931
<Route path={`${defaultPath}searchbox`} component={SearchBox} />
3032
<Route path={`${defaultPath}autocomplete`} component={Autocomplete} />
3133
<Redirect exact from="*" to={defaultPath} />

0 commit comments

Comments
 (0)