-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathHeatmap.js
58 lines (50 loc) · 1.22 KB
/
Heatmap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { Component } 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 (
<>
{!isEmpty(places) && (
<GoogleMap
defaultZoom={10}
defaultCenter={LOS_ANGELES_CENTER}
heatmap={heatmapData}
bootstrapURLKeys={{
key: process.env.REACT_APP_MAP_KEY,
libraries: ['visualization'],
}}
/>
)}
</>
);
}
}
export default Heatmap;