Пример #1
0
  /**
   * Add an item overlay
   *
   * @param overlay
   */
  public void addOverlay(OverlayItem overlay) {
    Drawable d = overlay.getMarker(0);

    if (d != null) {
      overlay.setMarker(boundCenterBottom(d));
    }

    mOverlays.add(overlay);
    populate(); // Called to prepare each item to be drawn
  }
 public void paintTasks() {
   allOverlays = mapView.getOverlays();
   allOverlays.remove(tasksPositionOverlay);
   tasksPositionOverlay = new TasksOverlay(doneMarker, this);
   tasksCursor = global_app.getDataStorage().getAllTasks();
   DecimalFormat km = new DecimalFormat();
   km.setMaximumFractionDigits(2);
   DecimalFormat m = new DecimalFormat();
   m.setMaximumFractionDigits(1);
   while (tasksCursor.moveToNext()) {
     double lat = tasksCursor.getDouble(tasksCursor.getColumnIndex(DataStorage.C_LAT));
     double lon = tasksCursor.getDouble(tasksCursor.getColumnIndex(DataStorage.C_LON));
     String taskTitle = (tasksCursor.getString(tasksCursor.getColumnIndex(DataStorage.C_NAME)));
     int taskState = (tasksCursor.getInt(tasksCursor.getColumnIndex(DataStorage.C_STATE)));
     int taskId = (tasksCursor.getInt(tasksCursor.getColumnIndex(DataStorage.C_ID)));
     GeoPoint taskLocation = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));
     Location tmp = new Location(provider);
     tmp.setLatitude(lat);
     tmp.setLongitude(lon);
     double distance = lastLocation.distanceTo(tmp);
     String prettyDistance;
     if (distance > 1000) prettyDistance = km.format(distance / 1000) + "km";
     else prettyDistance = m.format(distance) + "m";
     OverlayItem taskOverlayItem =
         new OverlayItem(
             taskLocation,
             taskTitle + " (id: " + Integer.toString(taskId) + ")",
             "oddalone o: " + prettyDistance);
     Drawable marker;
     switch (taskState) {
       case 0:
         marker = cancelMarker;
         break;
       case 1:
         marker = pendingMarker;
         break;
       case 2:
         marker = currentMarker;
         break;
       default:
         marker = doneMarker;
         break;
     }
     int w = marker.getIntrinsicWidth();
     int h = marker.getIntrinsicHeight();
     marker.setBounds(-w / 2, -h, w / 2, 0);
     taskOverlayItem.setMarker(marker);
     tasksPositionOverlay.addOverlay(taskOverlayItem);
   }
   allOverlays.add(tasksPositionOverlay);
   mapView.invalidate();
   tasksCursor.close();
 }
 /**
  * Constructor for the fountain overlay
  *
  * @param f Fountain information associated with overlay
  * @param marker Drawable to be rendered
  */
 public FountainOverlayItem(Fountain f, Drawable marker) {
   // Overlay position is the fountain's coordinates
   super(f.getCoordinates(), "", "");
   super.setMarker(marker);
   this.fountain = f;
 }