This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private byte[] decompress(byte[] compressedData) | |
{ | |
if(compressedData == null) return null; | |
Inflater inflater = new Inflater(); | |
inflater.setInput(compressedData); | |
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(compressedData.length); | |
byte[] buffer = new byte[1024]; | |
while (!inflater.finished()) { | |
int count = 0; | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private byte[] getGridBLOBData(TilePosition tilePosition) { | |
String[] columns = { "grid" }; | |
String[] args = { Integer.toString(tilePosition.getZoom()), Integer.toString(tilePosition.getX()), Integer.toString(tilePosition.getY()) }; | |
Cursor cursor = this.db.query("grids", columns, "zoom_level=? AND tile_column=? AND tile_row=?", args, null, null, null); | |
if (cursor == null || cursor.getCount() == 0) | |
return null; | |
cursor.moveToFirst(); | |
byte[] data = cursor.getBlob(0); | |
cursor.close(); | |
return data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TilePosition extends Object{ | |
private int zoom; | |
private int x; | |
private int y; | |
public TilePosition(int zoom, int x, int y) { | |
this.zoom = zoom; | |
this.x = x; | |
this.y = y; | |
} | |
public int getZoom() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public TilePosition getTilePosition(float zoomLevel, double latitude, double longitude) { | |
int tileZoom = round(zoomLevel); | |
int tileX = (int) ((longitude + 180.0) / 360.0 * pow(2.0, tileZoom)); | |
int tileY = (int)((1.0 - log(tan(latitude * PI / 180.0) + 1.0 / cos(latitude * PI / 180.0)) / PI) / 2.0 * pow(2.0, tileZoom)); | |
tileY = (int) (pow(2.0, tileZoom) - tileY - 1.0); // flip Y, this is only for mbtiles file | |
return new TilePosition(tileZoom, tileX, tileY); | |
} |