// 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(); } } }