-
Notifications
You must be signed in to change notification settings - Fork 0
/
Map.js
148 lines (128 loc) · 4.88 KB
/
Map.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import React, {Component} from 'react';
import MapGL, {Marker, Popup, NavigationControl, FullscreenControl} from 'react-map-gl';
import ControlPanel from './ControlPanel';
import Pin from './Pin';
import { Button } from 'react-bootstrap';
import './Map.css';
const width = window.innerWidth;
const height = window.innerHeight;
const winSize = width * height;
const zoom = winSize < 260000 ? 0 : (winSize < 580000 ? 0.5: 1);
const nav = {
position: 'absolute',
top: 36,
left: 0,
padding: '10px',
}
const fullscreen = {
position: 'absolute',
top: 0,
left: 0,
padding: '10px',
};
class Map extends Component {
constructor(props) {
super(props);
this.state = {
viewport: {
zoom: zoom
},
popupInfo: null,
};
}
_renderCityMarker = (entry, key) => {
const loc = entry['loc'];
if(!entry['ip'] || !loc.lat || !loc.long) {
return null;
}
return (
<Marker key={`marker-${key}`} longitude={loc.long} latitude={loc.lat}>
<Pin size={20} access={entry['access']} onClick={() => this.setState({popupInfo: {key: key, entry: entry}})} />
</Marker>
);
};
_renderPopup() {
const {popupInfo} = this.state;
return (
popupInfo && (
<Popup
tipSize={5}
anchor="top"
longitude={popupInfo['entry']['loc']['long']}
latitude={popupInfo['entry']['loc']['lat']}
offsetTop={5}
closeOnClick={false}
closeButton={true}
onClose={() => this.setState({popupInfo: null})}
>
<div style={{paddingTop: 10, fontFamily: 'Maven Pro'}}>
<table>
<tbody>
<tr>
<td><b>policyId:</b></td>
<td>{popupInfo['key']}</td>
</tr>
<hr></hr>
<tr>
<td><b>File:</b></td>
<td>{popupInfo['entry']['file']}</td>
</tr>
<tr>
<td><b>Users:</b></td>
<td>{popupInfo['entry']['users']}</td>
</tr>
<tr>
<td><b>IP Address:</b></td>
<td>{popupInfo['entry']['ip']}</td>
</tr>
<tr>
<td><b>Location:</b></td>
<td>{[popupInfo['entry']['loc']['city'], popupInfo['entry']['loc']['country']].join(', ')}</td>
</tr>
</tbody>
</table>
</div>
<div style={{display: "flex", justifyContent: "center"}}>
<Button
variant={popupInfo['entry']['access'] === 'REVOKE' ? "outline-primary" : "outline-danger"}
onClick={() => this.props.flipAccess(popupInfo['key'])}
>
{popupInfo['entry']['access'] === 'REVOKE' ? "GRANT ACCESS 🔵" : "REVOKE ACCESS 🛑"}
</Button>
</div>
</Popup>
)
);
}
render() {
const {viewport} = this.state;
return (
<MapGL
{...viewport}
width = "100%"
height = "65vh"
attributionControl = {false}
mapboxApiAccessToken={process.env.REACT_APP_MAPBOX}
mapStyle = "mapbox://styles/mapbox/dark-v9"
onViewportChange={viewport => this.setState({viewport})}
>
{console.log(this.props.data)}
{Object.keys(this.props.data).map((entry, key) =>
this._renderCityMarker(this.props.data[entry], entry))}
{this._renderPopup()}
<div style = {fullscreen}>
<FullscreenControl />
</div>
<div style = {nav}>
<NavigationControl />
</div>
<ControlPanel
containerComponent={this.props.containerComponent}
addPolicy={this.props.addPolicy}
client={this.props.client}
/>
</MapGL>
);
}
}
export default Map;