Skip to content

Commit

Permalink
handle bounds/minzoom/maxzoom
Browse files Browse the repository at this point in the history
still todo: json
  • Loading branch information
cldellow committed Oct 5, 2024
1 parent 4c5abd8 commit b55ddb3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/tilemaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,52 @@ int main(const int argc, const char* argv[]) {
// Populate the `metadata` table
// See https://github.com/mapbox/mbtiles-spec/blob/master/1.3/spec.md#content

double minLon = std::numeric_limits<double>::max(),
maxLon = std::numeric_limits<double>::min(),
minLat = std::numeric_limits<double>::max(),
maxLat = std::numeric_limits<double>::min();
int minzoom = 100;
int maxzoom = 0;
double minLonCurrent, maxLonCurrent, minLatCurrent, maxLatCurrent;

std::map<std::string, std::string> metadata;
for (auto& input : inputs) {
for (const auto& entry : input->mbtiles.readMetadata()) {
metadata[entry.first] = entry.second;

if (entry.first == "minzoom" || entry.first == "maxzoom") {
int zoom = atoi(entry.second.c_str());

if (entry.first == "minzoom" && zoom < minzoom)
minzoom = zoom;
if (entry.first == "maxzoom" && zoom > maxzoom)
maxzoom = zoom;
}
}

input->mbtiles.readBoundingBox(minLonCurrent, maxLonCurrent, minLatCurrent, maxLatCurrent);

if (minLonCurrent < minLon) minLon = minLonCurrent;
if (minLatCurrent < minLat) minLat = minLatCurrent;
if (maxLonCurrent > maxLon) maxLon = maxLonCurrent;
if (maxLatCurrent > maxLat) maxLat = maxLatCurrent;
}

// Dump the metadata into merged.mbtiles
for (auto const& entry : metadata) {
merged.writeMetadata(entry.first, entry.second);
}

merged.writeMetadata(
"bounds",
std::to_string(minLon) + "," +
std::to_string(minLat) + "," +
std::to_string(maxLon) + "," +
std::to_string(maxLat)
);

merged.writeMetadata("minzoom", std::to_string(minzoom));
merged.writeMetadata("maxzoom", std::to_string(maxzoom));
}

merged.closeForWriting();
Expand Down

0 comments on commit b55ddb3

Please sign in to comment.