Merge per-thread layer names and file keys

This commit is contained in:
Eric Fischer
2016-08-29 16:38:57 -07:00
parent c26fa23564
commit 7f49ce5caa
7 changed files with 75 additions and 22 deletions
+11 -4
View File
@@ -10,6 +10,7 @@
#include <vector>
#include <string>
#include <set>
#include <map>
#include "main.hpp"
#include "pool.hpp"
#include "mbtiles.hpp"
@@ -132,7 +133,7 @@ bool type_and_string::operator<(const type_and_string &o) const {
return false;
}
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, std::vector<std::string> &layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, std::vector<std::set<type_and_string> > &file_keys, int nlayers, int forcetable, const char *attribution) {
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, std::vector<std::string> &layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, std::vector<std::set<type_and_string> > &file_keys, int nlayers, int forcetable, const char *attribution, std::map<std::string, layermap_entry> const &layermap) {
char *sql, *err;
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('name', %Q);", fname);
@@ -230,19 +231,25 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, std::vector<std::
std::string buf("{");
aprintf(&buf, "\"vector_layers\": [ ");
std::vector<std::string> lnames;
for (auto ai = layermap.begin(); ai != layermap.end(); ++ai) {
lnames.push_back(ai->first);
}
int i;
for (i = 0; i < nlayers; i++) {
for (i = 0; i < lnames.size(); i++) {
if (i != 0) {
aprintf(&buf, ", ");
}
aprintf(&buf, "{ \"id\": \"");
quote(&buf, layername[i].c_str());
quote(&buf, lnames[i].c_str());
aprintf(&buf, "\", \"description\": \"\", \"minzoom\": %d, \"maxzoom\": %d, \"fields\": {", minzoom, maxzoom);
auto fk = layermap.find(lnames[i]);
std::set<type_and_string>::iterator j;
bool first = true;
for (j = file_keys[i].begin(); j != file_keys[i].end(); ++j) {
for (j = fk->second.file_keys.begin(); j != fk->second.file_keys.end(); ++j) {
if (first) {
first = false;
} else {