public void setup() {
    // (1) Initializing canvas and map tiles
    size(900, 700, OPENGL);
    if (offline) {
      map = new UnfoldingMap(this, 200, 50, 650, 600, new MBTilesMapProvider(mbTilesString));
      earthquakesURL = "2.5_week.atom"; // The same feed, but saved August 7, 2015
    } else {
      map = new UnfoldingMap(this, 200, 50, 650, 600, new Google.GoogleMapProvider());
      // IF YOU WANT TO TEST WITH A LOCAL FILE, uncomment the next line
      // earthquakesURL = "2.5_week.atom";
    }
    MapUtils.createDefaultEventDispatcher(this, map);

    // FOR TESTING: Set earthquakesURL to be one of the testing files by uncommenting
    // one of the lines below.  This will work whether you are online or offline
    // earthquakesURL = "test1.atom";
    // earthquakesURL = "test2.atom";

    // Uncomment this line to take the quiz
    earthquakesURL = "quiz2.atom";

    // (2) Reading in earthquake data and geometric properties
    //     STEP 1: load country features and markers
    List<Feature> countries = GeoJSONReader.loadData(this, countryFile);
    countryMarkers = MapUtils.createSimpleMarkers(countries);

    //     STEP 2: read in city data
    List<Feature> cities = GeoJSONReader.loadData(this, cityFile);
    cityMarkers = new ArrayList<Marker>();
    for (Feature city : cities) {
      cityMarkers.add(new CityMarker(city));
    }

    //     STEP 3: read in earthquake RSS feed
    List<PointFeature> earthquakes = ParseFeed.parseEarthquake(this, earthquakesURL);
    quakeMarkers = new ArrayList<Marker>();

    for (PointFeature feature : earthquakes) {
      // check if LandQuake
      if (isLand(feature)) {
        quakeMarkers.add(new LandQuakeMarker(feature));
      }
      // OceanQuakes
      else {
        quakeMarkers.add(new OceanQuakeMarker(feature));
      }
    }

    // could be used for debugging
    printQuakes();

    // (3) Add markers to map
    //     NOTE: Country markers are not added to the map.  They are used
    //           for their geometric properties
    map.addMarkers(quakeMarkers);
    map.addMarkers(cityMarkers);

    sortAndPrint(20);
  } // End setup
Ejemplo n.º 2
0
  public void setup() {
    // (1) Initializing canvas and map tiles
    size(900, 700, OPENGL);
    if (offline) {
      map = new UnfoldingMap(this, 200, 50, 650, 600, new MBTilesMapProvider(mbTilesString));
      earthquakesURL = "2.5_week.atom"; // The same feed, but saved August 7, 2015
    } else {
      map = new UnfoldingMap(this, 200, 50, 650, 600, new Google.GoogleMapProvider());
      // IF YOU WANT TO TEST WITH A LOCAL FILE, uncomment the next line
      // earthquakesURL = "2.5_week.atom";
    }
    MapUtils.createDefaultEventDispatcher(this, map);

    // (2) Reading in earthquake data and geometric properties
    //     STEP 1: load country features and markers
    List<Feature> countries = GeoJSONReader.loadData(this, countryFile);
    countryMarkers = MapUtils.createSimpleMarkers(countries);

    //     STEP 2: read in city data
    List<Feature> cities = GeoJSONReader.loadData(this, cityFile);
    cityMarkers = new ArrayList<Marker>();
    for (Feature city : cities) {
      System.out.println(
          city.getProperty("name")
              + ", "
              + city.getProperty("country")
              + " Pop: "
              + city.getProperty("population")
              + "Million");
      cityMarkers.add(new CityMarker(city));
    }

    //     STEP 3: read in earthquake RSS feed
    List<PointFeature> earthquakes = ParseFeed.parseEarthquake(this, earthquakesURL);
    quakeMarkers = new ArrayList<Marker>();

    for (PointFeature feature : earthquakes) {
      // check if LandQuake
      if (isLand(feature)) {
        quakeMarkers.add(new LandQuakeMarker(feature));
      }
      // OceanQuakes
      else {
        quakeMarkers.add(new OceanQuakeMarker(feature));
      }
    }

    // could be used for debugging
    printQuakes();

    // (3) Add markers to map
    //     NOTE: Country markers are not added to the map.  They are used
    //           for their geometric properties
    map.addMarkers(quakeMarkers);
    map.addMarkers(cityMarkers);
  } // End setup
  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();
  }