-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
571 lines (487 loc) · 21.1 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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
<!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>Urban Forestry | Madrid</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*/
}
#legend {
background: rgba(0,0,0,0.5);
width: 310px;
height: 260px;
border: 1px solid rgba(0,0,0,0.05);
position: absolute;
right: 0px;
top: 200px;
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: 260px;
min-height: 260px;
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;
}
/*This block defines tip color (small triangle when clicking)*/
.mapboxgl-popup-anchor-top .mapboxgl-popup-tip,
.mapboxgl-popup-anchor-top-left .mapboxgl-popup-tip,
.mapboxgl-popup-anchor-top-right .mapboxgl-popup-tip {
border-bottom-color: rgba(0,0,0,0.9);
}
.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip,
.mapboxgl-popup-anchor-bottom-left .mapboxgl-popup-tip,
.mapboxgl-popup-anchor-bottom-right .mapboxgl-popup-tip {
border-top-color: rgba(0,0,0,0.9);
}
.mapboxgl-popup-anchor-left .mapboxgl-popup-tip {
border-right-color: rgba(0,0,0,0.9);
}
.mapboxgl-popup-anchor-right .mapboxgl-popup-tip {
border-left-color: rgba(0,0,0,0.9);
}
#popup {
width: 300px;
height: 250px;
}
.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: 15px;
left: -62px;
height: 60px;
width: 10px;
background: rgba(0, 0, 0, 0);
}
.popup-listItem2 {
position: absolute;
bottom: 15px;
left: -42px;
height: 60px;
width: 10px;
background: rgba(0, 0, 0, 0);
}
.popup-listItem3 {
position: absolute;
bottom: 15px;
left: -22px;
height: 60px;
width: 10px;
background: rgba(0, 0, 0, 0);
}
.popup-listItem4 {
position: absolute;
bottom: 15px;
left: -2px;
height: 60px;
width: 10px;
background: rgba(0, 0, 0, 0);
}
.popup-listItem5 {
position: absolute;
bottom: 15px;
left: 18px;
height: 60px;
width: 10px;
background: rgba(0, 0, 0, 0);
}
.popup-listItem6 {
position: absolute;
bottom: 15px;
left: 38px;
height: 60px;
width: 10px;
background: rgba(0, 0, 0, 0);
}
.popup-listItem7 {
position: absolute;
bottom: 15px;
left: 58px;
height: 60px;
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-listBar4 {
height: 80px;
width: 8px;
display: flex;
flex-direction: column;
justify-content: flex-end;
transform: rotate(90deg);
}
.popup-listBar5 {
height: 80px;
width: 8px;
display: flex;
flex-direction: column;
justify-content: flex-end;
transform: rotate(90deg);
}
.popup-listBar6 {
height: 80px;
width: 8px;
display: flex;
flex-direction: column;
justify-content: flex-end;
transform: rotate(90deg);
}
.popup-listBar7 {
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;
height:10%;
width: 100%;
background: #3fd68e;
border-radius: 25px;
transform: rotate(270deg);
transform-origin: bottom center;
}
.popup-listBar2 span {
position: fixed;
bottom: 41px;
left: 60px;
width: 100%;
background: #3fd68e;
border-radius: 25px;
transform: rotate(270deg);
transform-origin: bottom center;
}
.popup-listBar3 span {
position: fixed;
bottom: 41px;
left: 60px;
width: 100%;
background: #3fd68e;
border-radius: 25px;
transform: rotate(270deg);
transform-origin: bottom center;
}
.popup-listBar4 span {
position: fixed;
bottom: 41px;
left: 60px;
width: 100%;
background: #3fd68e;
border-radius: 25px;
transform: rotate(270deg);
transform-origin: bottom center;
}
.popup-listBar5 span {
position: fixed;
bottom: 41px;
left: 60px;
width: 100%;
background: #3fd68e;
border-radius: 25px;
transform: rotate(270deg);
transform-origin: bottom center;
}
.popup-listBar6 span {
position: fixed;
bottom: 41px;
left: 60px;
width: 100%;
background: #3fd68e;
border-radius: 25px;
transform: rotate(270deg);
transform-origin: bottom center;
}
.popup-listBar7 span {
position: fixed;
bottom: 41px;
left: 60px;
width: 100%;
background: #3fd68e;
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>Environmental Discomfort Level</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 High</li>
<li><span style='background: #ff4747;'></span>Moderately High</li>
<li><span style='background: #ff9999;'></span>Medium</li>
<li><span style='background: #48f5fe;'></span>Moderately Low</li>
<li><span style='background: #006666;'></span>Very Low</li>
</ul>
<div id='legend'>
<!--legend title-->
<h4>Units Legend</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>Carbon Monoxide | mg/m<sup>3</li>
<li>Noise Pollution | decibel</li>
<li>Particulate Matter | µg/m<sup>3<li>
<li>Rainfall | l/m<sup>2</li>
<li>Solar Radiation | W/m<sup>2</li>
<li>Temperature | ºC</li>
<li>Trees Density | trees/km<sup>2</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/ckifyeijo1c1h1ao7ymme4ew5', // this is the map I created in mapbox
center: [-3.696, 40.435], // starting position [lng, lat]
zoom: 10, // starting zoom
minZoom: 10,
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: ['indexmadrid'] /*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 : ['indexmadrid'] /*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 neighborhood = lot.properties.name_barrios || '—';
var carbon_monoxide = lot.properties.carbon_monoxide || '—';
var carbon_monoxide_units = lot.properties.co_units || '—';
var noise_pollution = lot.properties.noise_pollution || '—';
var noise_pollution_units = lot.properties.noise_units || '—';
var particulate_matter = lot.properties.pm_10 || '—';
var particulate_matter_units = lot.properties.pm_units || '—';
var rainfall = lot.properties.rainfall || '—';
var rainfall_units = lot.properties.rain_units || '—';
var solar_radiation = lot.properties.solar_radiation || '—';
var solar_radiation_units = lot.properties.solar_units || '—';
var temperature = lot.properties.temperature || '—';
var temperature_units = lot.properties.temp_units || '—';
var trees_density = lot.properties.trees_density || '—';
var trees_density_units = lot.properties.trees_units || '—';
var edi = lot.properties.mpi_index || '—';
console.log(neighborhood);
/*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>Neighborhood :</dt>' +
'<dd>' + neighborhood + '</dd>' +
'<dt>Environmental Discomfort Index (2019) :</dt>' +
'<dd>' + edi + '</dd>' +
'<dt>carbon monoxide : '+ carbon_monoxide_units + '</dt>' +
'<dt>noise pollution : '+ noise_pollution_units + '</dt>' +
'<dt>pm 10 : '+ particulate_matter_units + '</dt>' +
'<dt>rainfall : '+ rainfall_units + '</dt>' +
'<dt>solar radiation : '+ solar_radiation_units + '</dt>' +
'<dt>temperature :' + temperature_units + '</dt>' +
'<dt>trees density : '+ trees_density_units + '</dt>' +
'</span>' +
'</div>' +
'<div class="popup-inner">' +
'<ul class="popup-list">' +
'<li class="popup-listItem1">' +
'<div class="popup-listBar">' +
'<span style="height:' + carbon_monoxide + '%;">' +
'</span>' +
'</div>' +
'</li>'+
'<li class="popup-listItem2">' +
'<div class="popup-listBar2">' +
'<span style="height:' + noise_pollution + '%;">' +
'</span>' +
'</div>' +
'</li>'+
'<li class="popup-listItem3">' +
'<div class="popup-listBar3">' +
'<span style="height:' + particulate_matter + '%;">' +
'</span>' +
'</div>' +
'</li>'+
'<li class="popup-listItem4">' +
'<div class="popup-listBar3">' +
'<span style="height:' + rainfall + '%;">' +
'</span>' +
'</div>' +
'</li>'+
'<li class="popup-listItem5">' +
'<div class="popup-listBar3">' +
'<span style="height:' + solar_radiation + '%;">' +
'</span>' +
'</div>' +
'</li>'+
'<li class="popup-listItem6">' +
'<div class="popup-listBar3">' +
'<span style="height:' + temperature + '%;">' +
'</span>' +
'</div>' +
'</li>'+
'<li class="popup-listItem7">' +
'<div class="popup-listBar3">' +
'<span style="height:' + trees_density + '%;">' +
'</span>' +
'</div>' +
'</li>'+
'</ul>' +
'</div>' +
'</div>'
)
.addTo(map); /*this line adds the pop up to the map */
}
});
</script>
</body>
</html>