summaryrefslogtreecommitdiff
path: root/src/mbgl/tile/vector_tile.cpp
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2016-04-05 16:27:37 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-04-29 12:00:24 -0700
commit61d14089e0dd742719328fd74c693bcae6274a4b (patch)
treee47265a472fe75c635a22815ddc4a0c3fa1dbf84 /src/mbgl/tile/vector_tile.cpp
parent25442a77be75001665771097d8978b1191e403d9 (diff)
downloadqtlocation-mapboxgl-61d14089e0dd742719328fd74c693bcae6274a4b.tar.gz
[core] implement queryRenderedFeatures
Diffstat (limited to 'src/mbgl/tile/vector_tile.cpp')
-rw-r--r--src/mbgl/tile/vector_tile.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/mbgl/tile/vector_tile.cpp b/src/mbgl/tile/vector_tile.cpp
index 4c6027d36c..f3a02c5d76 100644
--- a/src/mbgl/tile/vector_tile.cpp
+++ b/src/mbgl/tile/vector_tile.cpp
@@ -54,8 +54,8 @@ VectorTileFeature::VectorTileFeature(pbf feature_pbf, const VectorTileLayer& lay
}
optional<Value> VectorTileFeature::getValue(const std::string& key) const {
- auto keyIter = layer.keys.find(key);
- if (keyIter == layer.keys.end()) {
+ auto keyIter = layer.keysMap.find(key);
+ if (keyIter == layer.keysMap.end()) {
return optional<Value>();
}
@@ -63,7 +63,7 @@ optional<Value> VectorTileFeature::getValue(const std::string& key) const {
while (tags) {
uint32_t tag_key = tags.varint();
- if (layer.keys.size() <= tag_key) {
+ if (layer.keysMap.size() <= tag_key) {
throw std::runtime_error("feature referenced out of range key");
}
@@ -84,6 +84,21 @@ optional<Value> VectorTileFeature::getValue(const std::string& key) const {
return optional<Value>();
}
+std::unordered_map<std::string,Value> VectorTileFeature::getProperties() const {
+ std::unordered_map<std::string,Value> properties;
+ pbf tags = tags_pbf;
+ while (tags) {
+ uint32_t tag_key = tags.varint();
+ uint32_t tag_val = tags.varint();
+ properties[layer.keys.at(tag_key)] = layer.values.at(tag_val);
+ }
+ return properties;
+}
+
+uint64_t VectorTileFeature::getID() const {
+ return id;
+}
+
GeometryCollection VectorTileFeature::getGeometries() const {
pbf data(geometry_pbf);
uint8_t cmd = 1;
@@ -166,7 +181,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(layer_pbf.string(), keys.size());
+ keysMap.emplace(layer_pbf.string(), keysMap.size());
} else if (layer_pbf.tag == 4) { // values
values.emplace_back(parseValue(layer_pbf.message()));
} else if (layer_pbf.tag == 5) { // extent
@@ -175,12 +190,20 @@ VectorTileLayer::VectorTileLayer(pbf layer_pbf) {
layer_pbf.skip();
}
}
+
+ for (auto &pair : keysMap) {
+ keys.emplace_back(std::reference_wrapper<const std::string>(pair.first));
+ }
}
util::ptr<const GeometryTileFeature> VectorTileLayer::getFeature(std::size_t i) const {
return std::make_shared<VectorTileFeature>(features.at(i), *this);
}
+std::string VectorTileLayer::getName() const {
+ return name;
+}
+
VectorTileMonitor::VectorTileMonitor(const TileID& tileID_, float pixelRatio_, const std::string& urlTemplate_, FileSource& fileSource_)
: tileID(tileID_),
pixelRatio(pixelRatio_),