This repository was archived by the owner on Apr 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathMBTileDataSource.java
More file actions
74 lines (57 loc) · 2.35 KB
/
MBTileDataSource.java
File metadata and controls
74 lines (57 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package org.oscim.android.tiling.source.mbtiles;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import org.oscim.layers.tile.MapTile;
import org.oscim.tiling.ITileDataSink;
import org.oscim.tiling.ITileDataSource;
import org.oscim.tiling.source.ITileDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
/**
* Created by chaohan on 14-4-3.
*/
public class MBTileDataSource implements ITileDataSource {
static final Logger log = LoggerFactory.getLogger(MBTileDataSource.class);
MBTileSource mMBTileSource;
ITileDecoder mTileDecoder;
public final static String TABLE_TILES = "tiles";
public final static String COL_TILES_ZOOM_LEVEL = "zoom_level";
public final static String COL_TILES_TILE_COLUMN = "tile_column";
public final static String COL_TILES_TILE_ROW = "tile_row";
public final static String COL_TILES_TILE_DATA = "tile_data";
public MBTileDataSource(MBTileSource tileSource, ITileDecoder tileDecoder){
mMBTileSource = tileSource;
mTileDecoder = tileDecoder;
}
public void query(MapTile tile, ITileDataSink sink){
try {
InputStream ret = null;
final String[] tiledata = { COL_TILES_TILE_DATA };
final String[] xyz = {
Integer.toString(tile.tileX)
, Double.toString(Math.pow(2, tile.zoomLevel) - tile.tileY - 1) // Use Google Tiling Spec
, Integer.toString(tile.zoomLevel)
};
final Cursor cur = mMBTileSource.db.query(TABLE_TILES, tiledata, "tile_column=? and tile_row=? and zoom_level=?", xyz, null, null, null);
if(cur.getCount() != 0) {
cur.moveToFirst();
ret = new ByteArrayInputStream(cur.getBlob(0));
}
cur.close();
if(ret != null) {
if (mTileDecoder.decode(tile, sink, ret)) {
sink.completed(ITileDataSink.QueryResult.SUCCESS);
return;
}
}
} catch(final Throwable e) {
log.warn("Error getting db stream: " + tile, e);
sink.completed(ITileDataSink.QueryResult.FAILED);
}
sink.completed(ITileDataSink.QueryResult.FAILED);
}
public void destroy(){
}
}