summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-11-26 08:26:26 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2018-11-26 12:43:13 +0200
commit82be3104cd40372e6f99284ff0fccd1e3879fd1d (patch)
treef5c19cdd593fff0e7e14b8b6b5ffaebfea5e46e5
parentf3b9a43b133bb329dd7c6fb532e980e4525cd435 (diff)
downloadqtlocation-mapboxgl-82be3104cd40372e6f99284ff0fccd1e3879fd1d.tar.gz
[core] Fix VectorTileFeature::getValue() semantics after geometry@v1.0.0
-rw-r--r--src/mbgl/tile/vector_tile_data.cpp3
-rw-r--r--test/tile/vector_tile.test.cpp34
2 files changed, 36 insertions, 1 deletions
diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp
index 6363b0d3dd..2d47515e0f 100644
--- a/src/mbgl/tile/vector_tile_data.cpp
+++ b/src/mbgl/tile/vector_tile_data.cpp
@@ -22,7 +22,8 @@ FeatureType VectorTileFeature::getType() const {
}
optional<Value> VectorTileFeature::getValue(const std::string& key) const {
- return feature.getValue(key);
+ const optional<Value> value(feature.getValue(key));
+ return value->is<NullValue>() ? nullopt : std::move(value);
}
std::unordered_map<std::string, Value> VectorTileFeature::getProperties() const {
diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp
index cd53c7c4a4..ed3eda7863 100644
--- a/test/tile/vector_tile.test.cpp
+++ b/test/tile/vector_tile.test.cpp
@@ -1,6 +1,7 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/fake_file_source.hpp>
#include <mbgl/tile/vector_tile.hpp>
+#include <mbgl/tile/vector_tile_data.hpp>
#include <mbgl/tile/tile_loader_impl.hpp>
#include <mbgl/util/default_thread_pool.hpp>
@@ -73,3 +74,36 @@ TEST(VectorTile, Issue8542) {
std::vector<Feature> result;
tile.querySourceFeatures(result, { { {"layer"} }, {} });
}
+
+TEST(VectorTileData, ParseResults) {
+ VectorTileData data(std::make_shared<std::string>(util::read_file("test/fixtures/map/issue12432/0-0-0.mvt")));
+
+ std::vector<std::string> layerNames = data.layerNames();
+ ASSERT_EQ(layerNames.size(), 2u);
+ ASSERT_EQ(layerNames.at(0), "admin");
+ ASSERT_EQ(layerNames.at(1), "water");
+
+ ASSERT_FALSE(data.getLayer("invalid"));
+
+ std::unique_ptr<GeometryTileLayer> layer = data.getLayer("admin");
+ ASSERT_EQ(layer->getName(), "admin");
+ ASSERT_EQ(layer->featureCount(), 17154u);
+
+ try {
+ layer->getFeature(17154u);
+ ASSERT_TRUE(false) << "should throw: feature index is out of range.";
+ } catch (const std::out_of_range&) {
+ ASSERT_TRUE(true);
+ }
+
+ std::unique_ptr<GeometryTileFeature> feature = layer->getFeature(0u);
+ ASSERT_EQ(feature->getType(), mbgl::FeatureType::LineString);
+ ASSERT_TRUE(feature->getID().is<uint64_t>());
+ ASSERT_EQ(feature->getID().get<uint64_t>(), 1u);
+
+ std::unordered_map<std::string, Value> properties = feature->getProperties();
+ ASSERT_EQ(properties.size(), 3u);
+ ASSERT_EQ(properties.at("disputed"), *feature->getValue("disputed"));
+
+ ASSERT_EQ(feature->getValue("invalid"), nullopt);
+} \ No newline at end of file