@Override
  public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) {
    super.draw(canvas, mapView, shadow);

    // go through all OverlayItems and draw title for each of them
    for (OverlayItem item : mOverlays) {
      /* Converts latitude & longitude of this overlay item to coordinates on screen.
       * As we have called boundCenterBottom() in constructor, so these coordinates
       * will be of the bottom center position of the displayed marker.
       */
      GeoPoint point = item.getPoint();
      Point markerBottomCenterCoords = new Point();
      mapView.getProjection().toPixels(point, markerBottomCenterCoords);

      /* Find the width and height of the title*/
      TextPaint paintText = new TextPaint();
      Paint paintRect = new Paint();

      Rect rect = new Rect();
      paintText.setTextSize(FONT_SIZE);
      paintText.getTextBounds(item.getTitle(), 0, item.getTitle().length(), rect);

      rect.inset(-TITLE_MARGIN, -TITLE_MARGIN);
      rect.offsetTo(
          markerBottomCenterCoords.x - rect.width() / 2,
          markerBottomCenterCoords.y - markerHeight - rect.height());

      paintText.setTextAlign(Paint.Align.CENTER);
      paintText.setTextSize(FONT_SIZE);
      paintText.setARGB(255, 255, 255, 255);
      paintRect.setARGB(130, 0, 0, 0);

      canvas.drawRoundRect(new RectF(rect), 2, 2, paintRect);
      canvas.drawText(
          item.getTitle(), rect.left + rect.width() / 2, rect.bottom - TITLE_MARGIN, paintText);
    }
  }
Exemple #2
0
  @Override
  public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) {
    super.draw(canvas, mapView, shadow);

    Paint mPaint = new Paint();
    mPaint.setDither(true);
    mPaint.setColor(Color.RED);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(2);

    List<Clue> clues = huntedService.getDataProvider().getTrackLog();

    Clue prevClue = null;
    for (Clue clue : clues) {
      if (prevClue != null) {
        GeoPoint prevCluePoint = Map.getPointForClue(prevClue);
        GeoPoint currentCluePoint = Map.getPointForClue(clue);
        Point fromPoint = new Point();
        mapView.getProjection().toPixels(prevCluePoint, fromPoint);
        Point toPoint = new Point();
        mapView.getProjection().toPixels(currentCluePoint, toPoint);
        canvas.drawLine(fromPoint.x, fromPoint.y, toPoint.x, toPoint.y, mPaint);
      }

      prevClue = clue;
    }

    // go through all OverlayItems and draw title for each of them
    List<OverlayItem> overlaysCopy = new ArrayList<OverlayItem>(overlays);
    for (OverlayItem item : overlaysCopy) {
      /* Converts latitude & longitude of this overlay item to coordinates on screen.
       * As we have called boundCenterBottom() in constructor, so these coordinates
       * will be of the bottom center position of the displayed marker.
       */
      GeoPoint point = item.getPoint();
      Point markerBottomCenterCoords = new Point();
      mapView.getProjection().toPixels(point, markerBottomCenterCoords);

      /* Find the width and height of the title*/
      TextPaint paintText = new TextPaint();
      Paint paintRect = new Paint();

      Rect rect = new Rect();
      paintText.setTextSize(FONT_SIZE);
      paintText.getTextBounds(item.getTitle(), 0, item.getTitle().length(), rect);

      rect.inset(-TITLE_MARGIN, -TITLE_MARGIN);
      rect.offsetTo(
          markerBottomCenterCoords.x - rect.width() / 2,
          markerBottomCenterCoords.y - 15 - rect.height());

      paintText.setTextAlign(Paint.Align.CENTER);
      paintText.setTextSize(FONT_SIZE);
      paintText.setARGB(255, 255, 255, 255);
      paintRect.setARGB(130, 0, 0, 0);

      canvas.drawRoundRect(new RectF(rect), 2, 2, paintRect);
      canvas.drawText(
          item.getTitle(), rect.left + rect.width() / 2, rect.bottom - TITLE_MARGIN, paintText);
    }
  }