Skip to content

Commit

Permalink
Allow overzooming to complete the zoom if it ever starts
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Aug 24, 2023
1 parent 996b013 commit 9a33e53
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ join-test: tile-join
./tile-join --overzoom -f -o tests/ne_110m_ocean/join/joined.mbtiles tests/ne_110m_ocean/join/ocean.mbtiles tests/ne_110m_ocean/join/countries.mbtiles
./tippecanoe-decode tests/ne_110m_ocean/join/joined.mbtiles > tests/ne_110m_ocean/join/joined.mbtiles.json.check
cmp tests/ne_110m_ocean/join/joined.mbtiles.json.check tests/ne_110m_ocean/join/joined.mbtiles.json
# BUG: tiles 4/15/3, 4/15/2, 4/15/1, and 4/15/0 should be ocean, but are currently missing
rm -f tests/ne_110m_ocean/join/ocean.mbtiles tests/ne_110m_ocean/join/countries.mbtiles tests/ne_110m_ocean/join/joined.mbtiles tests/ne_110m_ocean/join/joined.mbtiles.json.check

join-filter-test:
Expand Down
27 changes: 22 additions & 5 deletions tile-join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ struct reader {
long long x = 0;
long long y = 0;
std::string data = "";
bool current_tile_is_overzoomed = false;

// "done" means we have read all of the real tiles from the source.
// The iterator will continue to produce overzoomed tiles after it is "done."
Expand All @@ -432,6 +433,7 @@ struct reader {
int maxzoom_so_far = -1;
std::vector<std::pair<unsigned, unsigned>> tiles_at_maxzoom_so_far;
std::vector<std::pair<unsigned, unsigned>> overzoomed_tiles;
bool overzoom_consumed_at_this_zoom = false;

// for iterating mbtiles
sqlite3 *db = NULL;
Expand Down Expand Up @@ -498,25 +500,35 @@ struct reader {
}

// Checks the done status not only of this reader but also
// the others chained to it in the queue
// the others chained to it in the queue.
//
// Does this actually also need to check whether there are overzoomed
// tiles that have not yet been returned for a zoom level that has been
// started? FIXME
// Also claims not to be done if at least one overzoomed tile
// has been consumed at this zoom level, in which case they should
// all allowed to be consumed before stopping.
bool all_done() {
if (!done) {
return false;
}
if (overzoom_consumed_at_this_zoom) {
return false;
}

for (struct reader *r = next; r != NULL; r = r->next) {
if (!r->done) {
return false;
}
if (r->overzoom_consumed_at_this_zoom) {
return false;
}
}
return true;
}

std::pair<zxy, std::string> current() {
if (current_tile_is_overzoomed) {
overzoom_consumed_at_this_zoom = true;
}

return std::pair<zxy, std::string>(zxy(zoom, x, y), data);
}

Expand All @@ -529,18 +541,22 @@ struct reader {

if (overzoomed_tiles.size() == 0) {
next_overzoom();
overzoom_consumed_at_this_zoom = false;
}

auto xy = overzoomed_tiles.front();
overzoomed_tiles.erase(overzoomed_tiles.begin());

x = xy.first;
y = xy.second;

data = retrieve_overzoom(zxy(zoom, x, y));
current_tile_is_overzoomed = true;

return;
}

current_tile_is_overzoomed = false;

if (db != NULL) {
if (sqlite3_step(stmt) == SQLITE_ROW) {
zoom = sqlite3_column_int(stmt, 0);
Expand Down Expand Up @@ -623,6 +639,7 @@ struct reader {
}

std::sort(overzoomed_tiles.begin(), overzoomed_tiles.end(), tilecmp);
overzoom_consumed_at_this_zoom = false;
}

std::string get_tile(zxy tile) {
Expand Down

0 comments on commit 9a33e53

Please sign in to comment.