From 6a5461763cf6aa9bdf415e9678406bec9b56baaf Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Tue, 20 Dec 2016 16:41:23 -0800 Subject: [PATCH] Fix reordering of attributes and failure to update layer name table --- plugin.cpp | 49 ++++++++++++++++++++++++++----------------------- serial.hpp | 3 ++- tile.cpp | 19 ++++++++++++------- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/plugin.cpp b/plugin.cpp index c5bcdd3..db623a6 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -368,6 +368,30 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std:: std::map &layermap = (*layermaps)[tiling_seg]; + if (layermap.count(layername) == 0) { + layermap_entry lme = layermap_entry(layermap.size()); + lme.minzoom = z; + lme.maxzoom = z; + + layermap.insert(std::pair(layername, lme)); + + if (lme.id >= (*layer_unmaps)[tiling_seg].size()) { + (*layer_unmaps)[tiling_seg].resize(lme.id + 1); + (*layer_unmaps)[tiling_seg][lme.id] = layername; + } + } + + auto fk = layermap.find(layername); + fprintf(stderr, "assign layer %zu\n", fk->second.id); + sf.layer = fk->second.id; + + if (z < fk->second.minzoom) { + fk->second.minzoom = z; + } + if (z > fk->second.maxzoom) { + fk->second.maxzoom = z; + } + for (size_t i = 0; i < properties->length; i++) { serial_val v; v.type = -1; @@ -375,35 +399,14 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std:: stringify_value(properties->values[i], v.type, v.s, "Filter output", jp->line, j); 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)); - - if (lme.id >= (*layer_unmaps)[tiling_seg].size()) { - (*layer_unmaps)[tiling_seg].resize(lme.id + 1); - (*layer_unmaps)[tiling_seg][lme.id] = layername; - } - } + sf.full_keys.push_back(std::string(properties->keys[i]->string)); + sf.full_values.push_back(v); 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); - - sf.layer = fk->second.id; } } diff --git a/serial.hpp b/serial.hpp index a554920..59c5765 100644 --- a/serial.hpp +++ b/serial.hpp @@ -52,7 +52,8 @@ struct serial_feature { // XXX This isn't serialized. Should it be here? long long bbox[4]; - std::map kv; + std::vector full_keys; + std::vector full_values; }; void serialize_feature(FILE *geomfile, serial_feature *sf, long long *geompos, const char *fname, long long wx, long long wy, bool include_minzoom); diff --git a/tile.cpp b/tile.cpp index 84ce7bc..abce83e 100644 --- a/tile.cpp +++ b/tile.cpp @@ -78,7 +78,8 @@ struct coalesce { char *stringpool; std::vector keys; std::vector values; - std::map kv; + std::vector full_keys; + std::vector full_values; drawvec geom; unsigned long long index; unsigned long long index2; @@ -315,7 +316,8 @@ struct partial { std::vector geoms; std::vector keys; std::vector values; - std::map kv; + std::vector full_keys; + std::vector full_values; std::vector arc_polygon; long long layer; long long original_seq; @@ -1583,7 +1585,8 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s p.maxzoom = maxzoom; p.keys = sf.keys; p.values = sf.values; - p.kv = sf.kv; + p.full_keys = sf.full_keys; + p.full_values = sf.full_values; p.spacing = spacing; p.simplification = simplification; p.id = sf.id; @@ -1681,7 +1684,8 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s c.stringpool = stringpool + pool_off[partials[i].segment]; c.keys = partials[i].keys; c.values = partials[i].values; - c.kv = partials[i].kv; + c.full_keys = partials[i].full_keys; + c.full_values = partials[i].full_values; c.spacing = partials[i].spacing; c.id = partials[i].id; c.has_id = partials[i].has_id; @@ -1798,9 +1802,10 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s feature.has_id = layer_features[x].has_id; decode_meta(layer_features[x].m, layer_features[x].keys, layer_features[x].values, layer_features[x].stringpool, layer, feature); - for (auto kv : layer_features[x].kv) { - mvt_value v = stringified_to_mvt_value(kv.second.type, kv.second.s.c_str()); - layer.tag(feature, kv.first, v); + for (size_t a = 0; a < layer_features[x].full_keys.size(); a++) { + serial_val sv = layer_features[x].full_values[a]; + mvt_value v = stringified_to_mvt_value(sv.type, sv.s.c_str()); + layer.tag(feature, layer_features[x].full_keys[a], v); } if (additional[A_CALCULATE_FEATURE_DENSITY]) {