-
Notifications
You must be signed in to change notification settings - Fork 5
/
App.js
78 lines (73 loc) · 2.02 KB
/
App.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import { GoogleMapLoader, GoogleMap, Marker } from 'react-google-maps';
import Hexbin from './Hexbin.js';
import fakeStoreLatLngData from './data/generated-data.json';
const MAP_PIXEL_HEIGHT = 600;
const HEX_PIXEL_RADIUS = 50;
class App extends Component {
constructor() {
super();
this.state = {
isMarkerOn: false,
}
this.toggleMarker = this.toggleMarker.bind(this);
}
toggleMarker() {
this.setState({
isMarkerOn: !this.state.isMarkerOn,
})
}
render() {
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Hexbin Demo</h2>
</div>
<GoogleMapLoader
query={{ libraries: 'geometry,drawing,places,visualization' }}
containerElement={
<div
style={{ width: '100%', height: MAP_PIXEL_HEIGHT }}
/>
}
googleMapElement={
<GoogleMap
defaultZoom={12}
options={{ mapTypeControl: false }}
defaultCenter={{ lat: 37.518397, lng: 126.978886 }}
>
<Hexbin
hexPixelRadius={HEX_PIXEL_RADIUS}
mapPixelHeight={MAP_PIXEL_HEIGHT}
data={fakeStoreLatLngData}
colorRange={['white', 'rgb(242, 117, 165)']}
/>
{
this.state.isMarkerOn ?
fakeStoreLatLngData.map(point => ({ position: point })
).map((obj, idx) => (
<Marker
key={idx}
{...obj}
/>
))
:
null
}
</GoogleMap>
}
/>
<button
style={{ margin: 25, padding: 10 }}
onClick={this.toggleMarker}
>
Toggle Markers
</button>
</div>
);
}
}
export default App;