summaryrefslogtreecommitdiff
path: root/platform/android/src/style/layers/layer.cpp
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2018-03-19 15:11:17 +0100
committerGitHub <noreply@github.com>2018-03-19 15:11:17 +0100
commitf0110350176e48e4ee2bac7a923287444f85dbea (patch)
tree564f73fb0e3e1784d00e3b7acbe0dd311c2f9161 /platform/android/src/style/layers/layer.cpp
parentc5075e33ec1c5024da5d583717c1626f8f243f24 (diff)
downloadqtlocation-mapboxgl-f0110350176e48e4ee2bac7a923287444f85dbea.tar.gz
Expression filters (#11429)
* [android] - add expression filter integration
Diffstat (limited to 'platform/android/src/style/layers/layer.cpp')
-rw-r--r--platform/android/src/style/layers/layer.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/platform/android/src/style/layers/layer.cpp b/platform/android/src/style/layers/layer.cpp
index 29530879a5..a2f4087fce 100644
--- a/platform/android/src/style/layers/layer.cpp
+++ b/platform/android/src/style/layers/layer.cpp
@@ -25,6 +25,8 @@
// C++ -> Java conversion
#include "../conversion/property_value.hpp"
+#include <mbgl/style/filter.hpp>
+#include "../conversion/gson.hpp"
#include <string>
@@ -134,6 +136,39 @@ namespace android {
layer.accept(SetFilterEvaluator {std::move(*converted)});
}
+ struct GetFilterEvaluator {
+ mbgl::style::Filter noop(std::string layerType) {
+ Log::Warning(mbgl::Event::JNI, "%s doesn't support filter", layerType.c_str());
+ return {};
+ }
+
+ mbgl::style::Filter operator()(style::BackgroundLayer&) { return noop("BackgroundLayer"); }
+ mbgl::style::Filter operator()(style::CustomLayer&) { return noop("CustomLayer"); }
+ mbgl::style::Filter operator()(style::RasterLayer&) { return noop("RasterLayer"); }
+ mbgl::style::Filter operator()(style::HillshadeLayer&) { return noop("HillshadeLayer"); }
+
+ template <class LayerType>
+ mbgl::style::Filter operator()(LayerType& layer) {
+ return layer.getFilter();
+ }
+ };
+
+ jni::Object<gson::JsonArray> Layer::getFilter(jni::JNIEnv& env) {
+ using namespace mbgl::style;
+ using namespace mbgl::style::conversion;
+
+ Filter filter = layer.accept(GetFilterEvaluator());
+
+ jni::jobject* converted = nullptr;
+ if (filter.is<ExpressionFilter>()) {
+ ExpressionFilter filterExpression = filter.get<ExpressionFilter>();
+ mbgl::Value expressionValue = filterExpression.expression.get()->serialize();
+ conversion::JsonEvaluator jsonEvaluator{env};
+ converted = apply_visitor(jsonEvaluator, expressionValue);
+ }
+ return jni::Object<gson::JsonArray>(converted);
+ }
+
struct SetSourceLayerEvaluator {
std::string sourceLayer;
@@ -208,6 +243,7 @@ namespace android {
METHOD(&Layer::setLayoutProperty, "nativeSetLayoutProperty"),
METHOD(&Layer::setPaintProperty, "nativeSetPaintProperty"),
METHOD(&Layer::setFilter, "nativeSetFilter"),
+ METHOD(&Layer::getFilter, "nativeGetFilter"),
METHOD(&Layer::setSourceLayer, "nativeSetSourceLayer"),
METHOD(&Layer::getSourceLayer, "nativeGetSourceLayer"),
METHOD(&Layer::getMinZoom, "nativeGetMinZoom"),