【发布时间】:2015-10-25 20:37:58
【问题描述】:
我需要添加代码以在 RSS 提要中每次地震的位置显示一个标记,并通过修改方法(并根据需要添加新的辅助方法)使每个标记的半径为 10。然后我需要根据地震的大小添加代码来设置每个标记的样式。
我知道我应该为列表特征中的每个 PointFeature 创建一个 SimplePointMarker 对象,在 setUp 方法中使标记出现在屏幕上,所以它可能涉及每个循环,但除此之外我不是确定如何编码。
展开标记包说明...http://unfoldingmaps.org/javadoc/
public class EarthquakeCityMap extends PApplet {
// You can ignore this. It's to keep eclipse from generating a warning.
private static final long serialVersionUID = 1L;
// IF YOU ARE WORKING OFFLINE, change the value of this variable to true
private static final boolean offline = false;
// Less than this threshold is a light earthquake
public static final float THRESHOLD_MODERATE = 5;
// Less than this threshold is a minor earthquake
public static final float THRESHOLD_LIGHT = 4;
/** This is where to find the local tiles, for working without an Internet connection */
public static String mbTilesString = "blankLight-1-3.mbtiles";
// The map
private UnfoldingMap map;
//feed with magnitude 2.5+ Earthquakes
private String earthquakesURL = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.atom";
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);
// These print statements show you (1) all of the relevant properties
// in the features, and (2) how to get one property and use it
if (earthquakes.size() > 0) {
PointFeature f = earthquakes.get(0);
System.out.println(f.getProperties());
Object magObj = f.getProperty("magnitude");
float mag = Float.parseFloat(magObj.toString());
// PointFeatures also have a getLocation method
}
// 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 red = color(255, 0, 0);
int blue = color(0, 0, 255);
//TODO: Add code here as appropriate
}
// A suggested helper method that takes in an earthquake feature and
// returns a SimplePointMarker for that earthquake
// TODO: Implement this method and call it from setUp, if it helps
private SimplePointMarker createMarker(PointFeature feature)
{
//feature.setColor(color(150, 150, 150));
// finish implementing and use this method, if it helps.
return new SimplePointMarker(feature.getLocation());
//earthquakeMarkers = MapUtils.create
}
public void draw() {
background(10);
map.draw();
addKey();
}
// helper method to draw key in GUI
// TODO: Implement this method to draw the key
private void addKey()
{
// Remember you can use Processing's graphics methods here
fill(255, 250, 240); //color white
rect(25, 50, 150, 250); // (x location of upper left corner, y location of upper left corner, width, height)
fill(0); //needed for text to appear, sets the color to fill shapes, takes in an int rgb value
textAlign(LEFT, CENTER);
textSize(12);
text("Earthquake Key", 50, 75); //heading of key, takes (string, float x, and float y)
fill(color(255, 0, 0)); //red
ellipse(50, 125, 15, 15); //(x coordinate, y coordinate, width, height) )
fill(color(255, 255, 0)); //yellow
ellipse(50, 175, 10, 10);
fill(color(0, 0, 255));
ellipse(50, 225, 5, 5);
fill(0, 0, 0);
text("5.0+ Magnitude", 75, 125);
text("4.0+ Magnitude", 75, 175); // same y coordinate but different x so it could appear right beside marker
text("Below 4.0", 75, 225);
}
}
【问题讨论】: