summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmake/core-files.cmake1
-rw-r--r--include/mbgl/map/map.hpp1
-rw-r--r--include/mbgl/map/query.hpp11
-rw-r--r--include/mbgl/style/query.hpp24
-rw-r--r--include/mbgl/style/source.hpp3
-rw-r--r--platform/android/src/style/sources/geojson_source.cpp6
-rw-r--r--platform/android/src/style/sources/vector_source.cpp7
-rw-r--r--platform/darwin/src/MGLShapeSource.mm5
-rw-r--r--platform/darwin/src/MGLSource.mm4
-rw-r--r--platform/darwin/src/MGLSource_Private.h8
-rw-r--r--platform/darwin/src/MGLVectorSource.mm7
-rw-r--r--src/mbgl/map/map.cpp11
-rw-r--r--src/mbgl/style/source.cpp4
-rw-r--r--src/mbgl/style/source_impl.cpp1
-rw-r--r--src/mbgl/style/source_impl.hpp2
-rw-r--r--src/mbgl/tile/geojson_tile.cpp4
-rw-r--r--src/mbgl/tile/geojson_tile.hpp2
-rw-r--r--src/mbgl/tile/geometry_tile.cpp3
-rw-r--r--src/mbgl/tile/geometry_tile.hpp4
-rw-r--r--src/mbgl/tile/tile.cpp3
-rw-r--r--src/mbgl/tile/tile.hpp4
-rw-r--r--test/api/query.test.cpp14
-rw-r--r--test/tile/vector_tile.test.cpp2
23 files changed, 70 insertions, 61 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake
index d281872102..d5f7ee0cc2 100644
--- a/cmake/core-files.cmake
+++ b/cmake/core-files.cmake
@@ -286,7 +286,6 @@ set(MBGL_CORE_FILES
include/mbgl/style/light.hpp
include/mbgl/style/position.hpp
include/mbgl/style/property_value.hpp
- include/mbgl/style/query.hpp
include/mbgl/style/source.hpp
include/mbgl/style/transition_options.hpp
include/mbgl/style/types.hpp
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 84ea3104d8..1c0c2c544b 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -194,6 +194,7 @@ public:
// Feature queries
std::vector<Feature> queryRenderedFeatures(const ScreenCoordinate&, const RenderedQueryOptions& options = {});
std::vector<Feature> queryRenderedFeatures(const ScreenBox&, const RenderedQueryOptions& options = {});
+ std::vector<Feature> querySourceFeatures(const std::string& sourceID, const SourceQueryOptions& options = {});
AnnotationIDs queryPointAnnotations(const ScreenBox&);
diff --git a/include/mbgl/map/query.hpp b/include/mbgl/map/query.hpp
index 827424d21d..9fac60d71d 100644
--- a/include/mbgl/map/query.hpp
+++ b/include/mbgl/map/query.hpp
@@ -19,4 +19,15 @@ public:
optional<style::Filter> filter;
};
+/**
+ * Options for query source features
+ */
+class SourceQueryOptions {
+public:
+ // Required for VectorSource, ignored for GeoJSONSource
+ optional<std::vector<std::string>> sourceLayers;
+
+ optional<style::Filter> filter;
+};
+
}
diff --git a/include/mbgl/style/query.hpp b/include/mbgl/style/query.hpp
deleted file mode 100644
index 8cb2545ab4..0000000000
--- a/include/mbgl/style/query.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-
-#include <mbgl/util/optional.hpp>
-#include <mbgl/style/filter.hpp>
-
-#include <string>
-#include <vector>
-
-namespace mbgl {
-namespace style {
-
-/**
- * Options for query source features
- */
-class SourceQueryOptions {
-public:
- // Required for VectorSource, ignored for GeoJSONSource
- optional<std::vector<std::string>> sourceLayers;
-
- optional<style::Filter> filter;
-};
-
-} // namespace style
-} // namespace mbgl
diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp
index f2dfb6a896..e49f1fc273 100644
--- a/include/mbgl/style/source.hpp
+++ b/include/mbgl/style/source.hpp
@@ -6,7 +6,6 @@
#include <mbgl/util/range.hpp>
#include <mbgl/util/any.hpp>
#include <mbgl/style/types.hpp>
-#include <mbgl/style/query.hpp>
#include <memory>
#include <string>
@@ -59,8 +58,6 @@ public:
optional<std::string> getAttribution() const;
optional<Range<uint8_t>> getZoomRange() const;
- std::vector<Feature> querySourceFeatures(const SourceQueryOptions& options = {});
-
// Private implementation
class Impl;
const std::unique_ptr<Impl> baseImpl;
diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp
index c201cdade1..9b56446e31 100644
--- a/platform/android/src/style/sources/geojson_source.cpp
+++ b/platform/android/src/style/sources/geojson_source.cpp
@@ -102,8 +102,10 @@ namespace android {
using namespace mbgl::android::conversion;
using namespace mbgl::android::geojson;
- auto filter = toFilter(env, jfilter);
- auto features = source.querySourceFeatures({ {}, filter });
+ std::vector<mbgl::Feature> features;
+ if (map) {
+ features = map->querySourceFeatures(source.getID(), { {}, toFilter(env, jfilter) });
+ }
return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features);
}
diff --git a/platform/android/src/style/sources/vector_source.cpp b/platform/android/src/style/sources/vector_source.cpp
index 53aa144450..a8f74df142 100644
--- a/platform/android/src/style/sources/vector_source.cpp
+++ b/platform/android/src/style/sources/vector_source.cpp
@@ -40,9 +40,10 @@ namespace android {
using namespace mbgl::android::conversion;
using namespace mbgl::android::geojson;
- mbgl::optional<std::vector<std::string>> sourceLayerIds = { toVector(env, jSourceLayerIds) };
- auto filter = toFilter(env, jfilter);
- auto features = source.querySourceFeatures({ sourceLayerIds, filter });
+ std::vector<mbgl::Feature> features;
+ if (map) {
+ features = map->querySourceFeatures(source.getID(), { toVector(env, jSourceLayerIds), toFilter(env, jfilter) });
+ }
return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features);
}
diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm
index 15437ebedb..023a81bba8 100644
--- a/platform/darwin/src/MGLShapeSource.mm
+++ b/platform/darwin/src/MGLShapeSource.mm
@@ -95,7 +95,10 @@ const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance = @"MGLSh
optionalFilter = predicate.mgl_filter;
}
- std::vector<mbgl::Feature> features = self.rawSource->querySourceFeatures({ {}, optionalFilter });
+ std::vector<mbgl::Feature> features;
+ if (self.mapView) {
+ features = self.mapView.mbglMap->querySourceFeatures(self.rawSource->getID(), { {}, optionalFilter });
+ }
return MGLFeaturesFromMBGLFeatures(features);
}
diff --git a/platform/darwin/src/MGLSource.mm b/platform/darwin/src/MGLSource.mm
index 59c2ae13e6..eb859ba2c0 100644
--- a/platform/darwin/src/MGLSource.mm
+++ b/platform/darwin/src/MGLSource.mm
@@ -10,6 +10,8 @@
// special internal source types like mbgl::AnnotationSource.
@property (nonatomic, readonly) mbgl::style::Source *rawSource;
+@property (nonatomic, readonly, weak) MGLMapView *mapView;
+
@end
@implementation MGLSource {
@@ -48,12 +50,14 @@
"to the style more than once is invalid.", self, mapView.style];
}
+ _mapView = mapView;
mapView.mbglMap->addSource(std::move(_pendingSource));
}
- (void)removeFromMapView:(MGLMapView *)mapView {
if (self.rawSource == mapView.mbglMap->getSource(self.identifier.UTF8String)) {
_pendingSource = mapView.mbglMap->removeSource(self.identifier.UTF8String);
+ _mapView = nil;
}
}
diff --git a/platform/darwin/src/MGLSource_Private.h b/platform/darwin/src/MGLSource_Private.h
index 6f86e4800b..91bfac6390 100644
--- a/platform/darwin/src/MGLSource_Private.h
+++ b/platform/darwin/src/MGLSource_Private.h
@@ -44,6 +44,14 @@ struct SourceWrapper {
@property (nonatomic, readonly) mbgl::style::Source *rawSource;
/**
+ The map view whose style currently contains the source.
+
+ If the source is not currently part of any map view’s style, this property is
+ set to `nil`.
+ */
+@property (nonatomic, readonly, weak) MGLMapView *mapView;
+
+/**
Adds the mbgl source that this object represents to the mbgl map.
Once a mbgl source is added, ownership of the object is transferred to the
diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm
index afce3bad46..5e9f4f4a6e 100644
--- a/platform/darwin/src/MGLVectorSource.mm
+++ b/platform/darwin/src/MGLVectorSource.mm
@@ -3,9 +3,11 @@
#import "MGLFeature_Private.h"
#import "MGLSource_Private.h"
#import "MGLTileSource_Private.h"
+#import "MGLMapView_Private.h"
#import "NSPredicate+MGLAdditions.h"
#import "NSURL+MGLAdditions.h"
+#include <mbgl/map/map.hpp>
#include <mbgl/style/sources/vector_source.hpp>
@interface MGLVectorSource ()
@@ -59,7 +61,10 @@
optionalFilter = predicate.mgl_filter;
}
- std::vector<mbgl::Feature> features = self.rawSource->querySourceFeatures({ optionalSourceLayerIDs, optionalFilter });
+ std::vector<mbgl::Feature> features;
+ if (self.mapView) {
+ features = self.mapView.mbglMap->querySourceFeatures(self.rawSource->getID(), { optionalSourceLayerIDs, optionalFilter });
+ }
return MGLFeaturesFromMBGLFeatures(features);
}
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index b5a1af172a..696dca1872 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -7,7 +7,7 @@
#include <mbgl/map/transform_state.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/style/style.hpp>
-#include <mbgl/style/source.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/layer.hpp>
#include <mbgl/style/light.hpp>
#include <mbgl/style/observer.hpp>
@@ -868,6 +868,15 @@ std::vector<Feature> Map::queryRenderedFeatures(const ScreenBox& box, const Rend
);
}
+std::vector<Feature> Map::querySourceFeatures(const std::string& sourceID, const SourceQueryOptions& options) {
+ if (!impl->style) return {};
+
+ const style::Source* source = impl->style->getSource(sourceID);
+ if (!source) return {};
+
+ return source->baseImpl->querySourceFeatures(options);
+}
+
AnnotationIDs Map::queryPointAnnotations(const ScreenBox& box) {
RenderedQueryOptions options;
options.layerIDs = {{ AnnotationManager::PointLayerID }};
diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp
index f10fc6916b..51863f8eba 100644
--- a/src/mbgl/style/source.cpp
+++ b/src/mbgl/style/source.cpp
@@ -22,9 +22,5 @@ optional<Range<uint8_t>> Source::getZoomRange() const {
return baseImpl->getZoomRange();
}
-std::vector<Feature> Source::querySourceFeatures(const SourceQueryOptions& options) {
- return baseImpl->querySourceFeatures(options);
-}
-
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp
index 7a65dd1ded..19138bd781 100644
--- a/src/mbgl/style/source_impl.cpp
+++ b/src/mbgl/style/source_impl.cpp
@@ -10,7 +10,6 @@
#include <mbgl/util/tile_cover.hpp>
#include <mbgl/util/enum.hpp>
#include <mbgl/map/query.hpp>
-#include <mbgl/style/query.hpp>
#include <mbgl/algorithm/update_renderables.hpp>
#include <mbgl/algorithm/generate_clip_ids.hpp>
diff --git a/src/mbgl/style/source_impl.hpp b/src/mbgl/style/source_impl.hpp
index 387428ec59..132d1b97f8 100644
--- a/src/mbgl/style/source_impl.hpp
+++ b/src/mbgl/style/source_impl.hpp
@@ -7,7 +7,7 @@
#include <mbgl/tile/tile.hpp>
#include <mbgl/tile/tile_cache.hpp>
#include <mbgl/style/types.hpp>
-#include <mbgl/style/query.hpp>
+#include <mbgl/map/query.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/mat4.hpp>
diff --git a/src/mbgl/tile/geojson_tile.cpp b/src/mbgl/tile/geojson_tile.cpp
index 00e10d148a..f989bc2ce6 100644
--- a/src/mbgl/tile/geojson_tile.cpp
+++ b/src/mbgl/tile/geojson_tile.cpp
@@ -1,6 +1,6 @@
#include <mbgl/tile/geojson_tile.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
-#include <mbgl/style/query.hpp>
+#include <mbgl/map/query.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/update_parameters.hpp>
@@ -98,7 +98,7 @@ void GeoJSONTile::setNecessity(Necessity) {}
void GeoJSONTile::querySourceFeatures(
std::vector<Feature>& result,
- const style::SourceQueryOptions& options) {
+ const SourceQueryOptions& options) {
// Ignore the sourceLayer, there is only one
auto layer = getData()->getLayer({});
diff --git a/src/mbgl/tile/geojson_tile.hpp b/src/mbgl/tile/geojson_tile.hpp
index e1d269a9a7..f8cde75106 100644
--- a/src/mbgl/tile/geojson_tile.hpp
+++ b/src/mbgl/tile/geojson_tile.hpp
@@ -21,7 +21,7 @@ public:
void querySourceFeatures(
std::vector<Feature>& result,
- const style::SourceQueryOptions&) override;
+ const SourceQueryOptions&) override;
};
} // namespace mbgl
diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp
index 6b768d9d5b..6ac4a2e3aa 100644
--- a/src/mbgl/tile/geometry_tile.cpp
+++ b/src/mbgl/tile/geometry_tile.cpp
@@ -18,7 +18,6 @@
#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>
#include <iostream>
@@ -191,7 +190,7 @@ void GeometryTile::queryRenderedFeatures(
void GeometryTile::querySourceFeatures(
std::vector<Feature>& result,
- const style::SourceQueryOptions& options) {
+ const SourceQueryOptions& options) {
// Data not yet available
if (!data) {
diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp
index 8aedd67060..227e774e9d 100644
--- a/src/mbgl/tile/geometry_tile.hpp
+++ b/src/mbgl/tile/geometry_tile.hpp
@@ -19,11 +19,11 @@ class GeometryTileData;
class FeatureIndex;
class CollisionTile;
class RenderLayer;
+class SourceQueryOptions;
namespace style {
class Style;
class UpdateParameters;
-class SourceQueryOptions;
} // namespace style
class GeometryTile : public Tile, public GlyphRequestor, IconRequestor {
@@ -58,7 +58,7 @@ public:
void querySourceFeatures(
std::vector<Feature>& result,
- const style::SourceQueryOptions&) override;
+ const SourceQueryOptions&) override;
void cancel() override;
diff --git a/src/mbgl/tile/tile.cpp b/src/mbgl/tile/tile.cpp
index 4fb8331aeb..0adc151a64 100644
--- a/src/mbgl/tile/tile.cpp
+++ b/src/mbgl/tile/tile.cpp
@@ -4,7 +4,6 @@
#include <mbgl/util/string.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/map/query.hpp>
-#include <mbgl/style/query.hpp>
namespace mbgl {
@@ -38,6 +37,6 @@ void Tile::queryRenderedFeatures(
void Tile::querySourceFeatures(
std::vector<Feature>&,
- const style::SourceQueryOptions&) {}
+ const SourceQueryOptions&) {}
} // namespace mbgl
diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp
index 6c2c78967f..795fd62140 100644
--- a/src/mbgl/tile/tile.hpp
+++ b/src/mbgl/tile/tile.hpp
@@ -22,10 +22,10 @@ class TransformState;
class TileObserver;
class PlacementConfig;
class RenderedQueryOptions;
+class SourceQueryOptions;
class RenderLayer;
namespace style {
-class SourceQueryOptions;
} // namespace style
class Tile : private util::noncopyable {
@@ -60,7 +60,7 @@ public:
virtual void querySourceFeatures(
std::vector<Feature>& result,
- const style::SourceQueryOptions&);
+ const SourceQueryOptions&);
void setTriedOptional();
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index 77dc095484..c509753d2d 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -86,7 +86,7 @@ TEST(Query, QueryRenderedFeaturesFilter) {
TEST(Query, QuerySourceFeatures) {
QueryTest test;
- auto features1 = test.map.getSource("source3")->querySourceFeatures();
+ auto features1 = test.map.querySourceFeatures("source3");
EXPECT_EQ(features1.size(), 1u);
}
@@ -94,15 +94,15 @@ TEST(Query, QuerySourceFeaturesOptionValidation) {
QueryTest test;
// GeoJSONSource, doesn't require a layer id
- auto features = test.map.getSource("source3")->querySourceFeatures();
+ auto features = test.map.querySourceFeatures("source3");
ASSERT_EQ(features.size(), 1u);
// VectorSource, requires a layer id
- features = test.map.getSource("source5")->querySourceFeatures();
+ features = test.map.querySourceFeatures("source5");
ASSERT_EQ(features.size(), 0u);
// RasterSource, not supported
- features = test.map.getSource("source6")->querySourceFeatures();
+ features = test.map.querySourceFeatures("source6");
ASSERT_EQ(features.size(), 0u);
}
@@ -110,15 +110,15 @@ TEST(Query, QuerySourceFeaturesFilter) {
QueryTest test;
const EqualsFilter eqFilter = { "key1", std::string("value1") };
- auto features1 = test.map.getSource("source4")->querySourceFeatures({{}, { eqFilter }});
+ auto features1 = test.map.querySourceFeatures("source4", {{}, { eqFilter }});
EXPECT_EQ(features1.size(), 1u);
const IdentifierNotEqualsFilter idNotEqFilter = { std::string("feature1") };
- auto features2 = test.map.getSource("source4")->querySourceFeatures({{}, { idNotEqFilter }});
+ auto features2 = test.map.querySourceFeatures("source4", {{}, { idNotEqFilter }});
EXPECT_EQ(features2.size(), 0u);
const GreaterThanFilter gtFilter = { "key2", 1.0 };
- auto features3 = test.map.getSource("source4")->querySourceFeatures({{}, { gtFilter }});
+ auto features3 = test.map.querySourceFeatures("source4", {{}, { gtFilter }});
EXPECT_EQ(features3.size(), 1u);
}
diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp
index 26c5dac8c0..15d437c361 100644
--- a/test/tile/vector_tile.test.cpp
+++ b/test/tile/vector_tile.test.cpp
@@ -6,8 +6,8 @@
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/map/transform.hpp>
+#include <mbgl/map/query.hpp>
#include <mbgl/style/style.hpp>
-#include <mbgl/style/query.hpp>
#include <mbgl/style/update_parameters.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/renderer/symbol_bucket.hpp>