If the requested tile doesn't exist, try climbing up to a lower zoom

This commit is contained in:
Eric Fischer
2014-10-27 16:00:16 -07:00
parent 984ac17d6c
commit ea7216641b
+14
View File
@@ -105,12 +105,16 @@ void handle(std::string message, int z, unsigned x, unsigned y) {
void decode(char *fname, int z, unsigned x, unsigned y) { void decode(char *fname, int z, unsigned x, unsigned y) {
sqlite3 *db; sqlite3 *db;
int oz = z;
unsigned ox = x, oy = y;
if (sqlite3_open(fname, &db) != SQLITE_OK) { if (sqlite3_open(fname, &db) != SQLITE_OK) {
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db)); fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int handled = 0;
while (z >= 0 && !handled) {
const char *sql = "SELECT tile_data from tiles where zoom_level = ? and tile_column = ? and tile_row = ?;"; const char *sql = "SELECT tile_data from tiles where zoom_level = ? and tile_column = ? and tile_row = ?;";
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) { if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
@@ -126,11 +130,21 @@ void decode(char *fname, int z, unsigned x, unsigned y) {
int len = sqlite3_column_bytes(stmt, 0); int len = sqlite3_column_bytes(stmt, 0);
const char *s = (const char *) sqlite3_column_blob(stmt, 0); const char *s = (const char *) sqlite3_column_blob(stmt, 0);
if (z != oz) {
fprintf(stderr, "%s: Warning: using tile %d/%u/%u instead of %d/%u/%u\n", fname, z, x, y, oz, ox, oy);
}
handle(std::string(s, len), z, x, y); handle(std::string(s, len), z, x, y);
handled = 1;
} }
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
z--;
x /= 2;
y /= 2;
}
if (sqlite3_close(db) != SQLITE_OK) { if (sqlite3_close(db) != SQLITE_OK) {
fprintf(stderr, "%s: could not close database: %s\n", fname, sqlite3_errmsg(db)); fprintf(stderr, "%s: could not close database: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);