-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.pde
More file actions
140 lines (105 loc) · 3.25 KB
/
Copy pathMap.pde
File metadata and controls
140 lines (105 loc) · 3.25 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
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
import java.awt.Polygon;
public class Map{
private ArrayList<State> stateList = new ArrayList<State>(50);
// not exactly x and y
XML xml;
public Map(){
xml = loadXML("statesCoord.xml");
JSONArray stateData = loadJSONArray("map.json");
XML[] state = xml.getChildren("state");
int relX = 1550;
int relY = 900;
int scaleX = 12;
int scaleY = -15;
//make Hawaii
makeState(state, stateData, 0, 2260, 750, 13, -13);
//make Alaska
makeState(state, stateData, 1, 700, 850, 4, -6);
for(int i=2; i<state.length; i++){ //draw Hawaii and Alaska separately
makeState(state, stateData, i, relX, relY, scaleX, scaleY);
}
for (State st: stateList){
st.draw();
}
}
public void makeState(XML[] state, JSONArray stateData, int i, int relX, int relY, int scaleX, int scaleY){
XML[] point = state[i].getChildren("point");
int pointCount = point.length;
int centerX = relX+int(scaleX* state[i].getFloat("lng"));
int centerY = relY+int(scaleY* state[i].getFloat("lat"));
int[] x = new int[pointCount];
int[] y = new int[pointCount];
for(int j=0; j<pointCount; j++){
x[j]= relX+int(scaleX* point[j].getFloat("lng"));
y[j]= relY+int(scaleY* point[j].getFloat("lat"));
}
Poly shape = new Poly(x,y,pointCount);
JSONObject jsonState = stateData.getJSONObject(i);
int alone = jsonState.getInt("alone");
int carpool = jsonState.getInt("carpool");
int publicTrans = jsonState.getInt("public");
int walk = jsonState.getInt("walk");
int other = jsonState.getInt("other");
int home = jsonState.getInt("home");
String name = jsonState.getString("name");
int workers = alone+carpool+publicTrans+walk+other+home;
float travel = 0.0;
State aState = new State(name, state[i].getString("abb"),
shape, centerX, centerY, workers, alone, carpool, publicTrans, walk, other, home, travel);
stateList.add(aState);
}
public void brush(State state){
for (State aState: stateList){
aState.setBrushing(false);
}
int index = stateList.indexOf(state);
if (index!=-1){
State myState = stateList.get(index);
myState.setBrushing(true);
}
}
// --- What Parameter is being looked at ----
public void setView(){
}
public void reset(){
for(State st: stateList){
st.setHighlight(false);
}
}
public void mouseMoved(){
reset();
for(State st: stateList){
if (st.contains(mouseX, mouseY)){
break;
}
}
drawMap();
}
public void mousePressed(){
for(State st: stateList){
if (st.highlight){
draw.setWindowState(st);
//return st;
}
}
// return null;
}
public void drawMap(){
/* fill(background);
noStroke();
rect(0,0, mapWidth, 600);*/
State selected = null;
for (State st: stateList){
State oneState = st.draw();
if (oneState!=null){
selected = oneState;
}
}
/* if (selected!=null){
selected.dataBox();
}*/
}
public ArrayList<State> getStateList(){
return stateList;
}
}