diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-03-04 18:44:33 -0800 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-03-09 13:11:23 -0800 |
commit | 0d10d2df1c6d246004e7291511f3aab7a8781d59 (patch) | |
tree | 3667c583d44c5237380ad7b79498787caa24a322 /src/mbgl/tile | |
parent | 548675a196f9e55d87cf8fce837b6e60393cb1b9 (diff) | |
download | qtlocation-mapboxgl-0d10d2df1c6d246004e7291511f3aab7a8781d59.tar.gz |
[core] query source features
Diffstat (limited to 'src/mbgl/tile')
-rw-r--r-- | src/mbgl/tile/geojson_tile.cpp | 23 | ||||
-rw-r--r-- | src/mbgl/tile/geojson_tile.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile.cpp | 36 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile.hpp | 10 | ||||
-rw-r--r-- | src/mbgl/tile/tile.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/tile/tile.hpp | 5 |
6 files changed, 82 insertions, 1 deletions
diff --git a/src/mbgl/tile/geojson_tile.cpp b/src/mbgl/tile/geojson_tile.cpp index 85d8b75619..5a2a72f50b 100644 --- a/src/mbgl/tile/geojson_tile.cpp +++ b/src/mbgl/tile/geojson_tile.cpp @@ -1,5 +1,6 @@ #include <mbgl/tile/geojson_tile.hpp> #include <mbgl/tile/geometry_tile_data.hpp> +#include <mbgl/style/query.hpp> #include <mapbox/geojsonvt.hpp> #include <supercluster.hpp> @@ -90,5 +91,27 @@ void GeoJSONTile::updateData(const mapbox::geometry::feature_collection<int16_t> } void GeoJSONTile::setNecessity(Necessity) {} + +void GeoJSONTile::querySourceFeatures( + std::vector<Feature>& result, + const style::SourceQueryOptions& options) { + + // Ignore the sourceLayer, there is only one + auto layer = getData()->getLayer({}); + + if (layer) { + auto featureCount = layer->featureCount(); + for (std::size_t i = 0; i < featureCount; i++) { + auto feature = layer->getFeature(i); + + // Apply filter, if any + if (options.filter && !(*options.filter)(*feature)) { + continue; + } + + result.push_back(convertFeature(*feature, id.canonical)); + } + } +} } // namespace mbgl diff --git a/src/mbgl/tile/geojson_tile.hpp b/src/mbgl/tile/geojson_tile.hpp index 6ddc6ea482..e1d269a9a7 100644 --- a/src/mbgl/tile/geojson_tile.hpp +++ b/src/mbgl/tile/geojson_tile.hpp @@ -18,6 +18,10 @@ public: void updateData(const mapbox::geometry::feature_collection<int16_t>&); void setNecessity(Necessity) final; + + void querySourceFeatures( + std::vector<Feature>& result, + const style::SourceQueryOptions&) override; }; } // namespace mbgl diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index 01f054bdf4..37787df9ea 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -12,8 +12,11 @@ #include <mbgl/geometry/feature_index.hpp> #include <mbgl/text/collision_tile.hpp> #include <mbgl/map/transform_state.hpp> -#include <mbgl/util/run_loop.hpp> #include <mbgl/map/query.hpp> +#include <mbgl/util/run_loop.hpp> +#include <mbgl/style/filter_evaluator.hpp> +#include <mbgl/style/query.hpp> +#include <mbgl/util/logging.hpp> namespace mbgl { @@ -158,4 +161,35 @@ void GeometryTile::queryRenderedFeatures( collisionTile.get()); } +void GeometryTile::querySourceFeatures( + std::vector<Feature>& result, + const style::SourceQueryOptions& options) { + + // No source layers, specified, nothing to do + if (!options.sourceLayers) { + Log::Warning(Event::General, "At least one sourceLayer required"); + return; + } + + for (auto sourceLayer : *options.sourceLayers) { + // Go throught all sourceLayers, if any + // to gather all the features + auto layer = data->getLayer(sourceLayer); + + if (layer) { + auto featureCount = layer->featureCount(); + for (std::size_t i = 0; i < featureCount; i++) { + auto feature = layer->getFeature(i); + + // Apply filter, if any + if (options.filter && !(*options.filter)(*feature)) { + continue; + } + + result.push_back(convertFeature(*feature, id.canonical)); + } + } + } +} + } // namespace mbgl diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index 538ea4fbd2..cabe193467 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -21,6 +21,7 @@ namespace style { class Style; class Layer; class UpdateParameters; +class SourceQueryOptions; } // namespace style class GeometryTile : public Tile { @@ -46,6 +47,10 @@ public: const TransformState&, const RenderedQueryOptions& options) override; + void querySourceFeatures( + std::vector<Feature>& result, + const style::SourceQueryOptions&) override; + void cancel() override; class LayoutResult { @@ -66,6 +71,11 @@ public: void onPlacement(PlacementResult); void onError(std::exception_ptr); + +protected: + const GeometryTileData* getData() { + return data.get(); + } private: const std::string sourceID; diff --git a/src/mbgl/tile/tile.cpp b/src/mbgl/tile/tile.cpp index 2f347fb950..4fb8331aeb 100644 --- a/src/mbgl/tile/tile.cpp +++ b/src/mbgl/tile/tile.cpp @@ -4,6 +4,7 @@ #include <mbgl/util/string.hpp> #include <mbgl/util/logging.hpp> #include <mbgl/map/query.hpp> +#include <mbgl/style/query.hpp> namespace mbgl { @@ -35,4 +36,8 @@ void Tile::queryRenderedFeatures( const TransformState&, const RenderedQueryOptions&) {} +void Tile::querySourceFeatures( + std::vector<Feature>&, + const style::SourceQueryOptions&) {} + } // namespace mbgl diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp index b335d1a5d5..613b15f36c 100644 --- a/src/mbgl/tile/tile.hpp +++ b/src/mbgl/tile/tile.hpp @@ -25,6 +25,7 @@ class RenderedQueryOptions; namespace style { class Layer; +class SourceQueryOptions; } // namespace style class Tile : private util::noncopyable { @@ -58,6 +59,10 @@ public: const TransformState&, const RenderedQueryOptions& options); + virtual void querySourceFeatures( + std::vector<Feature>& result, + const style::SourceQueryOptions&); + void setTriedOptional(); // Returns true when the tile source has received a first response, regardless of whether a load |