@Override protected SchedulePlot doInBackground(SchedulePlot... params) { // The params[0] element contains the schedulePlot object SchedulePlot scheduleToPlot = params[0]; // construct a list of geopoints for the schedule List<GeoPoint> geoPoints = new ArrayList<GeoPoint>(); // sections of given schedule SortedSet<Section> sectionsOfSchedule = scheduleToPlot.getSections(); // if the schedule has sections all at same location, or have 0 or 1 section, // then there is no route to be plotted if (sectionsOfSchedule.size() == 0 || sectionsOfSchedule.size() == 1) { scheduleToPlot.setRoute(null); } else { Iterator<Section> iterator = sectionsOfSchedule.iterator(); Section prev = iterator.next(); while (iterator.hasNext()) { Section next = iterator.next(); LatLon prevLatLon = prev.getBuilding().getLatLon(); LatLon nextLatLon = next.getBuilding().getLatLon(); geoPoints.addAll(getGeoPoints(getJSON(prevLatLon, nextLatLon))); prev = next; } // set the route of the schedule by setting the geopoints scheduleToPlot.setRoute(geoPoints); } // CPSC 210 Students: Complete this method. This method should // call the MapQuest webservice to retrieve a List<GeoPoint> // that forms the routing between the buildings on the // schedule. The List<GeoPoint> should be put into // scheduleToPlot object. return scheduleToPlot; }
/** * Plot all buildings referred to in the given information about plotting a schedule. * * @param schedulePlot All information about the schedule and route to plot. */ private void plotBuildings(SchedulePlot schedulePlot) { // CPSC 210 Students: Complete this method by plotting each building in the // schedulePlot with an appropriate message displayed if (schedulePlot.getSections().size() == 0) { AlertDialog aDialog = createSimpleDialog("Schedule To Plot Is Empty"); aDialog.show(); } else { for (Section s : schedulePlot.getSections()) { plotABuilding( s.getBuilding(), "Building: " + s.getBuilding().getName(), "Schedule for: " + schedulePlot.getName() + " " + s.getCourseInfo(), schedulePlot.getIcon()); } } // CPSC 210 Students: You will need to ensure the buildingOverlay is in // the overlayManager. The following code achieves this. You should not likely // need to touch it OverlayManager om = mapView.getOverlayManager(); om.add(buildingOverlay); }
@Override protected void onPostExecute(SchedulePlot schedulePlot) { // CPSC 210 Students: This method should plot the route onto the map // with the given line colour specified in schedulePlot. If there is // no route to plot, a dialog box should be displayed. // To actually make something show on the map, you can use overlays. // For instance, the following code should show a line on a map // PathOverlay po = createPathOverlay("#FFFFFF"); // po.addPoint(point1); // one end of line // po.addPoint(point2); // second end of line // scheduleOverlay.add(po); // OverlayManager om = mapView.getOverlayManager(); // om.addAll(scheduleOverlay); // mapView.invalidate(); // cause map to redraw PathOverlay po = createPathOverlay(schedulePlot.getColourOfLine()); // plot buildings of the schedule plotBuildings(schedulePlot); // if there is no route, display no route if (schedulePlot.getRoute() == null) { AlertDialog aDialog = createSimpleDialog("NO ROUTE TO PLOT"); aDialog.show(); // otherwise plot the route } else { // get the list of geopoints of the schedulePlot List<GeoPoint> points = schedulePlot.getRoute(); for (GeoPoint point : points) { po.addPoint(point); } scheduleOverlay.add(po); OverlayManager om = mapView.getOverlayManager(); om.addAll(scheduleOverlay); mapView.invalidate(); } }