コード例 #1
0
  // helper method to test whether a given earthquake is in a given country
  // This will also add the country property to the properties of the earthquake feature if
  // it's in one of the countries.
  // You should not have to modify this code
  private boolean isInCountry(PointFeature earthquake, Marker country) {
    // getting location of feature
    Location checkLoc = earthquake.getLocation();

    // some countries represented it as MultiMarker
    // looping over SimplePolygonMarkers which make them up to use isInsideByLoc
    if (country.getClass() == MultiMarker.class) {

      // looping over markers making up MultiMarker
      for (Marker marker : ((MultiMarker) country).getMarkers()) {

        // checking if inside
        if (((AbstractShapeMarker) marker).isInsideByLocation(checkLoc)) {
          earthquake.addProperty("country", country.getProperty("name"));

          // return if is inside one
          return true;
        }
      }
    }

    // check if inside country represented by SimplePolygonMarker
    else if (((AbstractShapeMarker) country).isInsideByLocation(checkLoc)) {
      earthquake.addProperty("country", country.getProperty("name"));

      return true;
    }
    return false;
  }
コード例 #2
0
  private void isOnEarthLand(PointFeature crater) {
    for (Marker country : countryMarkers) {
      Location checkLoc = crater.getLocation();

      // some countries represented it as MultiMarker
      // looping over SimplePolygonMarkers which make them up to use isInsideByLoc
      if (country.getClass() == MultiMarker.class) {
        // looping over markers making up MultiMarker
        for (Marker marker : ((MultiMarker) country).getMarkers()) {
          // checking if inside
          if (((AbstractShapeMarker) marker).isInsideByLocation(checkLoc)) {
            crater.addProperty("isOnEarthLand", "true");
            return;
          }
        }
      }
      // check if inside country represented by SimplePolygonMarker
      else if (((AbstractShapeMarker) country).isInsideByLocation(checkLoc)) {
        crater.addProperty("isOnEarthLand", "true");
        return;
      }
    }
    // not inside any country
    crater.addProperty("isOnEarthLand", "false");
  }
コード例 #3
0
 // constructor
 public EarthquakeMarker(PointFeature feature) {
   super(feature.getLocation());
   // Add a radius property and then set the properties
   java.util.HashMap<String, Object> properties = feature.getProperties();
   float magnitude = Float.parseFloat(properties.get("magnitude").toString());
   properties.put("radius", 2 * magnitude);
   setProperties(properties);
   this.radius = 1.75f * getMagnitude();
 }
コード例 #4
0
  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 we looped through each PointFeature in earthquakes
      for (PointFeature pf : earthquakes) {

        // we created a new simplePointMarker for each earthquake
        SimplePointMarker spm = createMarker(pf);

        // we added that simplepointmarker to the marker list
        markers.add(spm);
      }
    }

    // added the markers to the map
    map.addMarkers(markers);
    // 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);

    // Done: Add code here as appropriate
    addKey();
  }
コード例 #5
0
  // A suggested helper method that takes in an earthquake feature and
  // returns a SimplePointMarker for that earthquake
  // Done: Implement this method and call it from setUp, if it helps
  private SimplePointMarker createMarker(PointFeature feature) {
    // finish implementing and use this method, if it helps.
    SimplePointMarker spm = new SimplePointMarker(feature.getLocation());

    Object magnitudeProp = feature.getProperty("magnitude");

    float magnitude = Float.parseFloat(magnitudeProp.toString());

    if (magnitude < 4.0) {
      spm.setColor(color(0, 0, 255));
      spm.setRadius(5);
    } else if (magnitude >= 4.0 && magnitude < 5) {
      spm.setColor(color(255, 255, 0));
      spm.setRadius(10);
    } else {
      spm.setColor(color(255, 0, 0));
      spm.setRadius(15);
    }
    return spm;
  }