/** * Converts TMS tile coordinates to QuadTree * * @param aTile The tile coordinates to convert * @return The QuadTree as String. */ protected String quadTree(final MapTile aTile) { final StringBuilder quadKey = new StringBuilder(); for (int i = aTile.getZoomLevel(); i > 0; i--) { int digit = 0; final int mask = 1 << (i - 1); if ((aTile.getX() & mask) != 0) digit += 1; if ((aTile.getY() & mask) != 0) digit += 2; quadKey.append("" + digit); } return quadKey.toString(); }
public byte[] getImage(final ITileSource pTileSource, final MapTile pTile) { try { byte[] bits = null; final String[] tile = {COLUMN_TILE}; final long x = (long) pTile.getX(); final long y = (long) pTile.getY(); final long z = (long) pTile.getZoomLevel(); final long index = ((z << z) + x << z) + y; final Cursor cur = mDatabase.query( TABLE, tile, COLUMN_KEY + " = " + index + " and " + COLUMN_PROVIDER + " = '" + pTileSource.name() + "'", null, null, null, null); if (cur.getCount() != 0) { cur.moveToFirst(); bits = (cur.getBlob(0)); } cur.close(); if (bits != null) { return bits; } } catch (final Throwable e) { Log.w(IMapView.LOGTAG, "Error getting db stream: " + pTile, e); } return null; }
@Override public void handleTile( final Canvas pCanvas, final int pTileSizePx, final MapTile pTile, final int pX, final int pY) { // no overflow detected here Log.d(IMapView.LOGTAG, "handleTile " + pTile.toString() + // ","+pX + "," + pY); Drawable currentMapTile = mTileProvider.getMapTile(pTile); boolean isReusable = currentMapTile instanceof ReusableBitmapDrawable; final ReusableBitmapDrawable reusableBitmapDrawable = isReusable ? (ReusableBitmapDrawable) currentMapTile : null; if (currentMapTile == null) { currentMapTile = getLoadingTile(); } if (currentMapTile != null) { mTilePoint.set(pX * pTileSizePx, pY * pTileSizePx); mTileRect.set( mTilePoint.x, mTilePoint.y, mTilePoint.x + pTileSizePx, mTilePoint.y + pTileSizePx); if (isReusable) { reusableBitmapDrawable.beginUsingDrawable(); } try { if (isReusable && !((ReusableBitmapDrawable) currentMapTile).isBitmapValid()) { currentMapTile = getLoadingTile(); isReusable = false; } onTileReadyToDraw(pCanvas, currentMapTile, mTileRect); } finally { if (isReusable) reusableBitmapDrawable.finishUsingDrawable(); } } if (DEBUGMODE) { mTileRect.set( pX * pTileSizePx, pY * pTileSizePx, pX * pTileSizePx + pTileSizePx, pY * pTileSizePx + pTileSizePx); pCanvas.drawText( pTile.toString(), mTileRect.left + 1, mTileRect.top + mDebugPaint.getTextSize(), mDebugPaint); pCanvas.drawLine( mTileRect.left, mTileRect.top, mTileRect.right, mTileRect.top, mDebugPaint); pCanvas.drawLine( mTileRect.left, mTileRect.top, mTileRect.left, mTileRect.bottom, mDebugPaint); } }