예제 #1
0
  private Point getUpperLeftCornerOfCenterMapTileInScreen(
      final int[] centerMapTileCoords, final int tileSizePx, final Point reuse) {
    if (OpenStreetMapViewConstants.DEBUGMODE)
      Log.d("RMAPS-Me", "YandexTrafficOverlay getUpperLeftCornerOfCenterMapTileInScreen is Called");
    final Point out = (reuse != null) ? reuse : new Point();

    final int viewWidth = mMapView.getWidth();
    final int viewWidth_2 = viewWidth / 2;
    final int viewHeight = mMapView.getHeight();
    final int viewHeight_2 = viewHeight / 2;

    /*
     * Calculate the Latitude/Longitude on the left-upper ScreenCoords of the center MapTile. So in the end we can
     * determine which MapTiles we additionally need next to the centerMapTile.
     */
    final BoundingBoxE6 bb =
        Util.getBoundingBoxFromMapTile(
            centerMapTileCoords, mMapView.getZoomLevel(), mRendererInfo.PROJECTION);
    final float[] relativePositionInCenterMapTile =
        bb.getRelativePositionOfGeoPointInBoundingBoxWithLinearInterpolation(
            mMapView.getMapCenterLatitudeE6(), mMapView.getMapCenterLongitudeE6(), null);

    final int centerMapTileScreenLeft =
        viewWidth_2 - (int) (0.5f + (relativePositionInCenterMapTile[1] * tileSizePx));
    final int centerMapTileScreenTop =
        viewHeight_2 - (int) (0.5f + (relativePositionInCenterMapTile[0] * tileSizePx));

    out.set(centerMapTileScreenLeft, centerMapTileScreenTop);
    return out;
  }
예제 #2
0
  @Override
  protected void onDraw(Canvas c, OpenStreetMapView osmv) {
    if (OpenStreetMapViewConstants.DEBUGMODE)
      Log.d("RMAPS-Me", "YandexTrafficOverlay onDraw is Called");
    // final long startMs = System.currentTimeMillis();

    /*
     * Do some calculations and drag attributes to local variables to save some performance.
     */
    final int zoomLevel = mMapView.getZoomLevel();
    final int viewWidth = mMapView.getWidth();
    final int viewHeight = mMapView.getHeight();
    final int tileSizePx = (int) (this.mRendererInfo.getTileSizePx(zoomLevel) * osmv.mTouchScale);

    /*
     * Get the center MapTile which is above this.mLatitudeE6 and this.mLongitudeE6 .
     */
    final int[] centerMapTileCoords =
        Util.getMapTileFromCoordinates(
            mMapView.getMapCenterLatitudeE6(),
            mMapView.getMapCenterLongitudeE6(),
            zoomLevel,
            null,
            mRendererInfo.PROJECTION);

    /*
     * Calculate the Latitude/Longitude on the left-upper ScreenCoords of the center MapTile. So in the end we can
     * determine which MapTiles we additionally need next to the centerMapTile.
     */
    final Point upperLeftCornerOfCenterMapTile =
        getUpperLeftCornerOfCenterMapTileInScreen(centerMapTileCoords, tileSizePx, null);

    final int centerMapTileScreenLeft = upperLeftCornerOfCenterMapTile.x;
    final int centerMapTileScreenTop = upperLeftCornerOfCenterMapTile.y;

    final int centerMapTileScreenRight = centerMapTileScreenLeft + tileSizePx;
    final int centerMapTileScreenBottom = centerMapTileScreenTop + tileSizePx;

    /*
     * Calculate the amount of tiles needed for each side around the center one.
     */
    final int additionalTilesNeededToLeftOfCenter =
        (int) Math.ceil((float) centerMapTileScreenLeft / tileSizePx); // i.e.
    // "30 / 256"
    // = 1;
    final int additionalTilesNeededToRightOfCenter =
        (int) Math.ceil((float) (viewWidth - centerMapTileScreenRight) / tileSizePx);
    final int additionalTilesNeededToTopOfCenter =
        (int) Math.ceil((float) centerMapTileScreenTop / tileSizePx); // i.e.
    // "30 / 256"
    // = 1;
    final int additionalTilesNeededToBottomOfCenter =
        (int) Math.ceil((float) (viewHeight - centerMapTileScreenBottom) / tileSizePx);

    final int mapTileUpperBound = (int) Math.pow(2, zoomLevel);
    final int[] mapTileCoords = new int[] {centerMapTileCoords[0], centerMapTileCoords[1]};

    /* Draw all the MapTiles (from the upper left to the lower right). */
    for (int y = -additionalTilesNeededToTopOfCenter;
        y <= additionalTilesNeededToBottomOfCenter;
        y++) {
      for (int x = -additionalTilesNeededToLeftOfCenter;
          x <= additionalTilesNeededToRightOfCenter;
          x++) {
        /*
         * Add/substract the difference of the tile-position to the one of the center.
         */
        mapTileCoords[0] = MyMath.mod(centerMapTileCoords[0] + y, mapTileUpperBound);
        mapTileCoords[1] = MyMath.mod(centerMapTileCoords[1] + x, mapTileUpperBound);
        /* Construct a URLString, which represents the MapTile. */
        final String tileURLString = this.mRendererInfo.getTileURLString(mapTileCoords, zoomLevel);

        //				Log.i(DEBUGTAG, tileURLString);
        if (OpenStreetMapViewConstants.DEBUGMODE)
          Log.d("RMAPS-Me", "YandexTrafficOverlay onDraw Loop is Called");
        /* Draw the MapTile 'i tileSizePx' above of the centerMapTile */
        final Bitmap currentMapTile =
            this.mTileProvider.getMapTile(
                tileURLString, this.mRendererInfo.TILE_SOURCE_TYPE, null, 0, 0, 0);
        if (currentMapTile != null) {
          final int tileLeft =
              mMapView.mTouchMapOffsetX + centerMapTileScreenLeft + (x * tileSizePx);
          final int tileTop = mMapView.mTouchMapOffsetY + centerMapTileScreenTop + (y * tileSizePx);
          final Rect r = new Rect(tileLeft, tileTop, tileLeft + tileSizePx, tileTop + tileSizePx);
          c.drawBitmap(currentMapTile, null, r, this.mPaint);
          if (DEBUGMODE) {
            c.drawText(
                "y x = " + mapTileCoords[0] + " " + mapTileCoords[1] + " zoom " + zoomLevel,
                tileLeft + 5,
                tileTop + 45,
                this.mPaint);
          }
        }
      }
    }
  }
  @Override
  protected void onDraw(Canvas c, OpenStreetMapView osmv) {

    if (DEBUGMODE) logger.trace("onDraw");

    /*
     * Do some calculations and drag attributes to local variables to save
     * some performance.
     */
    final OpenStreetMapViewProjection pj = osmv.getProjection();
    final int zoomLevel = osmv.getZoomLevel(false);

    c.getClipBounds(mViewPort);
    final int tileSizePx = this.mRendererInfo.maptileSizePx();
    final int tileZoom = this.mRendererInfo.maptileZoom();
    final int worldSize_2 = 1 << (zoomLevel + tileZoom - 1);

    /*
     * Calculate the amount of tiles needed for each side around the center
     * one.
     */
    mViewPort.offset(worldSize_2, worldSize_2);
    final int tileNeededToLeftOfCenter = (mViewPort.left >> tileZoom) - 1;
    final int tileNeededToRightOfCenter = mViewPort.right >> tileZoom;
    final int tileNeededToTopOfCenter = (mViewPort.top >> tileZoom) - 1;
    final int tileNeededToBottomOfCenter = mViewPort.bottom >> tileZoom;

    final int mapTileUpperBound = 1 << zoomLevel;

    // make sure the cache is big enough for all the tiles
    final int numNeeded =
        (tileNeededToBottomOfCenter - tileNeededToTopOfCenter + 1)
            * (tileNeededToRightOfCenter - tileNeededToLeftOfCenter + 1);
    mTileProvider.ensureCapacity(numNeeded);

    /* Draw all the MapTiles (from the upper left to the lower right). */
    for (int y = tileNeededToTopOfCenter; y <= tileNeededToBottomOfCenter; y++) {
      for (int x = tileNeededToLeftOfCenter; x <= tileNeededToRightOfCenter; x++) {
        /* Construct a URLString, which represents the MapTile. */
        final int tileY = MyMath.mod(y, mapTileUpperBound);
        final int tileX = MyMath.mod(x, mapTileUpperBound);
        final OpenStreetMapTile tile =
            new OpenStreetMapTile(this.mRendererInfo, zoomLevel, tileX, tileY);

        pj.toPixels(x, y, mTilePos);
        final Drawable currentMapTile = mTileProvider.getMapTile(tile);
        if (currentMapTile != null) {
          currentMapTile.setBounds(
              mTilePos.x, mTilePos.y, mTilePos.x + tileSizePx, mTilePos.y + tileSizePx);
          currentMapTile.draw(c);
        }

        if (DEBUGMODE) {
          c.drawText(tile.toString(), mTilePos.x + 1, mTilePos.y + mPaint.getTextSize(), mPaint);
          c.drawLine(mTilePos.x, mTilePos.y, mTilePos.x + tileSizePx, mTilePos.y, mPaint);
          c.drawLine(mTilePos.x, mTilePos.y, mTilePos.x, mTilePos.y + tileSizePx, mPaint);
        }
      }
    }

    // draw a cross at center in debug mode
    if (DEBUGMODE) {
      final GeoPoint center = osmv.getMapCenter();
      final Point centerPoint = pj.toMapPixels(center, null);
      c.drawLine(centerPoint.x, centerPoint.y - 9, centerPoint.x, centerPoint.y + 9, mPaint);
      c.drawLine(centerPoint.x - 9, centerPoint.y, centerPoint.x + 9, centerPoint.y, mPaint);
    }
  }