-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstateshow.js
155 lines (131 loc) · 5.35 KB
/
stateshow.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
149
150
151
152
153
154
155
const queryParams = new URLSearchParams(window.location.search)
const stateName = queryParams.get('id')
const pageTitle = document.querySelector('.hero')
const stateCard = document.querySelector('.state-card')
fetch(`http://localhost:3000/covids/${stateName}`)
.then(response => response.json())
.then(state => {
const stateName = document.createElement('h2')
const toFullName = state.state
const positive = document.createElement('h4')
positive.textContent = `Current number of total positive cases are: ${state.positive}`
const totalTests = document.createElement('h4')
totalTests.textContent = `To date, there has been ${state.totalTestResults} total tests peformed.`
const deaths = document.createElement('h4')
deaths.textContent = `The total number of deaths is currently at ${state.death}.`
//will turn abbr to full state name and place on hero
pageTitle.append(abbrToState(toFullName))
//appends to the state card
stateCard.append(positive,totalTests, deaths)
fetch('http://localhost:3000/heat_map')
.then(response => response.json())
.then(states => {
let fullState = abbrToState(toFullName)
let currentState = states[fullState]
console.log(currentState.lat)
const mymap = L.map('mapid').setView([currentState.lat, currentState.long], 5.5);
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox/streets-v11',
tileSize: 512,
zoomOffset: -1,
accessToken: 'pk.eyJ1IjoiYWNub3dsYW5kIiwiYSI6ImNrbTJqaGhsZTBoYjcycGp2ZHoxNWlibncifQ.lAf9JwvZdGux5Cg6T_EFRg'
}).addTo(mymap);
if(state.hospitalizedCurrently > 3000){
var circle = L.circle([currentState.lat, currentState.long], {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.3,
radius: 150000
}).addTo(mymap);
}else if(state.hospitalizedCurrently < 3000 && state.hospitalizedCurrently > 1000){
var circle = L.circle([currentState.lat, currentState.long], {
color: 'yellow',
fillColor: '#FFFFE0',
fillOpacity: 0.5,
radius: 100000
}).addTo(mymap);
}else{
var circle = L.circle([currentState.lat, currentState.long], {
color: 'green',
fillColor: '##00ff00',
fillOpacity: 0.2,
radius: 80000
}).addTo(mymap);
}
circle.bindPopup(`The current number of currently hospitalized is ${state.hospitalizedCurrently}. \r
Compared to yesterday, there has been ${state.positiveIncrease} new cases.`);
})
})
function abbrToState(abbr){
var states = [
['Alabama', 'AL'],
['Alaska', 'AK'],
['American Samoa', 'AS'],
['Arizona', 'AZ'],
['Arkansas', 'AR'],
['Armed Forces Americas', 'AA'],
['Armed Forces Europe', 'AE'],
['Armed Forces Pacific', 'AP'],
['California', 'CA'],
['Colorado', 'CO'],
['Connecticut', 'CT'],
['Delaware', 'DE'],
['District Of Columbia', 'DC'],
['Florida', 'FL'],
['Georgia', 'GA'],
['Guam', 'GU'],
['Hawaii', 'HI'],
['Idaho', 'ID'],
['Illinois', 'IL'],
['Indiana', 'IN'],
['Iowa', 'IA'],
['Kansas', 'KS'],
['Kentucky', 'KY'],
['Louisiana', 'LA'],
['Maine', 'ME'],
['Marshall Islands', 'MH'],
['Mariana Islands', 'MP'],
['Maryland', 'MD'],
['Massachusetts', 'MA'],
['Michigan', 'MI'],
['Minnesota', 'MN'],
['Mississippi', 'MS'],
['Missouri', 'MO'],
['Montana', 'MT'],
['Nebraska', 'NE'],
['Nevada', 'NV'],
['New Hampshire', 'NH'],
['New Jersey', 'NJ'],
['New Mexico', 'NM'],
['New York', 'NY'],
['North Carolina', 'NC'],
['North Dakota', 'ND'],
['Northern Mariana Islands', 'NP'],
['Ohio', 'OH'],
['Oklahoma', 'OK'],
['Oregon', 'OR'],
['Pennsylvania', 'PA'],
['Puerto Rico', 'PR'],
['Rhode Island', 'RI'],
['South Carolina', 'SC'],
['South Dakota', 'SD'],
['Tennessee', 'TN'],
['Texas', 'TX'],
['US Virgin Islands', 'VI'],
['Utah', 'UT'],
['Vermont', 'VT'],
['Virginia', 'VA'],
['Washington', 'WA'],
['West Virginia', 'WV'],
['Wisconsin', 'WI'],
['Wyoming', 'WY']
];
abbr = abbr.toUpperCase();
for(var i = 0; i<states.length; i++){
if(states[i][1] == abbr){
return(states[i][0])
}
}
}