Repository navigation
Expand file tree
/
Copy pathmap1.js
More file actions
executable file
·68 lines (58 loc) · 2.31 KB
/
Copy pathmap1.js
File metadata and controls
executable file
·68 lines (58 loc) · 2.31 KB
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
let geoDataURL = "../zcta.topo.json";
let covidDataURL = "../FakeZCTAData.csv";
let geoObj = {};
let covidObj = {};
let viewObj = {};
let countSpec = "map1.vl.json";
let rateSpec = "mapRate.vl.json";
let percentSpec = "mapPercent.vl.json";
let deathCountSpec = "mapDeathCount.vl.json";
let deathRateSpec = "mapDeathRate.vl.json";
let radios ;
const opt = {"renderer":"svg"};
const el = document.getElementById('map');
// this code listens to the form with map chooser; must run after DOM loads
window.onload =listenRadios;
function listenRadios() {
radios = document.querySelectorAll('input[type=radio][name="mapRadioGroup"]');
radios.forEach(radio => radio.addEventListener('change', () => {
if (radio.value==='Case Rate') {rateMapCreate()}
else if (radio.value==='Case Count') {countMapCreate()}
else if (radio.value==='Death Count') {deathCountMapCreate()}
else if (radio.value==='Death Rate') {deathRateMapCreate()}
else {percentMapCreate()} // for if chosenField is Percent Positive
;
}));
}
//this function creates the map
function rateMapCreate() {
vegaEmbed('#map', rateSpec, opt).then(function(result) {
// Access the Vega view instance (https://vega.github.io/vega/docs/api/view/) as result.view
viewObj = result.view;
}).catch(console.error);
}
function countMapCreate() {
vegaEmbed('#map', countSpec, opt).then(function(result) {
// Access the Vega view instance (https://vega.github.io/vega/docs/api/view/) as result.view
viewObj = result.view;
}).catch(console.error);
}
function deathCountMapCreate() {
vegaEmbed('#map', deathCountSpec, opt).then(function(result) {
// Access the Vega view instance (https://vega.github.io/vega/docs/api/view/) as result.view
viewObj = result.view;
}).catch(console.error);
}
function deathRateMapCreate() {
vegaEmbed('#map', deathRateSpec, opt).then(function(result) {
// Access the Vega view instance (https://vega.github.io/vega/docs/api/view/) as result.view
viewObj = result.view;
}).catch(console.error);
}
function percentMapCreate() {
vegaEmbed('#map', percentSpec, opt).then(function(result) {
// Access the Vega view instance (https://vega.github.io/vega/docs/api/view/) as result.view
viewObj = result.view;
}).catch(console.error);
}
rateMapCreate();