diff --git a/plugin.cpp b/plugin.cpp index a235b29..9657aea 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -239,7 +239,7 @@ mvt_layer parse_layer(int fd, unsigned z, unsigned x, unsigned y, mvt_layer cons return ret; } -serial_feature parse_feature(json_pull *jp, unsigned z, unsigned x, unsigned y) { +serial_feature parse_feature(json_pull *jp, unsigned z, unsigned x, unsigned y, std::vector> *layermaps, size_t tiling_seg) { serial_feature sf; while (1) { @@ -332,6 +332,16 @@ serial_feature parse_feature(json_pull *jp, unsigned z, unsigned x, unsigned y) } if (dv.size() > 0) { + std::string layername = "unknown"; + json_object *tippecanoe = json_hash_get(j, "tippecanoe"); + json_object *layer = NULL; + if (tippecanoe != NULL) { + layer = json_hash_get(tippecanoe, "layer"); + if (layer != NULL && layer->type == JSON_STRING) { + layername = std::string(layer->string); + } + } + sf.t = mb_geometry[t]; sf.geometry = dv; sf.segment = 0; @@ -350,6 +360,8 @@ serial_feature parse_feature(json_pull *jp, unsigned z, unsigned x, unsigned y) sf.has_id = true; } + std::map &layermap = (*layermaps)[tiling_seg]; + for (size_t i = 0; i < properties->length; i++) { serial_val v; v.type = -1; @@ -358,6 +370,27 @@ serial_feature parse_feature(json_pull *jp, unsigned z, unsigned x, unsigned y) if (v.type >= 0) { sf.kv.insert(std::pair(std::string(properties->keys[i]->string), v)); + + if (layermap.count(layername) == 0) { + layermap_entry lme = layermap_entry(layermap.size()); + lme.minzoom = z; + lme.maxzoom = z; + + layermap.insert(std::pair(layername, lme)); + } + + type_and_string tas; + tas.string = std::string(properties->keys[i]->string); + tas.type = v.type; + + auto fk = layermap.find(layername); + if (z < fk->second.minzoom) { + fk->second.minzoom = z; + } + if (z > fk->second.maxzoom) { + fk->second.maxzoom = z; + } + fk->second.file_keys.insert(tas); } } diff --git a/plugin.hpp b/plugin.hpp index 57600d5..197983e 100644 --- a/plugin.hpp +++ b/plugin.hpp @@ -1,3 +1,3 @@ mvt_layer filter_layer(const char *filter, mvt_layer &layer, unsigned z, unsigned x, unsigned y, std::vector> *layermaps, size_t tiling_seg); void setup_filter(const char *filter, int *write_to, int *read_from, pid_t *pid, unsigned z, unsigned x, unsigned y); -serial_feature parse_feature(json_pull *jp, unsigned z, unsigned x, unsigned y); +serial_feature parse_feature(json_pull *jp, unsigned z, unsigned x, unsigned y, std::vector> *layermaps, size_t tiling_seg); diff --git a/tile.cpp b/tile.cpp index 408a5b5..11a0f4b 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1522,7 +1522,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s if (prefilter == NULL) { sf = next_feature(geoms, geompos_in, metabase, meta_off, z, tx, ty, initial_x, initial_y, &original_features, &unclipped_features, nextzoom, maxzoom, minzoom, max_zoom_increment, pass, passes, along, alongminus, buffer, within, &first_time, line_detail, geomfile, geompos, &oprogress, todo, fname, child_shards); } else { - sf = parse_feature(prefilter_jp, z, tx, ty); + sf = parse_feature(prefilter_jp, z, tx, ty, layermaps, tiling_seg); } if (sf.t < 0) {