-
Notifications
You must be signed in to change notification settings - Fork 0
/
AirportMap.java
96 lines (68 loc) · 2.73 KB
/
AirportMap.java
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
package EarthQuakeMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.data.PointFeature;
import de.fhpotsdam.unfolding.data.ShapeFeature;
import de.fhpotsdam.unfolding.marker.Marker;
import de.fhpotsdam.unfolding.marker.SimpleLinesMarker;
import de.fhpotsdam.unfolding.marker.SimplePointMarker;
import de.fhpotsdam.unfolding.utils.MapUtils;
import de.fhpotsdam.unfolding.geo.Location;
import parsing.ParseFeed;
import processing.core.PApplet;
/** An applet that shows airports (and routes) on a world map.
* An application with an interactive map displaying earthquake data.
* With help of UC San Diego Intermediate Software Development MOOC team
* @author Tarit Goswami
*/
public class AirportMap extends PApplet {
UnfoldingMap map;
private List<Marker> airportList;
List<Marker> routeList;
public void setup() {
// setting up PAppler
size(800,600, OPENGL);
// setting up map and default events
map = new UnfoldingMap(this, 50, 50, 750, 550);
MapUtils.createDefaultEventDispatcher(this, map);
// get features from airport data
List<PointFeature> features = ParseFeed.parseAirports(this, "airports.dat");
// list for markers, hashmap for quicker access when matching with routes
airportList = new ArrayList<Marker>();
HashMap<Integer, Location> airports = new HashMap<Integer, Location>();
// create markers from features
for(PointFeature feature : features) {
AirportMarker m = new AirportMarker(feature);
m.setRadius(5);
airportList.add(m);
// put airport in hashmap with OpenFlights unique id for key
airports.put(Integer.parseInt(feature.getId()), feature.getLocation());
}
// parse route data
List<ShapeFeature> routes = ParseFeed.parseRoutes(this, "routes.dat");
routeList = new ArrayList<Marker>();
for(ShapeFeature route : routes) {
// get source and destination airportIds
int source = Integer.parseInt((String)route.getProperty("source"));
int dest = Integer.parseInt((String)route.getProperty("destination"));
// get locations for airports on route
if(airports.containsKey(source) && airports.containsKey(dest)) {
route.addLocation(airports.get(source));
route.addLocation(airports.get(dest));
}
SimpleLinesMarker sl = new SimpleLinesMarker(route.getLocations(), route.getProperties());
System.out.println(sl.getProperties());
//UNCOMMENT IF YOU WANT TO SEE ALL ROUTES
//routeList.add(sl);
}
//UNCOMMENT IF YOU WANT TO SEE ALL ROUTES
//map.addMarkers(routeList);
map.addMarkers(airportList);
}
public void draw() {
background(0);
map.draw();
}
}