Blurred Custom Tiles On Android Maps V2
I want to show a CustomOverlay on a Google Maps V2. The loading of the tiles works as expected, the only thing is, that the shown tiles are not appearing to be sharp at all, kind o
Solution 1:
I am solving this issue by drawing four tiles into one tile.
I wrote this TileProvider which is using another tile provider to create higher resolution tiles.
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import com.google.android.gms.maps.model.Tile;
import com.google.android.gms.maps.model.TileProvider;
import java.io.ByteArrayOutputStream;
publicclassCanvasTileProviderimplementsTileProvider {
staticfinalintTILE_SIZE=512;
private TileProvider mTileProvider;
publicCanvasTileProvider(TileProvider tileProvider) {
mTileProvider = tileProvider;
}
@Overridepublic Tile getTile(int x, int y, int zoom) {
byte[] data;
Bitmapimage= getNewBitmap();
Canvascanvas=newCanvas(image);
booleanisOk= onDraw(canvas, zoom, x, y);
data = bitmapToByteArray(image);
image.recycle();
if (isOk) {
Tiletile=newTile(TILE_SIZE, TILE_SIZE, data);
return tile;
} else {
return mTileProvider.getTile(x, y, zoom);
}
}
Paintpaint=newPaint();
privatebooleanonDraw(Canvas canvas, int zoom, int x, int y) {
x = x * 2;
y = y * 2;
TileleftTop= mTileProvider.getTile(x, y, zoom + 1);
TileleftBottom= mTileProvider.getTile(x, y + 1, zoom + 1);
TilerightTop= mTileProvider.getTile(x + 1, y, zoom + 1);
TilerightBottom= mTileProvider.getTile(x + 1, y + 1, zoom + 1);
if (leftTop == NO_TILE && leftBottom == NO_TILE && rightTop == NO_TILE && rightBottom == NO_TILE) {
returnfalse;
}
Bitmap bitmap;
if (leftTop != NO_TILE) {
bitmap = BitmapFactory.decodeByteArray(leftTop.data, 0, leftTop.data.length);
canvas.drawBitmap(bitmap, 0, 0, paint);
bitmap.recycle();
}
if (leftBottom != NO_TILE) {
bitmap = BitmapFactory.decodeByteArray(leftBottom.data, 0, leftBottom.data.length);
canvas.drawBitmap(bitmap, 0, 256, paint);
bitmap.recycle();
}
if (rightTop != NO_TILE) {
bitmap = BitmapFactory.decodeByteArray(rightTop.data, 0, rightTop.data.length);
canvas.drawBitmap(bitmap, 256, 0, paint);
bitmap.recycle();
}
if (rightBottom != NO_TILE) {
bitmap = BitmapFactory.decodeByteArray(rightBottom.data, 0, rightBottom.data.length);
canvas.drawBitmap(bitmap, 256, 256, paint);
bitmap.recycle();
}
returntrue;
}
private Bitmap getNewBitmap() {
Bitmapimage= Bitmap.createBitmap(TILE_SIZE, TILE_SIZE,
Bitmap.Config.ARGB_8888);
image.eraseColor(Color.TRANSPARENT);
return image;
}
privatestaticbyte[] bitmapToByteArray(Bitmap bm) {
ByteArrayOutputStreambos=newByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] data = bos.toByteArray();
try {
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
}
Solution 2:
It's a problem with the zoom level and scaling of the map tiles. This seems to be a problem with the Maps API V2 for Android. The behavior is supposedly intended as stated here: gmaps-api-issues #4840
I solved it by requesting larger tiles from the WMS - just replace 256x256 with 512x512.
Post a Comment for "Blurred Custom Tiles On Android Maps V2"