-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
345 lines (297 loc) · 12.6 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE html>
<html>
<!--The head section is the title, styling rules, link to other sources and other meta fields -->
<head>
<!--this line defines the encoding type of the web document-->
<meta charset='utf-8' />
<!--this defines the title of the web page-->
<title>Data_Science_Italy</title>
<!--this line controls how our map is displayed in a mobile browser-->
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<!--this two lines import our map from mapbox (first one javascript code and second css stylesheet-->
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.5.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.5.0/mapbox-gl.css' rel='stylesheet' />
<!--here we define the style of our document using css rules-->
<style>
/*this defines the style of the body (ex. font style, font size, etc*/
body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 14px;
}
/*this defines the style of the map*/
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
/*this defines the style spacing of the text legend panel*/
li {
padding: 3px
}
/*this defines the style for the legend panel features that will be called underneath in the body*/
#panel {
background: rgba(0,0,0,0.5);
width: 310px;
border: 1px solid rgba(0,0,0,0.05);
position: absolute;
right: 16px;
top: 16px;
box-shadow: 0 0 4px 0 rgba(0,0,0,0.1);
color: rgba(255,255,255,0.9); /*this changes the text color*/
}
/*this defines the style of the legend title*/
h4 {
/*text-transform: lowercase;*/
border-bottom: 1px solid rgba(255,255,255,0.07); /*this changes the line color*/
margin:0;
padding: 16px;
}
/*this defines the spacing style for each legend text bullets*/
ul {
list-style-type: none; /*this line turns off the existing bullets*/
margin: 0;
padding: 16px;
}
/*this defines the style and shape of the legend text bullets*/
ul span {
width: 10px; /*width of bullet*/
height: 10px; /*height of bullet*/
display: inline-block; /*this is the bullet as a little square*/
margin-right: 8px; /*this sets the space beetween text and bullet*/
border-radius: 50%; /*this makes the bullet as a circle*/
}
/*I can find dd using the developer tools -> elements -> body -> div class -> div class -> dl -> dd */
/*this block defines the visual style of the pop up window that appears when I click on one of the restaurants */
dd {
margin-left : 0; /*this defines the left justification*/
margin-bottom : 8px; /*this defines the space from the bottom*/
font-weight : bold; /*this defines the text weight*/
color:white;
}
/*This block defines the text style and size of popup windows that appears when I click on a region*/
.mapboxgl-popup-content{
font-size: 14px;
box-shadow: 0 0 4px 0;
min-width: 260px;
max-height: 110px;
box-shadow: 0 0 4px 0 rgba(0,0,0,0.1);
color: rgb(134, 134, 134);
background: rgba(0,0,0,0.9);
border-radius: 10px;
}
#popup {
width: 300px;
height: 110px;
}
.popup-name {
margin-bottom: 8px;
width: 180px;
}
.popup-inner {
position: relative;
top: -130px;
right: -170px;
width: 150px;
}
.popup-list {
position: relative;
height: 80px;
width: 50px;
top: 32px;
left: 20px;
list-style-type: none;
background: rgba(0, 0, 0, 0);
transform: rotate(90deg);
}
.popup-graph-title {
position: absolute;
color: #747474;
}
.popup-listItem1 {
position: absolute;
bottom: -5px;
left: 20px;
height: 100px;
width: 10px;
background: rgba(0, 0, 0, 0);
}
.popup-listItem2 {
position: absolute;
bottom: -5px;
left: 40px;
height: 100px;
width: 10px;
background: rgba(0, 0, 0, 0);
}
.popup-listItem3 {
position: absolute;
bottom: -5px;
left: 60px;
height: 100px;
width: 10px;
background: rgba(0, 0, 0, 0);
}
.popup-listBar {
height: 80px;
width: 8px;
display: flex;
flex-direction: column;
transform: rotate(90deg);
}
.popup-listBar2 {
height: 80px;
width: 8px;
display: flex;
flex-direction: column;
transform: rotate(90deg);
}
.popup-listBar3 {
height: 80px;
width: 8px;
display: flex;
flex-direction: column;
justify-content: flex-end;
transform: rotate(90deg);
}
.popup-listBar span {
position: fixed;
bottom: 41px;
left: 60px;
width: 100%;
background: #ac0202;
border-radius: 25px;
transform: rotate(270deg);
transform-origin: bottom center;
}
.popup-listBar2 span {
position: fixed;
bottom: 41px;
left: 60px;
width: 100%;
background: #006666;
border-radius: 25px;
transform: rotate(270deg);
transform-origin: bottom center;
}
.popup-listBar3 span {
position: fixed;
bottom: 41px;
left: 60px;
width: 100%;
background: #48f5fe;
border-radius: 25px;
transform: rotate(270deg);
transform-origin: bottom center;
}
/*This block defines the bottom margin of the text inside the popup window*/
dl{
margin-bottom: 0;
}
</style>
</head>
<!--The body section contains all the visible elements of the page (ex. map, legend and other elements user interface) -->
<body>
<!--this line is the map-->
<div id='map'></div>
<div id='panel'>
<!--legend title-->
<h4>Economic and Social Satisfaction Italian Youngsters Graduates (20-34)</h4>
<ul>
<!--elements of the legend-->
<!--the span elements create the bullets in front of the text (the bullets features are defined above in the css rules in span-->
<li><span style='background: #ac0202;'></span>Very Low Economic Satisfaction</li>
<li><span style='background: #ff4747;'></span>Moderately Low Economic Satisfaction </li>
<li><span style='background: #ff9999;'></span>Medium Economic Satisfaction</li>
<li><span style='background: #48f5fe;'></span>Moderately Low Social Satisfaction</li>
<li><span style='background: #006666;'></span>Very Low Social Satisfaction</li>
</ul>
</div>
<!--Here between the script marks there is all the javascript code that control the user interaction-->
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiaWFjb3BvLWRzIiwiYSI6ImNrMzJ1NHBtdzA1b3YzbW55ZTJhbzZtdmgifQ.RcWjOUEo4i7LnQDcbhcPWQ'; // key used to make the link public on github
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/iacopo-ds/ckd7h4myz00zo1jlqooil10vs', // this is the map I created in mapbox
center: [12.055, 42.216], // starting position [lng, lat]
zoom: 5.4, // starting zoom
minZoom: 5.4,
maxZoom: 18
});
/*This block defines the map navigator on the top left of the map*/
var nav = new mapboxgl.NavigationControl();
map.addControl(nav, 'top-left');
/*This block makes the mouse change when it is above something that is possible to query*/
map.on('mousemove', function (event) {
if (map.loaded()) {
var features = map.queryRenderedFeatures(event.point, {
layers: ['visualdatamining'] /*this is the layer name in the mapbox map */
});
/*This line is an if statement, ? equals if and : equals else*/
map.getCanvas().style.cursor = features.length ? 'pointer' : '';
}
});
/*this block defines the mouse click */
map.on('click', function (event) {
var geometry = event.point;
var parameters = {
layers : ['visualdatamining'] /*this is the layer name in the mapbox map */
};
var features = map.queryRenderedFeatures(geometry, parameters);
var lot = features[0];
console.log(lot);
/*This if statement is useful to avoid errors in case of clicks where there are no data*/
if (features.length>0) {
/*these lines select the properties I want to show in the pop up window*/
// correggere --> var urbanZone = lot.properties.codzu|| '—';
var region = lot.properties.regione || '—';
var cluster1 = lot.properties.clusterA || '—';
var cluster2 = lot.properties.clusterB || '—';
var cluster3 = lot.properties.clusterC || '—';
console.log(region);
/*this creates the pop up (look at mapbox GL JS API for more information) */
var popup = new mapboxgl.Popup()
.setLngLat(event.lngLat) /*this is the mouse location */
.setHTML(
'<div id="popup" style="display: block;">' +
'<div class="popup-name">' +
'<span>' +
'<dt>Region :</dt>' +
'<dd>' + region + '</dd>' +
'<dt>Economic Dissatisfaction :</dt>' +
'<dt>Social Dissatisfaction :</dt>' +
'<dt>Satisfied :</dt>' +
'</span>' +
'</div>' +
'<div class="popup-inner">' +
'<ul class="popup-list">' +
'<li class="popup-listItem1">' +
'<div class="popup-listBar">' +
'<span style="height:' + cluster1 + '%;">' +
'</span>' +
'</div>' +
'</li>'+
'<li class="popup-listItem2">' +
'<div class="popup-listBar2">' +
'<span style="height:' + cluster2 + '%;">' +
'</span>' +
'</div>' +
'</li>'+
'<li class="popup-listItem3">' +
'<div class="popup-listBar3">' +
'<span style="height:' + cluster3 + '%;">' +
'</span>' +
'</div>' +
'</li>'+
'</ul>' +
'</div>' +
'</div>'
)
.addTo(map); /*this line adds the pop up to the map */
}
});
</script>
</body>
</html>