-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·145 lines (128 loc) · 7.03 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
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
// Called only once, the first time the map is loaded
const main = async() => {
startLoadingIcon(1);
idleLoadingIcon(); // shows that the map is loading
collectSettings(); // collects inital settings
loadConceptData("P1"); // loads in data regarding total population (P1)
loadFlagData(); // load in flag urls compiled from CRW flags
loadFullVariableList(); // get list of Census variable names
addSources(); // add Mapbox source
addFillLineExtrusionLayers(); // add Mapbox layers
loadAlmanacData('10');
loadAlmanacData('20');
addNativeLandsLayer();
takeTour(0);
}
// Called (just about) every time the map is changed in any way
// This is the main workhorse of the entire project
const update = async() => {
let geo = SETTINGS["Geo"];
if (!map.getLayer(`${geo}-fills`)) return
startLoadingIcon(1);
collectSettings(); // collects inital settings
updateGeo(); // updates geography size (state, county, zip code, etc.)
updateVariable(); // updates variable (data category) within the current concept
updatePaint(); // updates layer paint (colors, opacity, etc.)
updateFlagMode(); // updates if flag is mode is activated
legendSetup();
distributeSettings();
endLoadingIcon(2); // ends secondary loading icon when map is ready
endLoadingIcon(1);
}
// Updates the layer paint on the visible map layer
// This includes, color, opacity, lines, extrusions, and visibility (different than opacity!)
const updatePaint = async() => {
if (!SETTINGS["Variable"]) return
startLoadingIcon(1);
let colors = COLOR_DICT[SETTINGS['Scheme']]; // returns array of 5 colors according to color scheme
colors = getCustomColors(colors); // replace colors with custom ones if selected by user
let scale = SETTINGS['Scale'];
if (scale == "Linear") fiveStep = colorLinear(); // returns the five-step sequence needed to paint each layer
if (scale == "Quartile") fiveStep = colorQuartile();
if (scale == "Log") fiveStep = colorLog();
// if (QSummary[1000] > QSummary[250]*200) {
// console.log("sparse");
// fiveStep = colorLog();
// }
let fiveStep_values = Object.values(fiveStep).sort((a, b) => a - b); // get values as an array, and sort
fiveStep_values = fiveStepAdjustment(fiveStep_values); // ensure the values are in strictly increasing order
updateLegend(fiveStep_values, colors); // update legend to show proper values and colors
setLinePaint(); // set Mapbox paint with data-driven styling
setFillPaint(fiveStep_values, colors); // set Mapbox paint with data-driven styling
setExtrusionPaint(fiveStep_values, colors); // set Mapbox paint with data-driven styling
setLayerVisibility();
endLoadingIcon(1); // ensure proper layer visibility
}
// Updates the visible geography size
// Currently the availble geographies are: nation, state, county, csub (county subdivision), place, census tract, census group,
// metro/micro statistical areas, urban areas, zip codes, and unified school districts
let hoversCreated = []; // used to identift id the geography has previously been loaded in
const updateGeo = async() => {
startLoadingIcon(1);
hideAllLayers(); // hides all layers, as only one can be seen at a time
clearAllHolds(); // remove any held areas, thus holding a state is not equal to holding all counties in that state
let geo = SETTINGS['Geo'];
showCurrentLayer(); // ensures the current desired layer is visible
if (!hoversCreated.includes(geo)){ // if geography has not previously been loaded in
setupHoverHoldStates(geo); // then setup hover and hold feature states
hoversCreated.push(geo);
}
filterReset()
endLoadingIcon(1);
}
// Updates the selected variable (data category)
// The name variable is confusing (since everything is called a variable) but basically a variable is a single data category
// Variables collected by Census include counts of Black population, under 18s, those living in multi-generational households
// Each of these individually is a variable. In all, the Census tabulates something like 8000 variables
const updateVariable = async() => {
if (!SETTINGS["Variable"]) return
startLoadingIcon(1);
setFeatStates() // set the feature state for variable. feature states for each variable are set seperately to minimize time/space limits
getQuartileValues() // calculte the quartile values (QSummary) for the new variable,
createLandAlmanac()
endLoadingIcon(1);
}
// Updates the selected concept
// The concept is a grouping of variables around a specific idea. some examples of concepts are race, age, urbanity, etc.
// When updating the conecpt, we must also update the list of variables within that concept
const updateConcept = async() => {
startLoadingIcon(2);
let concept = SETTINGS['Concept']
if (!(concept in LORAX)) await loadConceptData(concept) // if concept has not previously been loaded, then retrieve it
await loadVariablesByConcept(concept) // get list of variables that pertain to each concept
await createVariableDropdownSelect(VAR_NAMES_BY_CONCEPT[concept]) // set new list of variables as dropdown menu option for user to select
update()
}
const updateRealm = async() => {
startLoadingIcon(1);
let realm = $('#realm-select-').val()
let op = await getRealmOptions(realm)
let st = getRealmSelectString(op)
setRealmSelect(st)
clearVariableSelect()
endLoadingIcon(1);
}
////==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==
///==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==
//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==//==
const accumulateShortcut = () => {
let test = $('#accumulate').is(":checked");
$('#accumulate').prop('checked', !test);
collectSettings();
clearAllHolds()
}
const nativelandStart = () => {
hideAllLayers();
setNativeLandPaint();
$('#drag-1').css('left', `-1000px`);
}
const nativelandEnd = () => {
hideAllLayers();
setLayerVisibility();
$('#drag-1').css('left', `500px`);
}
LORAX = {}
ALMANAC = {};
let mouse_pos = {x:0, y:0}
let bboxSize = 10;
let default_token = `{"Year":"10", "Geo":"state", "Realm":"Total", "Concept":"P1", "Variable":"P001001", "3D":false, "Height":"100010", "Scheme":"Viridis", "Scale":"Linear", "TileOpacity":0.5, "NumFormat":"comma", "Accumulate":false, "FlagMode":false, "WikiMode":false, "Center":{"lng":-104.8, "lat":38.85}, "Zoom":3.6, "Pitch":0, "Bearing":0}`;