mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-04 17:35:42 +02:00
If the requested tile doesn't exist, try climbing up to a lower zoom
This commit is contained in:
@@ -105,32 +105,46 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *sql = "SELECT tile_data from tiles where zoom_level = ? and tile_column = ? and tile_row = ?;";
|
int handled = 0;
|
||||||
sqlite3_stmt *stmt;
|
while (z >= 0 && !handled) {
|
||||||
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
|
const char *sql = "SELECT tile_data from tiles where zoom_level = ? and tile_column = ? and tile_row = ?;";
|
||||||
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
|
sqlite3_stmt *stmt;
|
||||||
exit(EXIT_FAILURE);
|
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
|
||||||
|
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_bind_int(stmt, 1, z);
|
||||||
|
sqlite3_bind_int(stmt, 2, x);
|
||||||
|
sqlite3_bind_int(stmt, 3, (1LL << z) - 1 - y);
|
||||||
|
|
||||||
|
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||||
|
int len = sqlite3_column_bytes(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);
|
||||||
|
handled = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
|
||||||
|
z--;
|
||||||
|
x /= 2;
|
||||||
|
y /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_bind_int(stmt, 1, z);
|
|
||||||
sqlite3_bind_int(stmt, 2, x);
|
|
||||||
sqlite3_bind_int(stmt, 3, (1LL << z) - 1 - y);
|
|
||||||
|
|
||||||
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
|
||||||
int len = sqlite3_column_bytes(stmt, 0);
|
|
||||||
const char *s = (const char *) sqlite3_column_blob(stmt, 0);
|
|
||||||
|
|
||||||
handle(std::string(s, len), z, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlite3_finalize(stmt);
|
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user