-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
92 lines (77 loc) · 1.91 KB
/
index.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
// console.log('hello there');
window.Data;
window.countryData
fetch('https://api.covid19api.com/summary')
.then((res)=>res.json())
.then((data)=>{
Data=data;
fetch('country_alpha3_Code.json').then((res)=>{
return res.json()
}).then((Cdata)=>{
countryData =Cdata ;
})
}
);
// const data = [
// { 'code': 'USA', 'hdi': 0.811 },
// { 'code': 'IND', 'hdi': 0.811 }
// ];
map.on('load', () => {
map.addSource('countries', {
type: 'vector',
url: 'mapbox://mapbox.country-boundaries-v1'
});
const matchExpression = ['match', ['get', 'iso_3166_1_alpha_3']];
// console.log(Data.Countries);
for (const row of Data.Countries) {
// // Convert the range of data values to a suitable color
const number = row['NewConfirmed'];
// console.log(row['TotalConfirmed']);
var red =0;
var blue =0;
var yellow=0;
if(number>10000)
red=80;
else if(number>100&&number<10000){
red=170;
yellow=100;
}
else if(number<100&&number>0){
red=200;
blue=50;
yellow=150;
}
else if(number==0){
blue =255;
}
// else
// // red=10;
// blue=10;
// console.log( row.Country+": "+row.NewConfirmed);
// console.log(red);
var color = `rgb(${red}, ${yellow}, ${blue})`;
// console.log(color);
for(let y of countryData){
if(y.name===row.Country){
// console.log(y.name);
// console.log(row.Country);
// color = `rgb(250, 0, 0)`;
// console.log(y["alpha-3"]);
matchExpression.push(y["alpha-3"], color);
}
}
}
matchExpression.push('rgba(0, 0, 0, 0)');
map.addLayer(
{
'id': 'countries-join',
'type': 'fill',
'source': 'countries',
'source-layer': 'country_boundaries',
'paint': {
'fill-color': matchExpression
}
},
'admin-1-boundary-bg'
);
});