Skip to content

Commit 7301201

Browse files
authored
Adds overzoom support to mbtile and NPE fixes (#1288)
* fixed a crash when readTile() returns null if no tile found in the db. * added logic to allow over zooming to a level * mTile is null when a tile gets recycled before setTileImage() is called * just moved to if check * should be not equal * fixed indentation
1 parent 6ef93b7 commit 7301201

3 files changed

Lines changed: 42 additions & 15 deletions

File tree

vtm-android/src/org/oscim/android/tiling/source/mbtiles/MBTilesBitmapTileDataSource.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,22 @@ public void query(MapTile tile, ITileDataSink sink) {
108108
QueryResult res = QueryResult.FAILED;
109109
try {
110110
byte[] bytes = readTile(tile.tileX, tile.tileY, tile.zoomLevel);
111-
112-
if (mTransparentColor != null || mAlpha != null) {
113-
android.graphics.Bitmap androidBitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
114-
if (mTransparentColor != null)
115-
androidBitmap = processTransparentColor(androidBitmap, mTransparentColor);
116-
if (mAlpha != null)
117-
androidBitmap = processAlpha(androidBitmap, mAlpha);
118-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
119-
androidBitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, bos);
120-
bytes = bos.toByteArray();
111+
if (bytes != null) {
112+
if (mTransparentColor != null || mAlpha != null) {
113+
android.graphics.Bitmap androidBitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
114+
if (mTransparentColor != null)
115+
androidBitmap = processTransparentColor(androidBitmap, mTransparentColor);
116+
if (mAlpha != null)
117+
androidBitmap = processAlpha(androidBitmap, mAlpha);
118+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
119+
androidBitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, bos);
120+
bytes = bos.toByteArray();
121+
}
122+
123+
Bitmap bitmap = CanvasAdapter.decodeBitmap(new ByteArrayInputStream(bytes));
124+
sink.setTileImage(bitmap);
125+
res = QueryResult.SUCCESS;
121126
}
122-
123-
Bitmap bitmap = CanvasAdapter.decodeBitmap(new ByteArrayInputStream(bytes));
124-
sink.setTileImage(bitmap);
125-
res = QueryResult.SUCCESS;
126127
} catch (Throwable t) {
127128
log.severe(t.toString());
128129
} finally {

vtm-android/src/org/oscim/android/tiling/source/mbtiles/MBTilesBitmapTileSource.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,30 @@ public MBTilesBitmapTileSource(String path) {
4040
public MBTilesBitmapTileSource(String path, Integer alpha, Integer transparentColor) {
4141
super(new MBTilesBitmapTileDataSource(path, alpha, transparentColor));
4242
}
43+
44+
/**
45+
* Create a tile source for MBTiles raster databases.
46+
*
47+
* @param path the path to the MBTiles database.
48+
* @param overZoom allow over zooming to this level.
49+
*/
50+
public MBTilesBitmapTileSource(String path, int overZoom) {
51+
this(path, null, null, overZoom);
52+
}
53+
54+
/**
55+
* Create a tile source for MBTiles raster databases.
56+
*
57+
* @param path the path to the MBTiles database.
58+
* @param alpha an optional alpha value [0-255] to make the tiles transparent.
59+
* @param transparentColor an optional color that will be made transparent in the bitmap.
60+
* @param overZoom allow over zooming to this level.
61+
*/
62+
public MBTilesBitmapTileSource(String path, Integer alpha, Integer transparentColor, int overZoom) {
63+
super(new MBTilesBitmapTileDataSource(path, alpha, transparentColor));
64+
MBTilesTileDataSource ds = getDataSource();
65+
mZoomMin = ds.getMinZoom();
66+
mZoomMax = ds.getMaxZoom();
67+
mOverZoom = overZoom;
68+
}
4369
}

vtm/src/org/oscim/layers/tile/bitmap/BitmapTileLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected boolean loadTile(MapTile tile) {
5555

5656
@Override
5757
public void setTileImage(Bitmap bitmap) {
58-
if (isCanceled() || !mTile.state(LOADING)) {
58+
if (mTile == null || isCanceled() || !mTile.state(LOADING)) {
5959
bitmap.recycle();
6060
return;
6161
}

0 commit comments

Comments
 (0)