-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLifeExpect.java
More file actions
51 lines (49 loc) · 1.58 KB
/
LifeExpect.java
File metadata and controls
51 lines (49 loc) · 1.58 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
package LifeExpectency;
import java.util.*;
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.data.Feature;
import de.fhpotsdam.unfolding.data.GeoJSONReader;
import de.fhpotsdam.unfolding.marker.Marker;
import de.fhpotsdam.unfolding.providers.Google;
import de.fhpotsdam.unfolding.utils.MapUtils;
import parsing.ParseFeed;
import processing.core.*;
public class LifeExpect extends PApplet{
UnfoldingMap map;
private Map<String,Float> lifeExpMap;
private List<Feature> countries;
private List<Marker> countryMarkers;
public void setup() {
//setting up the applet
size(800,600,OPENGL);
//creating a map from google
map = new UnfoldingMap(this,50,50,700,500,new Google.GoogleMapProvider());
MapUtils.createDefaultEventDispatcher(this, map);
lifeExpMap = ParseFeed.loadLifeExpectancyFromCSV(this,"LifeExpectancyWorldBank.csv");
//
countries = GeoJSONReader.loadData(this, "countries.geo.json");
//
countryMarkers = MapUtils.createSimpleMarkers(countries);
//
map.addMarkers(countryMarkers);
//
shadeCountries();
//This provide the user to manupilate the map like zooming, pinching, locating etc
}
//this method is runs in a loop
public void draw() {
map.draw();
}
private void shadeCountries() {
for(Marker marker : countryMarkers) {
String countryId = marker.getId();
if(lifeExpMap.containsKey(countryId)) {
float lifeExp = this.lifeExpMap.get(countryId);
int colorLevel = (int) map(lifeExp,40,90,20,255);
marker.setColor(color(255-colorLevel,100,colorLevel));
}else {
marker.setColor(color(150,150,150));
}
}
}
}