Esempio n. 1
0
  @Override
  public void draw(Canvas canvas, MapView mapView, boolean shadow) {

    super.draw(canvas, mapView, shadow);

    Projection projection = mapView.getProjection();

    int latSpan = mapView.getLatitudeSpan();
    int lngSpan = mapView.getLongitudeSpan();
    GeoPoint mapCenter = mapView.getMapCenter();
    int mapLeftGeo = mapCenter.getLongitudeE6() - (lngSpan / 2);
    int mapRightGeo = mapCenter.getLongitudeE6() + (lngSpan / 2);

    int mapTopGeo = mapCenter.getLatitudeE6() - (latSpan / 2);
    int mapBottomGeo = mapCenter.getLatitudeE6() + (latSpan / 2);

    GeoPoint geoPoint = this.getSampleLocation();

    if ((geoPoint.getLatitudeE6() > mapTopGeo && geoPoint.getLatitudeE6() < mapBottomGeo)
        && (geoPoint.getLongitudeE6() > mapLeftGeo && geoPoint.getLongitudeE6() < mapRightGeo)) {
      Point myPoint = new Point();
      projection.toPixels(geoPoint, myPoint);
      Bitmap marker =
          BitmapFactory.decodeResource(mapView.getContext().getResources(), R.drawable.markerblue);
      canvas.drawBitmap(marker, myPoint.x - 15, myPoint.y - 30, null);
    }
  }
Esempio n. 2
0
  public void calculateNewPathIfNeeded(MapView mv) {
    if (m_legs.isEmpty()) return;

    boolean shouldCalculate = false;
    GeoPoint ctr = mv.getMapCenter();

    // If we don't yet have a path, that obviously means we need to calculate, and
    // we should also cache the view limits for next time
    if (m_path == null) {
      shouldCalculate = true;
    } else {
      // We already have a path, which means we must have cached values
      // If we've simply moved a bit without changing the zoom level, and have
      // stayed on-screen, just shift pixels.
      int lat = ctr.getLatitudeE6();
      int lng = ctr.getLongitudeE6();
      if (lat < m_lat1
          || lat > m_lat2
          || lng < m_lng1
          || lng > m_lng2
          || mv.getLongitudeSpan() != (m_lng2 - m_lng1)) {
        shouldCalculate = true;
      }
    }
    if (shouldCalculate) {
      // Okay, we need to calculate a new path.  We'll make a path big enough to cover 9 screens.
      // (One each to the North, NE, E, SE, S, SW, W, and NW, and of course the real screen)
      // This allows us to wander all around the original screen all we want without having to
      // recalculate
      m_path = new Path();

      // So, lets set our 'area of interest'...
      m_lat = ctr.getLatitudeE6();
      m_lng = ctr.getLongitudeE6();
      int latSpan = mv.getLatitudeSpan();
      int lngSpan = mv.getLongitudeSpan();
      m_lat1 = m_lat - 2 * latSpan / 3;
      m_lat2 = m_lat + 2 * latSpan / 3;
      m_lng1 = m_lng - 2 * lngSpan / 3;
      m_lng2 = m_lng + 2 * lngSpan / 3;

      // Each tip may have one or more legs.  Try to draw them all
      for (TripLeg leg : m_legs) {

        // We can be more efficient here by short-circuiting and not considering
        // legs that aren't even partially on-screen

        // Iterate over each point in the leg, and figure out if we need to add it
        // to the drawn path.  The analogy here is a pen.
        boolean drewLastPoint = false;
        for (int i = 0; i < leg.size(); i++) {
          GeoPoint gp = leg.elementAt(i);
          int lat = gp.getLatitudeE6();
          int lng = gp.getLongitudeE6();
          Point thisPoint = new Point();
          Point otherPoint = new Point();

          if (lat >= m_lat1 && lat <= m_lat2 && lng >= m_lng1 && lng <= m_lng2) {

            // This point is in area of interest.  We will need to do some drawing
            mv.getProjection().toPixels(gp, thisPoint);
            if (drewLastPoint) {
              // Last point was also in area of interest...
              // The pen is on the paper.  Draw to the current point.
              m_path.lineTo(thisPoint.x, thisPoint.y);
            } else if (i != 0) {
              // The last point was out of the area of intersest.
              // Pick up the pen and put it there, then draw to the current point.
              mv.getProjection().toPixels(leg.elementAt(i - 1), otherPoint);
              m_path.moveTo(otherPoint.x, otherPoint.y);
              m_path.lineTo(thisPoint.x, thisPoint.y);
            } else {
              // This is the first point in the leg.
              // Pick up the pen and position it at this point.
              m_path.moveTo(thisPoint.x, thisPoint.y);
            }
            drewLastPoint = true;
          } else {
            // This point is not in the area of interest...
            if (drewLastPoint) {
              // ... but the last point was.  Draw to this point to finish the path
              mv.getProjection().toPixels(gp, thisPoint);
              m_path.lineTo(thisPoint.x, thisPoint.y);
            } else {
              // Neither is in the area of interest.  But, their connecting line
              // might CROSS the area of interest
              if (i != 0) {
                GeoPoint lastgeo = leg.elementAt(i - 1);
                Point previous = new Point(lastgeo.getLongitudeE6(), lastgeo.getLatitudeE6());
                Point current = new Point(lng, lat);
                if (Utils.doExteriorPointsCutRect(
                    previous, current,
                    m_lng1, m_lat1,
                    m_lng2, m_lat2)) {
                  mv.getProjection().toPixels(gp, thisPoint);
                  mv.getProjection().toPixels(lastgeo, otherPoint);
                  m_path.moveTo(otherPoint.x, otherPoint.y);
                  m_path.lineTo(thisPoint.x, thisPoint.y);
                }
              }
            }
            drewLastPoint = false;
          }
        }
      }
    } else {
      // Here, we don't need to calculate a whole new path, but we might need to move the existing
      // one a bit
      Point lastPoint = new Point();
      Point thisPoint = new Point();
      mv.getProjection().toPixels(new GeoPoint(m_lat, m_lng), lastPoint);
      mv.getProjection().toPixels(ctr, thisPoint);
      float dx = lastPoint.x - thisPoint.x;
      float dy = lastPoint.y - thisPoint.y;
      if (dx != 0.0 || dy != 0.0) {
        m_path.offset(dx, dy);
      }
      m_lat = ctr.getLatitudeE6();
      m_lng = ctr.getLongitudeE6();
    }
  }
 @Override
 public int getLongitudeSpan() {
   return mMapView.getLongitudeSpan();
 }