Beispiel #1
0
 @Override
 public void onMapChanged() {
   List<TrackPoint> trackpoints = track.getPoints();
   synchronized (trackpoints) {
     for (TrackPoint tp : trackpoints) {
       tp.dirty = true;
     }
   }
 }
Beispiel #2
0
  @Override
  protected void onDraw(final Canvas c, final MapView mapView, int centerX, int centerY) {
    if (!track.show) return;

    Androzic application = (Androzic) context.getApplication();

    final int[] cxy = mapView.mapCenterXY;

    int w2 = mapView.getWidth() / 2;
    int h2 = mapView.getHeight() / 2;
    int left = cxy[0] - w2;
    int right = cxy[0] + w2;
    int top = cxy[1] - h2;
    int bottom = cxy[1] + h2;

    final Path path = new Path();
    boolean first = true;
    boolean skipped = false;
    int lastX = 0, lastY = 0;
    List<TrackPoint> trackpoints = track.getPoints();
    synchronized (trackpoints) {
      for (TrackPoint tp : trackpoints) {
        int[] xy = new int[2];
        if (tp.dirty) {
          xy = application.getXYbyLatLon(tp.latitude, tp.longitude);
          tp.x = xy[0];
          tp.y = xy[1];
          tp.dirty = false;
        } else {
          xy[0] = tp.x;
          xy[1] = tp.y;
        }

        if (first) {
          path.setLastPoint(xy[0] - cxy[0], xy[1] - cxy[1]);
          lastX = xy[0];
          lastY = xy[1];
          first = false;
          continue;
        }
        if ((lastX == xy[0] && lastY == xy[1])
            || lastX < left && cxy[0] < left
            || lastX > right && cxy[0] > right
            || lastY < top && cxy[1] < top
            || lastY > bottom && cxy[1] > bottom) {
          lastX = xy[0];
          lastY = xy[1];
          skipped = true;
          continue;
        }
        if (skipped) {
          path.moveTo(lastX - cxy[0], lastY - cxy[1]);
          skipped = false;
        }
        if (tp.continous) path.lineTo(xy[0] - cxy[0], xy[1] - cxy[1]);
        else path.moveTo(xy[0] - cxy[0], xy[1] - cxy[1]);
        lastX = xy[0];
        lastY = xy[1];
      }
    }
    c.drawPath(path, paint);
  }