Exemple #1
0
 /**
  * Animated equivalent to {@link MapController#scrollBy(int, int)}. Scroll by a given amount using
  * the default animation, in pixels.
  *
  * <p><strong>Limitations</strong>: This method internally uses {@link
  * MapController#animateTo(com.google.android.maps.GeoPoint)} which doesn't animate anything if
  * the point is really far (in pixels) from the current point. In this case, nothing will be
  * animated at all.
  *
  * @param mapView The {@link MapView} to scroll
  * @param dx The horizontal scroll amount in pixels.
  * @param dy The vertical scroll amount in pixels.
  */
 public static void smoothScrollBy(MapView mapView, int dx, int dy) {
   final Projection projection = mapView.getProjection();
   final Point tmpPoint = TEMP_POINT;
   projection.toPixels(mapView.getMapCenter(), tmpPoint);
   tmpPoint.offset(dx, dy);
   IGeoPoint geoPoint = projection.fromPixels(tmpPoint.x, tmpPoint.y);
   //        mapView.getController().animateTo(geoPoint);
   mapView.getController().setCenter(geoPoint);
 }
Exemple #2
0
  @Override
  public void draw(final Canvas c, final MapView mapView, final boolean shadow) {

    if (shadow) {
      return;
    }

    // If map views is animating, don't update, scale will be wrong.
    if (mapView.isAnimating()) {
      return;
    }

    final int zoomLevel = mapView.getZoomLevel();

    if (zoomLevel >= minZoom) {
      final Projection projection = mapView.getProjection();

      if (projection == null) {
        return;
      }

      final IGeoPoint center = projection.fromPixels((screenWidth / 2), screenHeight / 2);
      if (zoomLevel != lastZoomLevel
          || (int) (center.getLatitudeE6() / 1E6) != (int) (lastLatitude / 1E6)) {
        lastZoomLevel = zoomLevel;
        lastLatitude = center.getLatitudeE6();
        createScaleBarPicture(mapView);
      }

      mBounds.set(projection.getScreenRect());
      mBounds.offset((int) xOffset, (int) yOffset);

      mBounds.set(
          mBounds.left,
          mBounds.top,
          mBounds.left + scaleBarPicture.getWidth(),
          mBounds.top + scaleBarPicture.getHeight());
      c.drawPicture(scaleBarPicture, mBounds);
    }
  }
Exemple #3
0
  @Override
  public boolean onSingleTapUp(final MotionEvent event, final MapView mapView) {
    Projection pj = mapView.getProjection();
    IGeoPoint p = pj.fromPixels(event.getX(), event.getY());

    // Store whether prior popup was displayed so we can call invalidate() &
    // remove it if necessary.
    boolean onHandleEvent = false;
    boolean isRemovePriorPopup = selectedGeoTrack != null;
    long idPriorStation = -1;
    if (isRemovePriorPopup) {
      idPriorStation = selectedGeoTrack.getId();
    }
    // Next test whether a new popup should be displayed
    selectedGeoTrack = getHitMapLocation(mapView, p);
    if (isRemovePriorPopup
        && selectedGeoTrack != null
        && idPriorStation == selectedGeoTrack.getId()) {
      selectedGeoTrack = null;
      hideBubble(mapView);
      onHandleEvent = true;
    }
    if (selectedGeoTrack != null) {
      openBubble(mapView, selectedGeoTrack);
      onHandleEvent = true;
    } else if (isRemovePriorPopup) {
      hideBubble(mapView);
    }
    // if (isRemovePriorPopup || selectedGeoTrack != null) {
    // // TODO hideBubble();
    // mapView.invalidate();
    // onHandleEvent = true;
    // }
    // ?? balloonView

    return onHandleEvent;
  }
Exemple #4
0
  private void createScaleBarPicture(final MapView mapView) {
    // We want the scale bar to be as long as the closest round-number miles/kilometers
    // to 1-inch at the latitude at the current center of the screen.

    projection = mapView.getProjection();

    if (projection == null) {
      return;
    }

    // Two points, 1-inch apart in x/latitude, centered on screen
    IGeoPoint p1 = projection.fromPixels((screenWidth / 2) - (xdpi / 2), screenHeight / 2);
    IGeoPoint p2 = projection.fromPixels((screenWidth / 2) + (xdpi / 2), screenHeight / 2);

    final int xMetersPerInch = ((GeoPoint) p1).distanceTo(p2);

    p1 = projection.fromPixels(screenWidth / 2, (screenHeight / 2) - (ydpi / 2));
    p2 = projection.fromPixels(screenWidth / 2, (screenHeight / 2) + (ydpi / 2));

    final int yMetersPerInch = ((GeoPoint) p1).distanceTo(p2);

    final Canvas canvas = scaleBarPicture.beginRecording((int) xdpi, (int) ydpi);

    if (latitudeBar) {
      final String xMsg = scaleBarLengthText(xMetersPerInch, imperial, nautical);
      final Rect xTextRect = new Rect();
      textPaint.getTextBounds(xMsg, 0, xMsg.length(), xTextRect);

      final int textSpacing = (int) (xTextRect.height() / 5.0);

      canvas.drawRect(0, 0, xdpi, lineWidth, barPaint);
      canvas.drawRect(
          xdpi, 0, xdpi + lineWidth, xTextRect.height() + lineWidth + textSpacing, barPaint);

      if (!longitudeBar) {
        canvas.drawRect(0, 0, lineWidth, xTextRect.height() + lineWidth + textSpacing, barPaint);
      }

      canvas.drawText(
          xMsg,
          xdpi / 2 - xTextRect.width() / 2,
          xTextRect.height() + lineWidth + textSpacing,
          textPaint);
    }

    if (longitudeBar) {
      final String yMsg = scaleBarLengthText(yMetersPerInch, imperial, nautical);
      final Rect yTextRect = new Rect();
      textPaint.getTextBounds(yMsg, 0, yMsg.length(), yTextRect);

      final int textSpacing = (int) (yTextRect.height() / 5.0);

      canvas.drawRect(0, 0, lineWidth, ydpi, barPaint);
      canvas.drawRect(
          0, ydpi, yTextRect.height() + lineWidth + textSpacing, ydpi + lineWidth, barPaint);

      if (!latitudeBar) {
        canvas.drawRect(0, 0, yTextRect.height() + lineWidth + textSpacing, lineWidth, barPaint);
      }

      final float x = yTextRect.height() + lineWidth + textSpacing;
      final float y = ydpi / 2 + yTextRect.width() / 2;

      canvas.rotate(-90, x, y);
      canvas.drawText(yMsg, x, y + textSpacing, textPaint);
    }

    scaleBarPicture.endRecording();
  }