-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
193 lines (169 loc) · 6.31 KB
/
index.html
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<style>
body {
padding-left: 30px;
padding-right: 30px;
}
#map {
width: 800px;
height: 600px;
}
.ghbtns {
position: relative;
top: 4px;
margin-left: 5px;
}
#spidergraphcontainer {
display: inline-block;
width: 100%;
height: 300px;
}
</style>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
<title>Vibe of Boston</title>
</head>
<body>
<h1>Vibe of Boston</h1>
<h4>Marc Bacvanski and Vedant Rautela</h4>
<div class="w-screen mt-4"> <!--style="padding-left:30px; padding-right: 30px">-->
<div class="row">
<div class="col-9">
<div id="map" style="width: 95%"></div>
</div>
<div class="col-3" style="text-align: center">
<div id="spidergraphcontainer"></div>
<p style="text-align: left">
Honesty: How accurate visitors found the description of an area
</p>
<hr>
<p style="text-align: left">
Happiness: Average sentiment of visitors
</p>
<hr>
<p style="text-align: left">
Liveliness: Number of visitors
</p>
<hr>
<p style="text-align: left">
Walkability: How walkable visitors found an area to be
</p>
<hr>
<p style="text-align: left">
Peacefulness: How quiet/tranquil visitors found an area to be
</p>
</div>
</div>
</div>
<p style="padding-top: 30px">
Use the alignment chart on the right to select what weight you give to each of the vibe factors.
<br>
The heatmap on the left will show you which regions of Boston align most with the features you selected.
<br>
Zoom in to take a closer look at which neighborhoods specifically suit you.
</p>
<script src="dist/leaflet-heat.js"></script>
<script src="dist/spidergraph.js"></script>
<script>
const defaultWeights = {
'honesty': 10,
'happiness': 10,
'liveliness': 10,
'walkability': 10,
'peacefulness': 10,
};
$(document).ready(function () {
let vibedata;
const map = L.map('map').setView([42.317048, -71.077208], 11);
const tiles = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map);
$.ajax({
type: 'GET',
url: 'dist/data/scaled_table.json',
dataType: 'text',
success: function (data) {
vibedata = JSON.parse(data);
processVibeTable(vibedata, defaultWeights, map);
}
});
$('#spidergraphcontainer').spidergraph({
'fields': ['Honesty', 'Happiness', 'Liveliness', 'Walkability', 'Peacefulness'],
'gridcolor': 'rgb(172,172,172)',
'linear': true,
});
$('#spidergraphcontainer').spidergraph('setactivedata', {
'strokecolor': 'rgba(46,131,230,0.8)',
'fillcolor': 'rgba(46,131,230,0.6)',
'data': [
defaultWeights['honesty'],
defaultWeights['happiness'],
defaultWeights['liveliness'],
defaultWeights['walkability'],
defaultWeights['peacefulness'],
],
'linear': true,
});
$('#spidergraphcontainer').bind('spiderdatachange', function (ev, data) {
processVibeTable(vibedata, {
'honesty': data[0],
'happiness': data[1],
'liveliness': data[2],
'walkability': data[3],
'peacefulness': data[4],
}, map);
});
});
function processVibeTable(data, weights, map) {
let biggestVibe = 0;
let formattedData = [];
Object.keys(data).forEach(key => {
const point = data[key];
const vibe = calcVibe(point, weights);
const arr = [point['lat'], point['lon'], vibe];
formattedData.push(arr);
if (vibe > biggestVibe) {
biggestVibe = vibe;
}
});
map.eachLayer(function (layer) {
map.removeLayer(layer);
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map);
const heat = L.heatLayer(formattedData, {
max: biggestVibe,
gradient: {0.1: 'blue', 0.2: 'green', 0.3: 'yellow', 0.4: 'orange', 1: 'red'}
}).addTo(map);
}
function calcVibe(datapoint, weights) {
return 2 * (weights['honesty'] - (defaultWeights['honesty'] * 4.0 / 5)) * datapoint['honesty'] +
0.5 * (weights['happiness'] - (defaultWeights['happiness'] * 4.0 / 5)) * datapoint['happiness'] +
2 * (weights['liveliness'] - (defaultWeights['liveliness'] * 4.0 / 5)) * datapoint['liveliness'] +
2 * (weights['walkability'] - (defaultWeights['walkability'] * 4.0 / 5)) * datapoint['walkability'] +
2 * (weights['peacefulness'] - (defaultWeights['peacefulness'] * 1.0 / 5)) * datapoint['peacefulness'];
}
</script>
</body>
</html>