mbtiles不存在快速失败

This commit is contained in:
2026-08-04 18:26:14 +08:00
parent 75bfd25508
commit 18e64dfe22
4 changed files with 427 additions and 302 deletions
+16 -12
View File
@@ -238,6 +238,7 @@ void Map_Tile_Source_Config::from_base_json(const Psc::JSON* that_json) {
key = read_string_field(that_json, "key");
name = read_string_field(that_json, "name");
tile_type = read_optional_string_field(that_json, "tile_type", "imagery");
request_method = read_optional_string_field(that_json, "request_method", "GET");
url = read_optional_string_field(that_json, "url");
resource.from_base_json(that_json->get("resource"));
}
@@ -246,6 +247,7 @@ Psc::JSON Map_Tile_Source_Config::to_base_json() const {
ret.append({"key", key});
ret.append({"name", name});
ret.append({"tile_type", tile_type});
ret.append({"request_method", request_method});
if (!url.empty()) {
ret.append({"url", url});
}
@@ -257,6 +259,7 @@ Psc::JSON Map_Tile_Source_Config::to_public_json(std::string_view local_url) con
ret.append({"key", key});
ret.append({"name", name});
ret.append({"tile_type", tile_type});
ret.append({"request_method", request_method});
ret.append({"resource", resource.to_public_json(local() ? local_url : url)});
return ret;
}
@@ -292,30 +295,27 @@ void Map_Resources_Config::from_base_json(const Psc::JSON* that_json) {
if (current_imagery_key.empty()) {
current_imagery_key = "imagery";
}
imagery.from_base_json(that_json->get("imagery"));
google_imagery.from_base_json(that_json->get("google_imagery"));
terrain.from_base_json(that_json->get("terrain"));
tile_sources = read_optional_tile_source_array(that_json, "tile_sources");
if (!is_imagery_key(current_imagery_key)) {
current_imagery_key = "imagery";
auto source = std::ranges::find_if(tile_sources, [](const Map_Tile_Source_Config& item) {
return item.tile_type == "imagery";
});
current_imagery_key = source == tile_sources.end() ? "" : source->key;
}
}
Psc::JSON Map_Resources_Config::to_base_json() const {
auto ret = Psc::JSON::object();
ret.append({"current_imagery_key", current_imagery_key});
ret.append({"imagery", imagery.to_base_json()});
ret.append({"google_imagery", google_imagery.to_base_json()});
ret.append({"terrain", terrain.to_base_json()});
ret.append(write_tile_source_array("tile_sources", tile_sources));
return ret;
}
Psc::JSON Map_Resources_Config::to_public_json() const {
auto ret = Psc::JSON::object();
auto imagery_json = imagery.to_public_json("/map/imagery/{z}/{x}/{y}");
auto google_imagery_json = google_imagery.to_public_json("/tiles/{z}/{x}/{y}");
auto sources = Psc::JSON::array();
auto imagery_sources = Psc::JSON::array();
auto terrain_sources = Psc::JSON::array();
auto terrain = Psc::JSON::object();
bool has_terrain = false;
for (const auto& source : tile_sources) {
auto url = "/map/tile_sources/" + source.key + "/{z}/{x}/{y}";
auto public_source = source.to_public_json(url);
@@ -325,15 +325,19 @@ Psc::JSON Map_Resources_Config::to_public_json() const {
}
else if (source.tile_type == "terrain") {
terrain_sources.append(public_source);
if (!has_terrain) {
terrain = *public_source.get("resource");
has_terrain = true;
}
}
}
ret.append({"current_imagery_key", current_imagery_key});
ret.append({"tile_sources", sources});
ret.append({"imagery_sources", imagery_sources});
ret.append({"terrain_sources", terrain_sources});
ret.append({"imagery", imagery_json});
ret.append({"google_imagery", google_imagery_json});
ret.append({"terrain", terrain.to_public_json("/map/terrain/{z}/{x}/{y}")});
if (has_terrain) {
ret.append({"terrain", std::move(terrain)});
}
return ret;
}
bool Map_Resources_Config::is_imagery_key(std::string_view key) const {