-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCityMarker.java
87 lines (71 loc) · 2.38 KB
/
CityMarker.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
package module6;
import de.fhpotsdam.unfolding.data.Feature;
import de.fhpotsdam.unfolding.data.PointFeature;
import de.fhpotsdam.unfolding.geo.Location;
import processing.core.PConstants;
import processing.core.PGraphics;
/** Implements a visual marker for cities on an earthquake map
*
* @author UC San Diego Intermediate Software Development MOOC team
*
*/
public class CityMarker extends CommonMarker {
public static int TRI_SIZE = 5; // The size of the triangle marker
public CityMarker(Location location) {
super(location);
}
public CityMarker(Feature city) {
super(((PointFeature)city).getLocation(), city.getProperties());
// Cities have properties: "name" (city name), "country" (country name)
// and "population" (population, in millions)
}
// pg is the graphics object on which you call the graphics
// methods. e.g. pg.fill(255, 0, 0) will set the color to red
// x and y are the center of the object to draw.
// They will be used to calculate the coordinates to pass
// into any shape drawing methods.
// e.g. pg.rect(x, y, 10, 10) will draw a 10x10 square
// whose upper left corner is at position x, y
/**
* Implementation of method to draw marker on the map.
*/
public void drawMarker(PGraphics pg, float x, float y) {
//System.out.println("Drawing a city");
// Save previous drawing style
pg.pushStyle();
// IMPLEMENT: drawing triangle for each city
pg.fill(250, 250, 250);
pg.noStroke();
pg.triangle(x, y-TRI_SIZE, x-TRI_SIZE, y+TRI_SIZE, x+TRI_SIZE, y+TRI_SIZE);
// Restore previous drawing style
pg.popStyle();
}
/** Show the title of the city if this marker is selected */
public void showTitle(PGraphics pg, float x, float y)
{
String name = getCity() + " " + getCountry() + " ";
String pop = "Pop: " + getPopulation() + " Million";
pg.pushStyle();
pg.fill(255, 255, 255);
pg.textSize(12);
pg.rectMode(PConstants.CORNER);
pg.rect(x, y-TRI_SIZE-39, Math.max(pg.textWidth(name), pg.textWidth(pop)) + 6, 39);
pg.fill(0, 0, 0);
pg.textAlign(PConstants.LEFT, PConstants.TOP);
pg.text(name, x+3, y-TRI_SIZE-33);
pg.text(pop, x+3, y - TRI_SIZE -18);
pg.popStyle();
}
private String getCity()
{
return getStringProperty("name");
}
private String getCountry()
{
return getStringProperty("country");
}
private float getPopulation()
{
return Float.parseFloat(getStringProperty("population"));
}
}