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);
        }
      }
    }
  }
 // 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) {
   // 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;
     }
   }
 }
 /** Event handler that gets called automatically when the mouse moves. */
 @Override
 public void mouseMoved() {
   // clear the last selection
   if (lastSelected != null) {
     lastSelected.setSelected(false);
     lastSelected = null;
   }
   selectMarkerIfHover(quakeMarkers);
   selectMarkerIfHover(cityMarkers);
 }
  // 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;
      }
    }
  }
 /**
  * The event handler for mouse clicks It will display an earthquake and its threat circle of
  * cities Or if a city is clicked, it will display all the earthquakes where the city is in the
  * threat circle
  */
 @Override
 public void mouseClicked() {
   // TODO: Implement this method
   // Hint: You probably want a helper method or two to keep this code
   // from getting too long/disorganized
   if (lastClicked != null) {
     unhideMarkers();
     lastClicked.setSelected(false);
     lastClicked = null;
   } else {
     selectMarkerIfClicked(quakeMarkers);
     selectMarkerIfClicked(cityMarkers);
     if (lastClicked != null) {
       showSelectMarkers();
     }
   }
 }
  /**
   * The event handler for mouse clicks It will display an earthquake and its threat circle of
   * cities Or if a city is clicked, it will display all the earthquakes where the city is in the
   * threat circle
   */
  @Override
  public void mouseClicked() {
    // Hint: You probably want a helper method or two to keep this code
    // from getting too long/disorganized

    // instantly saving the x and y coordinates of the click
    float x = mouseX;
    float y = mouseY;

    // lastClicked tells us if it was clicked before
    if (lastClicked != null) {
      lastClicked.setClicked(false);
      lastClicked = null;
      unhideMarkers();
    }

    if (clickMarkerIfClicked(quakeMarkers, x, y) || clickMarkerIfClicked(cityMarkers, x, y)) {
      hideSafeMarkers();
    }
  }
 private void hideSafeMarkers() {
   lastClicked.showThreat(quakeMarkers, cityMarkers);
 }