// 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;
  }
  // prints countries with number of earthquakes
  // You will want to loop through the country markers or country features
  // (either will work) and then for each country, loop through
  // the quakes to count how many occurred in that country.
  // Recall that the country markers have a "name" property,
  // And LandQuakeMarkers have a "country" property set.
  private void printQuakes() {
    // TODO: Implement this method
    int countOceanQuakes = 0;
    int temp = countryMarkers.size();
    for (Marker countryMarker : countryMarkers) {
      int count = 0;

      String countryName;
      countryName = (String) countryMarker.getProperty("name");
      // System.out.println(countryMarker.getProperty("name"));
      for (Marker quakeMarker : quakeMarkers) {

        String quakeCountry;
        quakeCountry = quakeMarker.getStringProperty("country");
        if (quakeCountry == countryName) {

          count++;
        }
        if (quakeCountry == null) countOceanQuakes++;

        // System.out.println(quakeCountry);

        // System.out.println(quakeMarker.getStringProperty("country"));
        // System.out.println(quakeMarker.getProperties());

      }

      if (count > 0) {
        System.out.println(countryName + " number of times the quakes happened: " + count);
      }
    }
    System.out.println("number of ocean quakes: " + countOceanQuakes / temp);
  }
示例#3
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");
  }
 private void hideUnclickedMarkers(List<Marker> markers) {
   for (Marker marker : markers) {
     if (marker != lastClicked) {
       marker.setHidden(true);
     }
   }
 }
  private void showSelectMarkers() {
    // if lastClicked is a city marker, show only that city marker and
    // earthquake markers that affect that city
    if (cityMarkers.contains(lastClicked)) {
      hideUnclickedMarkers(cityMarkers);

      for (Marker marker : quakeMarkers) {
        EarthquakeMarker quakeMarker = (EarthquakeMarker) marker;
        double quakeDistanceToCity = quakeMarker.getDistanceTo(lastClicked.getLocation());
        double quakeDangerRadius = quakeMarker.threatCircle();
        if (quakeDistanceToCity > quakeDangerRadius) {
          marker.setHidden(true);
        }
      }

      // if lastClicked is an earthquake marker, show only that earthquake marker
      // and city markers that can be affected by that earthquake
    } else if (quakeMarkers.contains(lastClicked)) {
      hideUnclickedMarkers(quakeMarkers);

      EarthquakeMarker quakeMarker = (EarthquakeMarker) lastClicked;
      double quakeDangerRadius = quakeMarker.threatCircle();

      for (Marker marker : cityMarkers) {
        double quakeDistanceToCity = quakeMarker.getDistanceTo(marker.getLocation());
        if (quakeDistanceToCity > quakeDangerRadius) {
          marker.setHidden(true);
        }
      }
    }
  }
  // loop over and unhide all markers
  private void unhideMarkers() {
    for (Marker marker : quakeMarkers) {
      marker.setHidden(false);
    }

    for (Marker marker : cityMarkers) {
      marker.setHidden(false);
    }
  }
 private void selectMarkerIfClicked(List<Marker> markers) {
   for (Marker marker : markers) {
     if (marker.isInside(map, mouseX, mouseY)) {
       marker.setSelected(true);
       lastClicked = (CommonMarker) marker;
       break;
     }
   }
 }
 // If there was a marker underneath the mouse when it was clicked
 // it's clicked property is set to true
 // returns true if the marker was found underneath it
 private boolean clickMarkerIfClicked(List<Marker> markers, float x, float y) {
   for (Marker marker : markers) {
     if (marker.isInside(map, x, y)) {
       lastClicked = (CommonMarker) marker;
       lastClicked.setClicked(true);
       return true;
     }
   }
   return false;
 }
 // If there is a marker under the cursor, and lastSelected is null
 // set the lastSelected to be the first marker found under the cursor
 // Make sure you do not select two markers.
 //
 private void selectMarkerIfHover(List<Marker> markers) {
   // TODO: Implement this method
   for (Marker marker : markers) {
     if (marker.isInside(map, mouseX, mouseY)) {
       marker.setSelected(true);
       lastSelected = (CommonMarker) marker;
       break;
     }
   }
 }
 // If there is a marker under the cursor, and lastSelected is null
 // set the lastSelected to be the first marker found under the cursor
 // Make sure you do not select two markers.
 //
 private void selectMarkerIfHover(List<Marker> markers) {
   // Select the marker and call it's setSelected() method with first argument as true
   for (Marker marker : markers) {
     if (marker.isInside(map, mouseX, mouseY)) {
       lastSelected = (CommonMarker) marker;
       lastSelected.setSelected(true);
       break;
     }
   }
 }
示例#11
0
 private void cratersToShow() {
   for (Marker marker : craterMarkers) {
     java.util.HashMap<String, Object> properties = marker.getProperties();
     float diameter = Float.parseFloat(properties.get("diameter").toString());
     properties.put(
         "radius",
         ((diameter / 100) * map.getZoom())); // radius scaling is to match scales of the map
     if (Float.parseFloat(marker.getProperty("diameter").toString()) < requestedCraterSize)
       marker.setHidden(true);
     else marker.setHidden(false);
   }
 }
  // If there is a marker under the cursor, and lastSelected is null
  // set the lastSelected to be the first marker found under the cursor
  // Make sure you do not select two markers.
  //
  private void selectMarkerIfHover(List<Marker> markers) {
    // TODO: Implement this method
    if (lastSelected != null) return;

    for (Marker marker : markers) {
      if (marker.isInside(map, mouseX, mouseY)) {
        lastSelected = (CommonMarker) marker;
        lastSelected.setSelected(true);
        return;
      }
    }
  }
示例#13
0
 private void shadeCountries() {
   for (Marker marker : coutryMarkers) {
     String coutryId = marker.getId();
     if (lifeExpByCountry.containsKey(coutryId)) {
       float lifeExp = lifeExpByCountry.get(coutryId);
       // now encode values as brightness (values range between 40-90)
       int colorLevel = (int) map(lifeExp, 40, 90, 10, 255);
       marker.setColor(color(255 - colorLevel, 100, colorLevel));
     } else {
       marker.setColor(color(150, 150, 150));
     }
   }
 }
 private void shadeCountries() {
   for (Marker marker : countryMarkers) {
     // Find data for country of the current marker
     String countryId = marker.getId();
     if (lifeExpByCountry.containsKey(countryId)) {
       float lifeExp = lifeExpByCountry.get(countryId);
       int colorLevel = (int) map(lifeExp, 40, 90, 10, 255);
       marker.setColor(color(255 - colorLevel, 100, colorLevel));
     } else {
       marker.setColor(color(150, 150, 150));
     }
   }
 }
  @Test
  public void testCountryMarker() {
    addCountryMarker();

    Location berlinLocation = new Location(52.5f, 13.4f);
    Location pragueLocation = new Location(50.08f, 14.42f);

    for (Marker marker : map.getMarkers()) {
      if ("DEU".equals(marker.getId())) {

        AbstractShapeMarker shapeMarker = (AbstractShapeMarker) marker;

        assertTrue(shapeMarker.isInsideByLocation(berlinLocation));
        assertFalse(shapeMarker.isInsideByLocation(pragueLocation));
      }
    }
  }
  // Helper method that will check if an earthquake marker was clicked on
  // and respond appropriately
  private void checkEarthquakesForClick() {
    if (lastClicked != null) return;
    // Loop over the earthquake markers to see if one of them is selected
    for (Marker m : quakeMarkers) {
      EarthquakeMarker marker = (EarthquakeMarker) m;
      if (!marker.isHidden() && marker.isInside(map, mouseX, mouseY)) {
        lastClicked = marker;

        for (Marker mhide : quakeMarkers) if (mhide != lastClicked) mhide.setHidden(true);

        for (Marker mhide : cityMarkers)
          if (mhide.getDistanceTo(marker.getLocation()) > marker.threatCircle())
            mhide.setHidden(true);

        return;
      }
    }
  }
示例#17
0
 // prints countries with number of earthquakes
 // You will want to loop through the country markers or country features
 // (either will work) and then for each country, loop through
 // the quakes to count how many occurred in that country.
 // Recall that the country markers have a "name" property,
 // And LandQuakeMarkers have a "country" property set.
 private void printQuakes() {
   // TODO: Implement this method
   int total = 0;
   for (Marker country : countryMarkers) {
     int count = 0;
     for (Marker feature : quakeMarkers) {
       if (country.getProperty("name").equals(feature.getProperty("country"))) {
         count++;
       }
     }
     total = total + count;
     if (count >= 1) {
       System.out.println(country.getProperty("name") + ":" + count);
     }
   }
   System.out.println(
       "Number of quakes that were detected in the ocean: " + (quakeMarkers.size() - total));
 }
 // prints countries with number of earthquakes
 private void printQuakes() {
   int totalWaterQuakes = quakeMarkers.size();
   for (Marker country : countryMarkers) {
     String countryName = country.getStringProperty("name");
     int numQuakes = 0;
     for (Marker marker : quakeMarkers) {
       EarthquakeMarker eqMarker = (EarthquakeMarker) marker;
       if (eqMarker.isOnLand()) {
         if (countryName.equals(eqMarker.getStringProperty("country"))) {
           numQuakes++;
         }
       }
     }
     if (numQuakes > 0) {
       totalWaterQuakes -= numQuakes;
       System.out.println(countryName + ": " + numQuakes);
     }
   }
   System.out.println("OCEAN QUAKES: " + totalWaterQuakes);
 }
  // Helper method that will check if a city marker was clicked on
  // and respond appropriately
  private void checkCitiesForClick() {
    if (lastClicked != null) return;
    // Loop over the earthquake markers to see if one of them is selected
    for (Marker marker : cityMarkers) {
      if (!marker.isHidden() && marker.isInside(map, mouseX, mouseY)) {
        lastClicked = (CommonMarker) marker;
        // Hide all the other earthquakes and hide
        for (Marker mhide : cityMarkers) if (mhide != lastClicked) mhide.setHidden(true);

        for (Marker mhide : quakeMarkers) {
          EarthquakeMarker quakeMarker = (EarthquakeMarker) mhide;
          if (quakeMarker.getDistanceTo(marker.getLocation()) > quakeMarker.threatCircle())
            quakeMarker.setHidden(true);
        }
        return;
      }
    }
  }