summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2018-06-28 11:27:04 +0200
committertobrun <tobrun.van.nuland@gmail.com>2018-06-28 11:27:04 +0200
commit9d702a806fba61cfbead347ec87373749a435f97 (patch)
tree80e02a0f90a4138d75306725819540761ac73977
parenteabf209bad80634e1dd4fbe7784408ee7d332c5a (diff)
downloadqtlocation-mapboxgl-upstream/tvn-query-snapshot-wip.tar.gz
[android] [core] - add query rendered features to map snapshotupstream/tvn-query-snapshot-wip
-rw-r--r--platform/android/src/snapshotter/map_snapshot.cpp26
-rw-r--r--platform/android/src/snapshotter/map_snapshot.hpp12
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.cpp4
-rw-r--r--platform/default/mbgl/gl/headless_frontend.cpp2
-rw-r--r--platform/default/mbgl/gl/headless_frontend.hpp3
-rw-r--r--platform/default/mbgl/map/map_snapshotter.cpp6
-rw-r--r--platform/default/mbgl/map/map_snapshotter.hpp4
7 files changed, 51 insertions, 6 deletions
diff --git a/platform/android/src/snapshotter/map_snapshot.cpp b/platform/android/src/snapshotter/map_snapshot.cpp
index f5092b3c56..1e86586ad3 100644
--- a/platform/android/src/snapshotter/map_snapshot.cpp
+++ b/platform/android/src/snapshotter/map_snapshot.cpp
@@ -2,6 +2,9 @@
#include "../bitmap.hpp"
#include "../jni/collection.hpp"
+#include "../geojson/feature.hpp"
+#include "../conversion/collection.hpp"
+#include "../style/conversion/filter.hpp"
#include <memory>
@@ -20,6 +23,20 @@ jni::Object<PointF> MapSnapshot::pixelForLatLng(jni::JNIEnv& env, jni::Object<La
return PointF::New(env, point.x * pixelRatio, point.y * pixelRatio);
}
+jni::Array<jni::Object<geojson::Feature>> MapSnapshot::queryRenderedFeaturesForPoint(JNIEnv& env, jni::jfloat x, jni::jfloat y,
+ jni::Array<jni::String> layerIds,
+ jni::Array<jni::Object<>> jfilter) {
+ using namespace mbgl::android::conversion;
+ using namespace mbgl::android::geojson;
+
+ mbgl::optional<std::vector<std::string>> layers;
+ if (layerIds != nullptr && layerIds.Length(env) > 0) {
+ layers = android::conversion::toVector(env, layerIds);
+ }
+ mapbox::geometry::point<double> point = {x, y};
+ std::vector<mbgl::Feature> features = queryPointForFn(point, {layers, toFilter(env, jfilter)});
+ return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features);
+}
// Static methods //
@@ -28,13 +45,14 @@ jni::Object<MapSnapshot> MapSnapshot::New(JNIEnv& env,
float pixelRatio,
std::vector<std::string> attributions,
bool showLogo,
- mbgl::MapSnapshotter::PointForFn pointForFn) {
+ mbgl::MapSnapshotter::PointForFn pointForFn,
+ mbgl::MapSnapshotter::QueryPointForFn queryPointForFn) {
// Create the bitmap
auto bitmap = Bitmap::CreateBitmap(env, std::move(image));
// Create the Mapsnapshot peers
static auto constructor = javaClass.GetConstructor<jni::jlong, jni::Object<Bitmap>, jni::Array<jni::String>, jni::jboolean>(env);
- auto nativePeer = std::make_unique<MapSnapshot>(pixelRatio, pointForFn);
+ auto nativePeer = std::make_unique<MapSnapshot>(pixelRatio, pointForFn, queryPointForFn);
return javaClass.New(env, constructor, reinterpret_cast<jlong>(nativePeer.release()), bitmap, jni::Make<jni::Array<jni::String>>(env, attributions), (jni::jboolean) showLogo);
}
@@ -52,7 +70,9 @@ void MapSnapshot::registerNative(jni::JNIEnv& env) {
std::make_unique<MapSnapshot, JNIEnv&>,
"initialize",
"finalize",
- METHOD(&MapSnapshot::pixelForLatLng, "pixelForLatLng")
+ METHOD(&MapSnapshot::pixelForLatLng, "pixelForLatLng"),
+ METHOD(&MapSnapshot::queryRenderedFeaturesForPoint, "queryRenderedFeaturesForPoint")//,
+// METHOD(&MapSnapshot::queryRenderedFeaturesForBox, "queryRenderedFeaturesForPoint")
);
}
diff --git a/platform/android/src/snapshotter/map_snapshot.hpp b/platform/android/src/snapshotter/map_snapshot.hpp
index 4673dcd16e..3393d66317 100644
--- a/platform/android/src/snapshotter/map_snapshot.hpp
+++ b/platform/android/src/snapshotter/map_snapshot.hpp
@@ -6,6 +6,7 @@
#include "../geometry/lat_lng.hpp"
#include "../graphics/pointf.hpp"
+#include "../geojson/feature.hpp"
#include <vector>
#include <string>
@@ -17,6 +18,7 @@ class MapSnapshot {
public:
using PointForFn = mbgl::MapSnapshotter::PointForFn;
+ using QueryPointForFn = mbgl::MapSnapshotter::QueryPointForFn;
static constexpr auto Name() { return "com/mapbox/mapboxsdk/snapshotter/MapSnapshot"; };
@@ -27,19 +29,27 @@ public:
float pixelRatio,
std::vector<std::string> attributions,
bool showLogo,
- PointForFn pointForFn);
+ PointForFn pointForFn,
+ QueryPointForFn queryPointForFn);
MapSnapshot(jni::JNIEnv&) {};
MapSnapshot(float pixelRatio, PointForFn);
~MapSnapshot();
jni::Object<PointF> pixelForLatLng(jni::JNIEnv&, jni::Object<LatLng>);
+ jni::Array<jni::Object<geojson::Feature>> queryRenderedFeaturesForPoint(JNIEnv&, jni::jfloat, jni::jfloat,
+ jni::Array<jni::String>,
+ jni::Array<jni::Object<>> jfilter);
+// jni::Array<jni::Object<geojson::Feature>> queryRenderedFeaturesForBox(JNIEnv&, jni::jfloat, jni::jfloat, jni::jfloat,
+// jni::jfloat, jni::Array<jni::String>,
+// jni::Array<jni::Object<>> jfilter);
private:
static jni::Class<MapSnapshot> javaClass;
float pixelRatio;
mbgl::MapSnapshotter::PointForFn pointForFn;
+ mbgl::MapSnapshotter::QueryPointForFn queryPointForFn;
};
} // namespace android
diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp
index 155fdf81fb..e0e7de5263 100644
--- a/platform/android/src/snapshotter/map_snapshotter.cpp
+++ b/platform/android/src/snapshotter/map_snapshotter.cpp
@@ -77,7 +77,7 @@ void MapSnapshotter::start(JNIEnv& env) {
snapshotCallback = std::make_unique<Actor<mbgl::MapSnapshotter::Callback>>(
*Scheduler::GetCurrent(),
- [this](std::exception_ptr err, PremultipliedImage image, std::vector<std::string> attributions, mbgl::MapSnapshotter::PointForFn pointForFn) {
+ [this](std::exception_ptr err, PremultipliedImage image, std::vector<std::string> attributions, mbgl::MapSnapshotter::PointForFn pointForFn, mbgl::MapSnapshotter::QueryPointForFn queryPointForFn) {
MBGL_VERIFY_THREAD(tid);
android::UniqueEnv _env = android::AttachEnv();
@@ -89,7 +89,7 @@ void MapSnapshotter::start(JNIEnv& env) {
jni::DeleteLocalRef(*_env, message);
} else {
// Create the wrapper
- auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, attributions, showLogo, pointForFn);
+ auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, attributions, showLogo, pointForFn, queryPointForFn);
// invoke callback
static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<MapSnapshot>)>(*_env, "onSnapshotReady");
diff --git a/platform/default/mbgl/gl/headless_frontend.cpp b/platform/default/mbgl/gl/headless_frontend.cpp
index 4263d2b148..d8d316ad4f 100644
--- a/platform/default/mbgl/gl/headless_frontend.cpp
+++ b/platform/default/mbgl/gl/headless_frontend.cpp
@@ -91,6 +91,8 @@ optional<TransformState> HeadlessFrontend::getTransformState() const {
} else {
return {};
}
+
+
}
} // namespace mbgl
diff --git a/platform/default/mbgl/gl/headless_frontend.hpp b/platform/default/mbgl/gl/headless_frontend.hpp
index 8ae617d37b..8bc0edcb4a 100644
--- a/platform/default/mbgl/gl/headless_frontend.hpp
+++ b/platform/default/mbgl/gl/headless_frontend.hpp
@@ -7,6 +7,8 @@
#include <mbgl/util/optional.hpp>
#include <memory>
+#include <mbgl/renderer/query.hpp>
+#include <mbgl/util/geo.hpp>
namespace mbgl {
@@ -37,6 +39,7 @@ public:
PremultipliedImage render(Map&);
optional<TransformState> getTransformState() const;
+ std::vector<Feature> queryRenderedFeatures(const ScreenCoordinate&, const RenderedQueryOptions&) const;
private:
Size size;
diff --git a/platform/default/mbgl/map/map_snapshotter.cpp b/platform/default/mbgl/map/map_snapshotter.cpp
index a909e3fe9b..0c5c4c8d48 100644
--- a/platform/default/mbgl/map/map_snapshotter.cpp
+++ b/platform/default/mbgl/map/map_snapshotter.cpp
@@ -85,6 +85,12 @@ void MapSnapshotter::Impl::snapshot(ActorRef<MapSnapshotter::Callback> callback)
return transform.latLngToScreenCoordinate(unwrappedLatLng);
}};
+ assert (frontend.getRenderer());
+ QueryPointForFn queryPointForFn { [=] (const mapbox::geometry::point<double>& point,
+ const RenderedQueryOptions& renderedQueryOptions){
+ return frontend.getRenderer()->queryRenderedFeatures({point.x, point.y}, renderedQueryOptions);
+ }};
+
// Collect all source attributions
std::vector<std::string> attributions;
for (auto source : map.getStyle().getSources()) {
diff --git a/platform/default/mbgl/map/map_snapshotter.hpp b/platform/default/mbgl/map/map_snapshotter.hpp
index b9e6307664..a633a4b16c 100644
--- a/platform/default/mbgl/map/map_snapshotter.hpp
+++ b/platform/default/mbgl/map/map_snapshotter.hpp
@@ -10,6 +10,8 @@
#include <string>
#include <vector>
#include <functional>
+#include <mbgl/util/feature.hpp>
+#include <mbgl/renderer/query.hpp>
namespace mbgl {
@@ -52,6 +54,8 @@ public:
LatLngBounds getRegion() const;
using PointForFn = std::function<ScreenCoordinate (const LatLng&)>;
+ using QueryPointForFn = std::function<std::vector<mbgl::Feature> (const mapbox::geometry::point<double>&,
+ const RenderedQueryOptions&)>;
using Attributions = std::vector<std::string>;
using Callback = std::function<void (std::exception_ptr, PremultipliedImage, Attributions, PointForFn)>;
void snapshot(ActorRef<Callback>);