summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-04-29 18:28:34 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-05-03 17:25:49 -0700
commitc8391729c7af8edc142f0319ccffe2720cfb6c18 (patch)
tree7159629cb4f8c9b86ba39dd8c79b87e8f5cb432d
parent01b3eac52f810b61dc2d5f0ea7a2bfa229daa01f (diff)
downloadqtlocation-mapboxgl-c8391729c7af8edc142f0319ccffe2720cfb6c18.tar.gz
[core] Use geometry.hpp feature type
m---------.mason0
-rw-r--r--bin/offline.gypi1
-rw-r--r--bin/render.gypi1
-rw-r--r--binding.gyp2
-rwxr-xr-xconfigure1
-rw-r--r--include/mbgl/map/map.hpp5
-rw-r--r--include/mbgl/util/feature.hpp19
-rw-r--r--mbgl.gypi3
-rw-r--r--platform/android/scripts/configure.sh1
-rw-r--r--platform/darwin/src/MGLGeometry_Private.h1
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj4
-rw-r--r--platform/ios/scripts/configure.sh1
-rw-r--r--platform/linux/scripts/configure.sh1
-rw-r--r--platform/node/src/node_feature.cpp172
-rw-r--r--platform/node/src/node_feature.hpp18
-rw-r--r--platform/node/src/node_map.cpp5
-rw-r--r--platform/node/test/suite_implementation.js3
-rw-r--r--platform/osx/osx.xcodeproj/project.pbxproj2
-rw-r--r--platform/osx/scripts/configure.sh1
-rw-r--r--platform/qt/scripts/configure.sh1
-rw-r--r--src/mbgl/geometry/feature_index.cpp52
-rw-r--r--src/mbgl/geometry/feature_index.hpp5
-rw-r--r--src/mbgl/map/map.cpp4
-rw-r--r--src/mbgl/source/source.cpp4
-rw-r--r--src/mbgl/source/source.hpp3
-rw-r--r--src/mbgl/style/filter.hpp2
-rw-r--r--src/mbgl/style/filter_evaluator.hpp10
-rw-r--r--src/mbgl/style/style.cpp7
-rw-r--r--src/mbgl/style/style.hpp3
-rw-r--r--src/mbgl/tile/geometry_tile.hpp6
-rw-r--r--src/mbgl/tile/tile_data.cpp2
-rw-r--r--src/mbgl/tile/tile_data.hpp3
-rw-r--r--src/mbgl/tile/vector_tile.cpp2
-rw-r--r--src/mbgl/tile/vector_tile.hpp4
-rw-r--r--src/mbgl/tile/vector_tile_data.cpp2
-rw-r--r--src/mbgl/tile/vector_tile_data.hpp3
-rw-r--r--src/mbgl/util/value.hpp9
37 files changed, 282 insertions, 81 deletions
diff --git a/.mason b/.mason
-Subproject ce432280285b3bb6a3b0fd042e7833acbfddf9e
+Subproject 2d75da369d1ebc7c5dd4139cde8941074366524
diff --git a/bin/offline.gypi b/bin/offline.gypi
index acdd17a749..295cbd0a01 100644
--- a/bin/offline.gypi
+++ b/bin/offline.gypi
@@ -6,6 +6,7 @@
'type': 'executable',
'dependencies': [
+ 'core',
'platform-lib',
'copy_certificate_bundle',
],
diff --git a/bin/render.gypi b/bin/render.gypi
index 31815d3c44..b6ae668981 100644
--- a/bin/render.gypi
+++ b/bin/render.gypi
@@ -6,6 +6,7 @@
'type': 'executable',
'dependencies': [
+ 'core',
'platform-lib',
'copy_certificate_bundle',
],
diff --git a/binding.gyp b/binding.gyp
index 3e7f9a452a..acd8129260 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -35,6 +35,8 @@
'platform/node/src/node_map.cpp',
'platform/node/src/node_request.hpp',
'platform/node/src/node_request.cpp',
+ 'platform/node/src/node_feature.hpp',
+ 'platform/node/src/node_feature.cpp',
'platform/node/src/util/async_queue.hpp',
],
diff --git a/configure b/configure
index 3290899498..d276cb7ace 100755
--- a/configure
+++ b/configure
@@ -110,6 +110,7 @@ print_flags libuv static_libs cflags ldflags
print_flags zlib static_libs cflags ldflags
print_flags nunicode static_libs cflags ldflags
print_flags libzip static_libs cflags ldflags
+print_flags geometry static_libs cflags ldflags
print_flags geojsonvt static_libs cflags ldflags
print_flags variant static_libs cflags ldflags
print_flags rapidjson static_libs cflags ldflags
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 41f34c102b..3200484ec1 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -7,6 +7,7 @@
#include <mbgl/map/update.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/util/geo.hpp>
+#include <mbgl/util/feature.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/annotation/annotation.hpp>
#include <mbgl/style/types.hpp>
@@ -159,8 +160,8 @@ public:
void removeCustomLayer(const std::string& id);
// Feature queries
- std::vector<std::string> queryRenderedFeatures(const ScreenCoordinate&, const optional<std::vector<std::string>>& layerIDs = {});
- std::vector<std::string> queryRenderedFeatures(const std::array<ScreenCoordinate, 2>&, const optional<std::vector<std::string>>& layerIDs = {});
+ std::vector<Feature> queryRenderedFeatures(const ScreenCoordinate&, const optional<std::vector<std::string>>& layerIDs = {});
+ std::vector<Feature> queryRenderedFeatures(const std::array<ScreenCoordinate, 2>&, const optional<std::vector<std::string>>& layerIDs = {});
// Memory
void setSourceTileCacheSize(size_t);
diff --git a/include/mbgl/util/feature.hpp b/include/mbgl/util/feature.hpp
new file mode 100644
index 0000000000..c9dbc31769
--- /dev/null
+++ b/include/mbgl/util/feature.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <mbgl/util/optional.hpp>
+
+#include <mapbox/geometry/feature.hpp>
+
+namespace mbgl {
+
+using Value = mapbox::geometry::value;
+
+class Feature : public mapbox::geometry::feature<double> {
+public:
+ Feature(geometry_type&& geometry_)
+ : mapbox::geometry::feature<double> { std::move(geometry_) } {}
+
+ optional<Value> id {};
+};
+
+} // namespace mbgl
diff --git a/mbgl.gypi b/mbgl.gypi
index 6619e0011f..e4d2474dfd 100644
--- a/mbgl.gypi
+++ b/mbgl.gypi
@@ -174,6 +174,7 @@
'<@(opengl_cflags)',
'<@(protozero_cflags)',
'<@(boost_cflags)',
+ '<@(geometry_cflags)',
'<@(geojsonvt_cflags)',
'<@(rapidjson_cflags)',
'<@(variant_cflags)',
@@ -288,10 +289,12 @@
'direct_dependent_settings': {
'cflags_cc': [
'<@(variant_cflags)',
+ '<@(geometry_cflags)',
],
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': [
'<@(variant_cflags)',
+ '<@(geometry_cflags)',
],
},
},
diff --git a/platform/android/scripts/configure.sh b/platform/android/scripts/configure.sh
index cf20f4a99e..30913aaf92 100644
--- a/platform/android/scripts/configure.sh
+++ b/platform/android/scripts/configure.sh
@@ -8,6 +8,7 @@ SQLITE_VERSION=3.9.1
ZLIB_VERSION=system
NUNICODE_VERSION=1.6
LIBZIP_VERSION=0.11.2
+GEOMETRY_VERSION=0.1.0
GEOJSONVT_VERSION=4.1.2
VARIANT_VERSION=1.1.0
RAPIDJSON_VERSION=1.0.2
diff --git a/platform/darwin/src/MGLGeometry_Private.h b/platform/darwin/src/MGLGeometry_Private.h
index 72123827df..71a083e588 100644
--- a/platform/darwin/src/MGLGeometry_Private.h
+++ b/platform/darwin/src/MGLGeometry_Private.h
@@ -5,7 +5,6 @@
#import <UIKit/UIKit.h>
#endif
-#import <mbgl/map/map.hpp>
#import <mbgl/util/geo.hpp>
/// Returns the smallest rectangle that contains both the given rectangle and
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 80f73adbbb..f97263f2cd 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -1591,6 +1591,7 @@
"$(zlib_cflags)",
"$(rapidjson_cflags)",
"$(variant_cflags)",
+ "$(geometry_cflags)",
);
OTHER_LDFLAGS = (
"$(sqlite_ldflags)",
@@ -1630,6 +1631,7 @@
"$(zlib_cflags)",
"$(rapidjson_cflags)",
"$(variant_cflags)",
+ "$(geometry_cflags)",
);
OTHER_LDFLAGS = (
"$(sqlite_ldflags)",
@@ -1682,6 +1684,7 @@
"$(zlib_cflags)",
"$(rapidjson_cflags)",
"$(variant_cflags)",
+ "$(geometry_cflags)",
);
OTHER_LDFLAGS = (
"-ObjC",
@@ -1711,6 +1714,7 @@
"$(zlib_cflags)",
"$(rapidjson_cflags)",
"$(variant_cflags)",
+ "$(geometry_cflags)",
);
OTHER_LDFLAGS = (
"-ObjC",
diff --git a/platform/ios/scripts/configure.sh b/platform/ios/scripts/configure.sh
index 769407445a..c92e58c7d2 100644
--- a/platform/ios/scripts/configure.sh
+++ b/platform/ios/scripts/configure.sh
@@ -4,6 +4,7 @@ PROTOZERO_VERSION=1.3.0
BOOST_VERSION=1.60.0
SQLITE_VERSION=system
ZLIB_VERSION=system
+GEOMETRY_VERSION=0.1.0
GEOJSONVT_VERSION=4.1.2
VARIANT_VERSION=1.1.0
RAPIDJSON_VERSION=1.0.2
diff --git a/platform/linux/scripts/configure.sh b/platform/linux/scripts/configure.sh
index 4d1b26fc9b..5f7edf7f8a 100644
--- a/platform/linux/scripts/configure.sh
+++ b/platform/linux/scripts/configure.sh
@@ -11,6 +11,7 @@ SQLITE_VERSION=3.9.1
LIBUV_VERSION=1.7.5
ZLIB_VERSION=system
NUNICODE_VERSION=1.6
+GEOMETRY_VERSION=0.1.0
GEOJSONVT_VERSION=4.1.2
VARIANT_VERSION=1.1.0
RAPIDJSON_VERSION=1.0.2
diff --git a/platform/node/src/node_feature.cpp b/platform/node/src/node_feature.cpp
new file mode 100644
index 0000000000..0a9e70cc2b
--- /dev/null
+++ b/platform/node/src/node_feature.cpp
@@ -0,0 +1,172 @@
+#include "node_feature.hpp"
+
+namespace node_mbgl {
+
+using namespace mapbox::geometry;
+
+using Value = mbgl::Value;
+using Feature = mbgl::Feature;
+using Geometry = mbgl::Feature::geometry_type;
+using Properties = mbgl::Feature::property_map;
+
+template <class T>
+struct ToType {
+public:
+ v8::Local<v8::String> operator()(const point<T>&) {
+ return type("Point");
+ }
+
+ v8::Local<v8::String> operator()(const line_string<T>&) {
+ return type("LineString");
+ }
+
+ v8::Local<v8::String> operator()(const polygon<T>&) {
+ return type("Polygon");
+ }
+
+ v8::Local<v8::String> operator()(const multi_point<T>&) {
+ return type("MultiPoint");
+ }
+
+ v8::Local<v8::String> operator()(const multi_line_string<T>&) {
+ return type("MultiLineString");
+ }
+
+ v8::Local<v8::String> operator()(const multi_polygon<T>&) {
+ return type("MultiPolygon");
+ }
+
+ v8::Local<v8::String> operator()(const geometry_collection<T>&) {
+ return type("GeometryCollection");
+ }
+
+private:
+ v8::Local<v8::String> type(const char* type) {
+ Nan::EscapableHandleScope scope;
+ return scope.Escape(Nan::New(type).ToLocalChecked());
+ }
+};
+
+template <class T>
+struct ToCoordinates {
+public:
+ // Handles line_string, multi_point, multi_line_string, and multi_polygon.
+ template <class E>
+ v8::Local<v8::Object> operator()(const std::vector<E>& vector) {
+ Nan::EscapableHandleScope scope;
+ v8::Local<v8::Array> result = Nan::New<v8::Array>(vector.size());
+ for (std::size_t i = 0; i < vector.size(); ++i) {
+ Nan::Set(result, i, operator()(vector[i]));
+ }
+ return scope.Escape(result);
+ }
+
+ v8::Local<v8::Object> operator()(const point<T>& point) {
+ Nan::EscapableHandleScope scope;
+ v8::Local<v8::Array> result = Nan::New<v8::Array>(2);
+ Nan::Set(result, 0, Nan::New(point.x));
+ Nan::Set(result, 1, Nan::New(point.y));
+ return scope.Escape(result);
+ }
+
+ v8::Local<v8::Object> operator()(const polygon<T>& polygon) {
+ Nan::EscapableHandleScope scope;
+ v8::Local<v8::Array> result = Nan::New<v8::Array>(1 + polygon.interior_rings.size());
+ Nan::Set(result, 0, operator()(polygon.exterior_ring));
+ for (std::size_t i = 0; i < polygon.interior_rings.size(); ++i) {
+ Nan::Set(result, i + 1, operator()(polygon.interior_rings[i]));
+ }
+ return scope.Escape(result);
+ }
+
+ v8::Local<v8::Object> operator()(const geometry_collection<T>& collection) {
+ Nan::EscapableHandleScope scope;
+ v8::Local<v8::Array> result = Nan::New<v8::Array>(collection.size());
+ for (std::size_t i = 0; i < collection.size(); ++i) {
+ Nan::Set(result, i, toJS(collection[i]));
+ }
+ return scope.Escape(result);
+ }
+};
+
+struct ToValue {
+ v8::Local<v8::Value> operator()(bool t) {
+ Nan::EscapableHandleScope scope;
+ return scope.Escape(Nan::New(t));
+ }
+
+ v8::Local<v8::Value> operator()(int64_t t) {
+ return operator()(double(t));
+ }
+
+ v8::Local<v8::Value> operator()(uint64_t t) {
+ return operator()(double(t));
+ }
+
+ v8::Local<v8::Value> operator()(double t) {
+ Nan::EscapableHandleScope scope;
+ return scope.Escape(Nan::New(t));
+ }
+
+ v8::Local<v8::Value> operator()(const std::string& t) {
+ Nan::EscapableHandleScope scope;
+ return scope.Escape(Nan::New(t).ToLocalChecked());
+ }
+
+ v8::Local<v8::Value> operator()(const std::vector<mbgl::Value>& array) {
+ Nan::EscapableHandleScope scope;
+ v8::Local<v8::Array> result = Nan::New<v8::Array>();
+ for (unsigned int i = 0; i < array.size(); i++) {
+ result->Set(i, toJS(array[i]));
+ }
+ return scope.Escape(result);
+ }
+
+ v8::Local<v8::Value> operator()(const std::unordered_map<std::string, mbgl::Value>& map) {
+ return toJS(map);
+ }
+};
+
+v8::Local<v8::Object> toJS(const Geometry& geometry) {
+ Nan::EscapableHandleScope scope;
+
+ v8::Local<v8::Object> result = Nan::New<v8::Object>();
+
+ Nan::Set(result, Nan::New("type").ToLocalChecked(), Geometry::visit(geometry, ToType<double>()));
+ Nan::Set(result, Nan::New("coordinates").ToLocalChecked(), Geometry::visit(geometry, ToCoordinates<double>()));
+
+ return scope.Escape(result);
+}
+
+v8::Local<v8::Value> toJS(const Value& value) {
+ return Value::visit(value, ToValue());
+}
+
+v8::Local<v8::Object> toJS(const Properties& properties) {
+ Nan::EscapableHandleScope scope;
+
+ v8::Local<v8::Object> result = Nan::New<v8::Object>();
+ for (const auto& property : properties) {
+ Nan::Set(result, Nan::New(property.first).ToLocalChecked(), toJS(property.second));
+ }
+
+ return scope.Escape(result);
+}
+
+v8::Local<v8::Object> toJS(const Feature& feature) {
+ Nan::EscapableHandleScope scope;
+
+ v8::Local<v8::Object> result = Nan::New<v8::Object>();
+
+ Nan::Set(result, Nan::New("type").ToLocalChecked(), Nan::New("Feature").ToLocalChecked());
+ Nan::Set(result, Nan::New("geometry").ToLocalChecked(), toJS(feature.geometry));
+ Nan::Set(result, Nan::New("properties").ToLocalChecked(), toJS(feature.properties));
+
+ if (feature.id) {
+ Nan::Set(result, Nan::New("id").ToLocalChecked(), toJS(*feature.id));
+ }
+
+ return scope.Escape(result);
+}
+
+}
diff --git a/platform/node/src/node_feature.hpp b/platform/node/src/node_feature.hpp
new file mode 100644
index 0000000000..7973ee19d4
--- /dev/null
+++ b/platform/node/src/node_feature.hpp
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <mbgl/util/feature.hpp>
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#pragma GCC diagnostic ignored "-Wshadow"
+#include <nan.h>
+#pragma GCC diagnostic pop
+
+namespace node_mbgl {
+
+v8::Local<v8::Value> toJS(const mbgl::Value&);
+v8::Local<v8::Object> toJS(const mbgl::Feature&);
+v8::Local<v8::Object> toJS(const mbgl::Feature::geometry_type&);
+v8::Local<v8::Object> toJS(const mbgl::Feature::property_map&);
+
+}
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index cf828782f5..b139e4252c 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -1,5 +1,6 @@
#include "node_map.hpp"
#include "node_request.hpp"
+#include "node_feature.hpp"
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/util/exception.hpp>
@@ -465,7 +466,7 @@ NAN_METHOD(NodeMap::QueryRenderedFeatures) {
}
try {
- std::vector<std::string> result;
+ std::vector<mbgl::Feature> result;
if (Nan::Get(posOrBox, 0).ToLocalChecked()->IsArray()) {
@@ -490,7 +491,7 @@ NAN_METHOD(NodeMap::QueryRenderedFeatures) {
auto array = Nan::New<v8::Array>();
for (unsigned int i = 0; i < result.size(); i++) {
- array->Set(i, Nan::New<v8::String>(result[i]).ToLocalChecked());
+ array->Set(i, toJS(result[i]));
}
info.GetReturnValue().Set(array);
} catch (const std::exception &ex) {
diff --git a/platform/node/test/suite_implementation.js b/platform/node/test/suite_implementation.js
index a5c70ab802..05b86f379f 100644
--- a/platform/node/test/suite_implementation.js
+++ b/platform/node/test/suite_implementation.js
@@ -51,8 +51,7 @@ module.exports = function (style, options, callback) {
callback(err, pixels, results.map(prepareFeatures));
});
- function prepareFeatures(json) {
- var r = JSON.parse(json);
+ function prepareFeatures(r) {
delete r.layer;
r.geometry = null;
return r;
diff --git a/platform/osx/osx.xcodeproj/project.pbxproj b/platform/osx/osx.xcodeproj/project.pbxproj
index 1174d5ef46..61c028bf8f 100644
--- a/platform/osx/osx.xcodeproj/project.pbxproj
+++ b/platform/osx/osx.xcodeproj/project.pbxproj
@@ -943,6 +943,7 @@
"$(zlib_cflags)",
"$(rapidjson_cflags)",
"$(variant_cflags)",
+ "$(geometry_cflags)",
);
OTHER_LDFLAGS = (
"$(zlib_ldflags)",
@@ -981,6 +982,7 @@
"$(zlib_cflags)",
"$(rapidjson_cflags)",
"$(variant_cflags)",
+ "$(geometry_cflags)",
);
OTHER_LDFLAGS = (
"$(zlib_ldflags)",
diff --git a/platform/osx/scripts/configure.sh b/platform/osx/scripts/configure.sh
index 6d2eef03c4..44e0c618e9 100644
--- a/platform/osx/scripts/configure.sh
+++ b/platform/osx/scripts/configure.sh
@@ -7,6 +7,7 @@ GLFW_VERSION=3.1.2
SQLITE_VERSION=3.9.1
ZLIB_VERSION=system
NUNICODE_VERSION=1.6
+GEOMETRY_VERSION=0.1.0
GEOJSONVT_VERSION=4.1.2
VARIANT_VERSION=1.1.0
RAPIDJSON_VERSION=1.0.2
diff --git a/platform/qt/scripts/configure.sh b/platform/qt/scripts/configure.sh
index d9a8f15cc2..b7807bd469 100644
--- a/platform/qt/scripts/configure.sh
+++ b/platform/qt/scripts/configure.sh
@@ -2,6 +2,7 @@
PROTOZERO_VERSION=1.3.0
BOOST_VERSION=1.60.0
+GEOMETRY_VERSION=0.1.0
GEOJSONVT_VERSION=4.1.2
GTEST_VERSION=1.7.0
LIBJPEG_TURBO_VERSION=1.4.2
diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp
index d6e19c1932..3e345fe817 100644
--- a/src/mbgl/geometry/feature_index.cpp
+++ b/src/mbgl/geometry/feature_index.cpp
@@ -5,8 +5,6 @@
#include <mbgl/layer/symbol_layer.hpp>
#include <mbgl/util/get_geometries.hpp>
#include <mbgl/text/collision_tile.hpp>
-#include <mbgl/util/rapidjson.hpp>
-#include <rapidjson/writer.h>
#include <mbgl/util/constants.hpp>
#include <cassert>
@@ -61,7 +59,7 @@ bool topDownSymbols(const IndexedSubfeature& a, const IndexedSubfeature& b) {
}
void FeatureIndex::query(
- std::unordered_map<std::string, std::vector<std::string>>& result,
+ std::unordered_map<std::string, std::vector<Feature>>& result,
const GeometryCollection& queryGeometry,
const float bearing,
const double tileSize,
@@ -116,7 +114,7 @@ void FeatureIndex::query(
}
void FeatureIndex::addFeature(
- std::unordered_map<std::string, std::vector<std::string>>& result,
+ std::unordered_map<std::string, std::vector<Feature>>& result,
const IndexedSubfeature& indexedFeature,
const GeometryCollection& queryGeometry,
const optional<std::vector<std::string>>& filterLayerIDs,
@@ -131,8 +129,8 @@ void FeatureIndex::addFeature(
auto sourceLayer = geometryTile.getLayer(indexedFeature.sourceLayerName);
assert(sourceLayer);
- auto feature = sourceLayer->getFeature(indexedFeature.index);
- assert(feature);
+ auto geometryTileFeature = sourceLayer->getFeature(indexedFeature.index);
+ assert(geometryTileFeature);
for (auto& layerID : layerIDs) {
@@ -142,49 +140,19 @@ void FeatureIndex::addFeature(
if (!styleLayer) continue;
if (!styleLayer->is<SymbolLayer>()) {
- auto geometries = getGeometries(*feature);
+ auto geometries = getGeometries(*geometryTileFeature);
if (!styleLayer->queryIntersectsGeometry(queryGeometry, geometries, bearing, pixelsToTileUnits)) continue;
}
- auto& layerResult = result[layerID];
+ Feature feature { mapbox::geometry::point<double>() };
+ feature.properties = geometryTileFeature->getProperties();
- auto properties = feature->getProperties();
- rapidjson::StringBuffer buffer;
- buffer.Clear();
- rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
-
- writer.StartObject();
- writer.Key("type");
- writer.String("Feature");
- auto id = feature->getID();
+ optional<uint64_t> id = geometryTileFeature->getID();
if (id) {
- writer.Key("id");
- writer.Double(feature->getID());
- }
- writer.Key("properties");
- writer.StartObject();
- for (auto& prop : properties) {
- std::string key = prop.first;
- Value& value = prop.second;
-
- writer.Key(key.c_str());
-
- if (value.is<std::string>()) {
- writer.String(value.get<std::string>().c_str());
- } else if (value.is<bool>()) {
- writer.Bool(value.get<bool>());
- } else if (value.is<int64_t>()) {
- writer.Int64(value.get<int64_t>());
- } else if (value.is<uint64_t>()) {
- writer.Uint64(value.get<uint64_t>());
- } else if (value.is<double>()) {
- writer.Double(value.get<double>());
- }
+ feature.id = Value(*id);
}
- writer.EndObject();
- writer.EndObject();
- layerResult.push_back(buffer.GetString());
+ result[layerID].push_back(std::move(feature));
}
}
diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp
index 0b520a841a..5d78df2138 100644
--- a/src/mbgl/geometry/feature_index.hpp
+++ b/src/mbgl/geometry/feature_index.hpp
@@ -3,6 +3,7 @@
#include <mbgl/tile/geometry_tile.hpp>
#include <mbgl/util/grid_index.hpp>
+#include <mbgl/util/feature.hpp>
#include <vector>
#include <string>
@@ -29,7 +30,7 @@ class FeatureIndex {
void insert(const GeometryCollection&, std::size_t index, const std::string& sourceLayerName, const std::string& bucketName);
void query(
- std::unordered_map<std::string, std::vector<std::string>>& result,
+ std::unordered_map<std::string, std::vector<Feature>>& result,
const GeometryCollection& queryGeometry,
const float bearing,
const double tileSize,
@@ -52,7 +53,7 @@ class FeatureIndex {
private:
void addFeature(
- std::unordered_map<std::string, std::vector<std::string>>& result,
+ std::unordered_map<std::string, std::vector<Feature>>& result,
const IndexedSubfeature &indexedFeature,
const GeometryCollection& queryGeometry,
const optional<std::vector<std::string>>& filterLayerIDs,
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 38198d42ec..2a0246b654 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -722,14 +722,14 @@ std::vector<TileCoordinate> pointsToCoordinates(const std::vector<ScreenCoordina
return queryGeometry;
}
-std::vector<std::string> Map::queryRenderedFeatures(const ScreenCoordinate& point, const optional<std::vector<std::string>>& layerIDs) {
+std::vector<Feature> Map::queryRenderedFeatures(const ScreenCoordinate& point, const optional<std::vector<std::string>>& layerIDs) {
if (!impl->style) return {};
auto queryGeometry = pointsToCoordinates({ point }, impl->transform.getState());
return impl->style->queryRenderedFeatures(queryGeometry, impl->transform.getZoom(), impl->transform.getAngle(), layerIDs);
}
-std::vector<std::string> Map::queryRenderedFeatures(const std::array<ScreenCoordinate, 2>& box, const optional<std::vector<std::string>>& layerIDs) {
+std::vector<Feature> Map::queryRenderedFeatures(const std::array<ScreenCoordinate, 2>& box, const optional<std::vector<std::string>>& layerIDs) {
if (!impl->style) return {};
std::vector<ScreenCoordinate> queryPoints {
diff --git a/src/mbgl/source/source.cpp b/src/mbgl/source/source.cpp
index 18de7bc093..78bffbb9b3 100644
--- a/src/mbgl/source/source.cpp
+++ b/src/mbgl/source/source.cpp
@@ -498,13 +498,13 @@ struct TileQuery {
double scale;
};
-std::unordered_map<std::string, std::vector<std::string>> Source::queryRenderedFeatures(
+std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatures(
const std::vector<TileCoordinate>& queryGeometry,
const double zoom,
const double bearing,
const optional<std::vector<std::string>>& layerIDs) {
- std::unordered_map<std::string, std::vector<std::string>> result;
+ std::unordered_map<std::string, std::vector<Feature>> result;
double minX = std::numeric_limits<double>::infinity();
double minY = std::numeric_limits<double>::infinity();
diff --git a/src/mbgl/source/source.hpp b/src/mbgl/source/source.hpp
index a4b6961245..cc579e11e7 100644
--- a/src/mbgl/source/source.hpp
+++ b/src/mbgl/source/source.hpp
@@ -7,6 +7,7 @@
#include <mbgl/util/mat4.hpp>
#include <mbgl/util/rapidjson.hpp>
+#include <mbgl/util/feature.hpp>
#include <forward_list>
#include <vector>
@@ -72,7 +73,7 @@ public:
std::forward_list<Tile *> getLoadedTiles() const;
const std::vector<Tile*>& getTiles() const;
- std::unordered_map<std::string, std::vector<std::string>> queryRenderedFeatures(
+ std::unordered_map<std::string, std::vector<Feature>> queryRenderedFeatures(
const std::vector<TileCoordinate>& queryGeometry,
const double zoom,
const double bearing,
diff --git a/src/mbgl/style/filter.hpp b/src/mbgl/style/filter.hpp
index 85878543f8..0a1dcbd17a 100644
--- a/src/mbgl/style/filter.hpp
+++ b/src/mbgl/style/filter.hpp
@@ -1,7 +1,7 @@
#pragma once
#include <mbgl/util/variant.hpp>
-#include <mbgl/util/value.hpp>
+#include <mbgl/util/feature.hpp>
#include <string>
#include <vector>
diff --git a/src/mbgl/style/filter_evaluator.hpp b/src/mbgl/style/filter_evaluator.hpp
index 27402ac211..0f3ee2a424 100644
--- a/src/mbgl/style/filter_evaluator.hpp
+++ b/src/mbgl/style/filter_evaluator.hpp
@@ -121,6 +121,16 @@ private:
!std::is_arithmetic<T1>::value || std::is_same<T1, bool>::value, bool> {
return false;
}
+
+ bool operator()(const std::vector<Value>&,
+ const std::vector<Value>&) const {
+ return false;
+ }
+
+ bool operator()(const std::unordered_map<std::string, Value>&,
+ const std::unordered_map<std::string, Value>&) const {
+ return false;
+ }
};
template <class Op>
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 4d515b4e60..fc0f1de9c8 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -314,18 +314,17 @@ RenderData Style::getRenderData() const {
return result;
}
-std::vector<std::string> Style::queryRenderedFeatures(
+std::vector<Feature> Style::queryRenderedFeatures(
const std::vector<TileCoordinate>& queryGeometry,
const double zoom,
const double bearing,
const optional<std::vector<std::string>>& layerIDs) {
- std::vector<std::unordered_map<std::string, std::vector<std::string>>> sourceResults;
+ std::vector<std::unordered_map<std::string, std::vector<Feature>>> sourceResults;
for (const auto& source : sources) {
sourceResults.emplace_back(source->queryRenderedFeatures(queryGeometry, zoom, bearing, layerIDs));
}
-
- std::vector<std::string> features;
+ std::vector<Feature> features;
auto featuresInserter = std::back_inserter(features);
// Combine all results based on the style layer order.
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index 5dac4d4790..bfeebc28d5 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -13,6 +13,7 @@
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/worker.hpp>
#include <mbgl/util/optional.hpp>
+#include <mbgl/util/feature.hpp>
#include <cstdint>
#include <string>
@@ -108,7 +109,7 @@ public:
RenderData getRenderData() const;
- std::vector<std::string> queryRenderedFeatures(
+ std::vector<Feature> queryRenderedFeatures(
const std::vector<TileCoordinate>& queryGeometry,
const double zoom,
const double bearing,
diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp
index 57d8eab1cc..0bcb92b47b 100644
--- a/src/mbgl/tile/geometry_tile.hpp
+++ b/src/mbgl/tile/geometry_tile.hpp
@@ -1,7 +1,7 @@
#ifndef MBGL_MAP_GEOMETRY_TILE
#define MBGL_MAP_GEOMETRY_TILE
-#include <mbgl/util/value.hpp>
+#include <mbgl/util/feature.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/vec.hpp>
@@ -39,8 +39,8 @@ public:
virtual ~GeometryTileFeature() = default;
virtual FeatureType getType() const = 0;
virtual optional<Value> getValue(const std::string& key) const = 0;
- virtual std::unordered_map<std::string,Value> getProperties() const { return std::unordered_map<std::string,Value>{}; };
- virtual uint64_t getID() const { return 0; }
+ virtual Feature::property_map getProperties() const { return Feature::property_map(); }
+ virtual optional<uint64_t> getID() const { return {}; }
virtual GeometryCollection getGeometries() const = 0;
virtual uint32_t getExtent() const { return defaultExtent; }
};
diff --git a/src/mbgl/tile/tile_data.cpp b/src/mbgl/tile/tile_data.cpp
index cb12e301f2..49a426b466 100644
--- a/src/mbgl/tile/tile_data.cpp
+++ b/src/mbgl/tile/tile_data.cpp
@@ -30,7 +30,7 @@ void TileData::dumpDebugLogs() const {
}
void TileData::queryRenderedFeatures(
- std::unordered_map<std::string, std::vector<std::string>>&,
+ std::unordered_map<std::string, std::vector<Feature>>&,
const GeometryCollection&,
const double,
const double,
diff --git a/src/mbgl/tile/tile_data.hpp b/src/mbgl/tile/tile_data.hpp
index 26c0032e35..338f246da0 100644
--- a/src/mbgl/tile/tile_data.hpp
+++ b/src/mbgl/tile/tile_data.hpp
@@ -4,6 +4,7 @@
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/optional.hpp>
+#include <mbgl/util/feature.hpp>
#include <mbgl/map/tile_id.hpp>
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/text/placement_config.hpp>
@@ -85,7 +86,7 @@ public:
virtual void redoPlacement(const std::function<void()>&) {}
virtual void queryRenderedFeatures(
- std::unordered_map<std::string, std::vector<std::string>>& result,
+ std::unordered_map<std::string, std::vector<Feature>>& result,
const GeometryCollection& queryGeometry,
const double bearing,
const double tileSize,
diff --git a/src/mbgl/tile/vector_tile.cpp b/src/mbgl/tile/vector_tile.cpp
index af30fa9986..aedb703898 100644
--- a/src/mbgl/tile/vector_tile.cpp
+++ b/src/mbgl/tile/vector_tile.cpp
@@ -102,7 +102,7 @@ std::unordered_map<std::string,Value> VectorTileFeature::getProperties() const {
return properties;
}
-uint64_t VectorTileFeature::getID() const {
+optional<uint64_t> VectorTileFeature::getID() const {
return id;
}
diff --git a/src/mbgl/tile/vector_tile.hpp b/src/mbgl/tile/vector_tile.hpp
index 441d6827ac..153d7dcef4 100644
--- a/src/mbgl/tile/vector_tile.hpp
+++ b/src/mbgl/tile/vector_tile.hpp
@@ -23,13 +23,13 @@ public:
FeatureType getType() const override { return type; }
optional<Value> getValue(const std::string&) const override;
std::unordered_map<std::string,Value> getProperties() const override;
- uint64_t getID() const override;
+ optional<uint64_t> getID() const override;
GeometryCollection getGeometries() const override;
uint32_t getExtent() const override;
private:
const VectorTileLayer& layer;
- uint64_t id = 0;
+ optional<uint64_t> id;
FeatureType type = FeatureType::Unknown;
packed_iter_type tags_iter;
packed_iter_type geometry_iter;
diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp
index c71b2b733d..1840dca9fe 100644
--- a/src/mbgl/tile/vector_tile_data.cpp
+++ b/src/mbgl/tile/vector_tile_data.cpp
@@ -191,7 +191,7 @@ void VectorTileData::redoPlacement(const std::function<void()>& callback) {
}
void VectorTileData::queryRenderedFeatures(
- std::unordered_map<std::string, std::vector<std::string>>& result,
+ std::unordered_map<std::string, std::vector<Feature>>& result,
const GeometryCollection& queryGeometry,
const double bearing,
const double tileSize,
diff --git a/src/mbgl/tile/vector_tile_data.hpp b/src/mbgl/tile/vector_tile_data.hpp
index 303fe343fe..52cef71d1b 100644
--- a/src/mbgl/tile/vector_tile_data.hpp
+++ b/src/mbgl/tile/vector_tile_data.hpp
@@ -4,6 +4,7 @@
#include <mbgl/tile/tile_data.hpp>
#include <mbgl/tile/tile_worker.hpp>
#include <mbgl/text/placement_config.hpp>
+#include <mbgl/util/feature.hpp>
#include <atomic>
#include <memory>
@@ -37,7 +38,7 @@ public:
bool hasData() const override;
void queryRenderedFeatures(
- std::unordered_map<std::string, std::vector<std::string>>& result,
+ std::unordered_map<std::string, std::vector<Feature>>& result,
const GeometryCollection& queryGeometry,
const double bearing,
const double tileSize,
diff --git a/src/mbgl/util/value.hpp b/src/mbgl/util/value.hpp
deleted file mode 100644
index 78507c7f25..0000000000
--- a/src/mbgl/util/value.hpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-
-#include <mbgl/util/variant.hpp>
-
-namespace mbgl {
-
-typedef variant<bool, int64_t, uint64_t, double, std::string> Value;
-
-} // namespace mbgl