diff --git a/src/mbgl/map/geometry_tile.cpp b/src/mbgl/map/geometry_tile.cpp index f87468914..785845b4d 100644 --- a/src/mbgl/map/geometry_tile.cpp +++ b/src/mbgl/map/geometry_tile.cpp @@ -1,4 +1,5 @@ #include +#include #include namespace mbgl { diff --git a/src/mbgl/map/geometry_tile.hpp b/src/mbgl/map/geometry_tile.hpp index f303a32bd..3df0661fb 100644 --- a/src/mbgl/map/geometry_tile.hpp +++ b/src/mbgl/map/geometry_tile.hpp @@ -1,9 +1,7 @@ #ifndef MBGL_MAP_GEOMETRY_TILE #define MBGL_MAP_GEOMETRY_TILE -#include #include -#include #include #include #include @@ -11,10 +9,7 @@ #include #include -#include #include -#include -#include #include namespace mbgl { diff --git a/src/mbgl/map/vector_tile.cpp b/src/mbgl/map/vector_tile.cpp index e0f6c2d73..bf10f8706 100644 --- a/src/mbgl/map/vector_tile.cpp +++ b/src/mbgl/map/vector_tile.cpp @@ -29,7 +29,8 @@ Value parseValue(pbf data) { return false; } -VectorTileFeature::VectorTileFeature(pbf feature_pbf, const VectorTileLayer& layer) { +VectorTileFeature::VectorTileFeature(pbf feature_pbf, const VectorTileLayer& layer_) + : layer(layer_) { while (feature_pbf.next()) { if (feature_pbf.tag == 1) { // id id = feature_pbf.varint(); @@ -43,16 +44,16 @@ VectorTileFeature::VectorTileFeature(pbf feature_pbf, const VectorTileLayer& lay throw std::runtime_error("feature referenced out of range key"); } - if (tags) { - uint32_t tag_val = tags.varint(); - if (layer.values.size() <= tag_val) { - throw std::runtime_error("feature referenced out of range value"); - } - - properties.emplace(layer.keys[tag_key], layer.values[tag_val]); - } else { + if (!tags) { throw std::runtime_error("uneven number of feature tag ids"); } + + uint32_t tag_val = tags.varint(); + if (layer.values.size() <= tag_val) { + throw std::runtime_error("feature referenced out of range value"); + } + + properties.emplace(tag_key, tag_val); } } else if (feature_pbf.tag == 3) { // type type = (FeatureType)feature_pbf.varint(); @@ -65,11 +66,15 @@ VectorTileFeature::VectorTileFeature(pbf feature_pbf, const VectorTileLayer& lay } mapbox::util::optional VectorTileFeature::getValue(const std::string& key) const { - auto it = properties.find(key); - if (it != properties.end()) { - return it->second; + auto keyIter = layer.keys.find(key); + if (keyIter == layer.keys.end()) { + return mapbox::util::optional(); } - return mapbox::util::optional(); + auto propIter = properties.find(keyIter->second); + if (propIter == properties.end()) { + return mapbox::util::optional(); + } + return layer.values[propIter->second]; } GeometryCollection VectorTileFeature::getGeometries() const { @@ -143,7 +148,7 @@ VectorTileLayer::VectorTileLayer(pbf layer_pbf) { } else if (layer_pbf.tag == 2) { // feature features.push_back(layer_pbf.message()); } else if (layer_pbf.tag == 3) { // keys - keys.emplace_back(layer_pbf.string()); + keys.emplace(layer_pbf.string(), keys.size()); } else if (layer_pbf.tag == 4) { // values values.emplace_back(std::move(parseValue(layer_pbf.message()))); } else if (layer_pbf.tag == 5) { // extent diff --git a/src/mbgl/map/vector_tile.hpp b/src/mbgl/map/vector_tile.hpp index fc8c5966a..6685bb613 100644 --- a/src/mbgl/map/vector_tile.hpp +++ b/src/mbgl/map/vector_tile.hpp @@ -4,6 +4,8 @@ #include #include +#include + namespace mbgl { class VectorTileLayer; @@ -17,9 +19,10 @@ public: GeometryCollection getGeometries() const override; private: + const VectorTileLayer& layer; uint64_t id = 0; FeatureType type = FeatureType::Unknown; - std::map properties; + std::unordered_map properties; pbf geometry_pbf; }; @@ -36,7 +39,7 @@ private: std::string name; uint32_t extent = 4096; - std::vector keys; + std::unordered_map keys; std::vector values; std::vector features; }; @@ -48,7 +51,7 @@ public: util::ptr getLayer(const std::string&) const override; private: - std::map> layers; + std::unordered_map> layers; }; } diff --git a/src/mbgl/style/filter_expression.cpp b/src/mbgl/style/filter_expression.cpp index ec44b57b5..684715b02 100644 --- a/src/mbgl/style/filter_expression.cpp +++ b/src/mbgl/style/filter_expression.cpp @@ -1,3 +1,4 @@ +#include #include #include