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 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); } }
private void hideUnclickedMarkers(List<Marker> markers) { for (Marker marker : markers) { if (marker != lastClicked) { marker.setHidden(true); } } }
// 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; } } }
// 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; } } }