コード例 #1
0
  @Override
  protected void draw(Canvas c, MapView osmv, boolean shadow) {

    if (DEBUGMODE) {
      Log.d(IMapView.LOGTAG, "onDraw(" + shadow + ")");
    }

    if (shadow) {
      return;
    }

    Projection projection = osmv.getProjection();

    // Get the area we are drawing to
    Rect screenRect = projection.getScreenRect();
    // No overflow detected here! Log.d(IMapView.LOGTAG, "BEFORE Rect is " + screenRect.toString() +
    // mTopLeftMercator.toString());
    projection.toMercatorPixels(screenRect.left, screenRect.top, mTopLeftMercator);

    projection.toMercatorPixels(screenRect.right, screenRect.bottom, mBottomRightMercator);
    // No overflow detected here! Log.d(IMapView.LOGTAG, "AFTER Rect is " + screenRect.toString()  +
    // mTopLeftMercator.toString() + mBottomRightMercator.toString());
    mViewPort.set(
        mTopLeftMercator.x, mTopLeftMercator.y, mBottomRightMercator.x, mBottomRightMercator.y);
    // No overflow detected here! Log.d(IMapView.LOGTAG, "AFTER Rect is " + mViewPort.toString());

    // Draw the tiles!
    drawTiles(c, projection, projection.getZoomLevel(), TileSystem.getTileSize(), mViewPort);
  }
コード例 #2
0
  @Override
  protected void draw(final Canvas pC, final MapView pOsmv, final boolean shadow) {

    if (shadow) {
      return;
    }

    // Don't draw if we are animating
    if (pOsmv.isAnimating()) {
      return;
    }

    // Calculate the half-world size
    final Projection projection = pOsmv.getProjection();
    final int zoomLevel = projection.getZoomLevel();
    mWorldSize_2 = TileSystem.MapSize(zoomLevel) / 2;

    // Save the Mercator coordinates of what is on the screen
    mViewportRect.set(projection.getScreenRect());
    mViewportRect.offset(mWorldSize_2, mWorldSize_2);

    // Start calculating the tile area with the current viewport
    mTileArea.set(mViewportRect);

    // Get the target zoom level difference.
    int miniMapZoomLevelDifference = getZoomDifference();

    // Make sure the zoom level difference isn't below the minimum zoom level
    if (zoomLevel - getZoomDifference() < mTileProvider.getMinimumZoomLevel()) {
      miniMapZoomLevelDifference +=
          zoomLevel - getZoomDifference() - mTileProvider.getMinimumZoomLevel();
    }

    // Shift the screen coordinates into the target zoom level
    mTileArea.set(
        mTileArea.left >> miniMapZoomLevelDifference,
        mTileArea.top >> miniMapZoomLevelDifference,
        mTileArea.right >> miniMapZoomLevelDifference,
        mTileArea.bottom >> miniMapZoomLevelDifference);

    // Limit the area we are interested in for tiles to be the MAP_WIDTH by MAP_HEIGHT and
    // centered on the center of the screen
    mTileArea.set(
        mTileArea.centerX() - (getWidth() / 2),
        mTileArea.centerY() - (getHeight() / 2),
        mTileArea.centerX() + (getWidth() / 2),
        mTileArea.centerY() + (getHeight() / 2));

    // Get the area where we will draw the minimap in screen coordinates
    mMiniMapCanvasRect.set(
        mViewportRect.right - getPadding() - getWidth(),
        mViewportRect.bottom - getPadding() - getHeight(),
        mViewportRect.right - getPadding(),
        mViewportRect.bottom - getPadding());
    mMiniMapCanvasRect.offset(-mWorldSize_2, -mWorldSize_2);

    // Draw a solid background where the minimap will be drawn with a 2 pixel inset
    pC.drawRect(
        mMiniMapCanvasRect.left - 2,
        mMiniMapCanvasRect.top - 2,
        mMiniMapCanvasRect.right + 2,
        mMiniMapCanvasRect.bottom + 2,
        mPaint);

    super.drawTiles(
        pC,
        projection.getZoomLevel() - miniMapZoomLevelDifference,
        TileSystem.getTileSize(),
        mTileArea);
  }