Skip to content

Instantly share code, notes, and snippets.

Patrick Yin patrickyin

Block or report user

Report or block patrickyin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Decompress.java
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 {
View TilePoistion.java
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;
View TilePosition.java
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() {
View TilePosition.java
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);
}
You can’t perform that action at this time.