- 자바 애플릿(Java Applet)으로 지진 강도 시각화하기
1. RSS 피드로 받은 각 지진 위치 마커로 표시하는 코드 추가
- EarthquakeCityMap.java
public void setup() {
size(950, 600, OPENGL);
if (offline) {
map = new UnfoldingMap(this, 200, 50, 700, 500, new MBTilesMapProvider(mbTilesString));
earthquakesURL = "2.5_week.atom"; // Same feed, saved Aug 7, 2015, for working offline
}
else {
map = new UnfoldingMap(this, 200, 50, 700, 500, new Google.GoogleMapProvider());
// IF YOU WANT TO TEST WITH A LOCAL FILE, uncomment the next line
//earthquakesURL = "2.5_week.atom";
}
map.zoomToLevel(2);
MapUtils.createDefaultEventDispatcher(this, map);
// The List you will populate with new SimplePointMarkers
List<Marker> markers = new ArrayList<Marker>();
//Use provided parser to collect properties for each earthquake
//PointFeatures have a getLocation method
List<PointFeature> earthquakes = ParseFeed.parseEarthquake(this, earthquakesURL);
//TODO (Step 3): Add a loop here that calls createMarker (see below)
// to create a new SimplePointMarker for each PointFeature in
// earthquakes. Then add each new SimplePointMarker to the
// List markers (so that it will be added to the map in the line below)
for(PointFeature eq : earthquakes) {
markers.add(createMarker(eq));
}
// Add the markers to the map so that they are displayed
map.addMarkers(markers);
}
2. 지진 규모에 따라 각 마커의 스타일을 지정하는 코드 추가
- 소규모 지진(규모 4.0 미만)은 파란색 마커로 표시되며 규모가 작습니다.
- 가벼운 지진(4.0~4.9 사이)은 노란색 표시가 있고 크기는 중간입니다.
- 보통 및 높은 규모의 지진(5.0 이상)은 빨간색 마커로 표시되며 규모가 가장 큽니다.
- EarthquakeCityMap.java
private SimplePointMarker createMarker(PointFeature feature) {
// Create a new SimplePointMarker at the location given by the PointFeature
SimplePointMarker marker = new SimplePointMarker(feature.getLocation());
Object magObj = feature.getProperty("magnitude");
float mag = Float.parseFloat(magObj.toString());
// Here is an example of how to use Processing's color method to generate
// an int that represents the color yellow.
int yellow = color(255, 255, 0);
int blue = color(0, 0, 255);
int red = color(255, 0, 0);
// TODO (Step 4): Add code below to style the marker's size and color
// according to the magnitude of the earthquake.
// Don't forget about the constants THRESHOLD_MODERATE and
// THRESHOLD_LIGHT, which are declared above.
// Rather than comparing the magnitude to a number directly, compare
// the magnitude to these variables (and change their value in the code
// above if you want to change what you mean by "moderate" and "light")
if(mag < THRESHOLD_LIGHT) {
marker.setColor(blue); // Minor earthquakes (less than magnitude 4.0)
marker.setRadius(5);
}
else if(mag >= THRESHOLD_MODERATE) {
marker.setColor(red); // Moderate and higher earthquakes (5.0 and over)
marker.setRadius(20);
}
else {
marker.setColor(yellow); // Light earthquakes (between 4.0-4.9)
}
// Finally return the marker
return marker;
}
3. 지진 강도 설명하는 키를 그리고 지도 왼쪽에 표시
- EarthquakeCityMap.java
private void addKey() {
// Remember you can use Processing's graphics methods here
// white rectangle
fill(color(255, 255, 255));
rect(25, 50, 150, 250);
// red circle
fill(color(255, 0, 0));
ellipse(50, 117, 20, 20);
// yellow circle
fill(color(255, 255, 0));
ellipse(50, 157, 10, 10);
// blue circle
fill(color(0, 0, 255));
ellipse(50, 197, 5, 5);
// text
fill(color(0, 0, 0));
text("Earthquake Key", 45, 80);
text("5.0+ Magnitude", 70, 120);
text("4.0+ Magnitude", 70, 160);
text("Below 4.0", 70, 200);
}