From aa4cc2dd58f504ba5eba95e43950bbea488ea1dd Mon Sep 17 00:00:00 2001 From: tobrun Date: Mon, 8 Jan 2018 14:03:02 +0100 Subject: [android] - add expression accessor for layout and paint properties --- .../mapboxsdk/style/layers/PropertyValue.java | 26 ++++++++++++++++++++++ .../activity/style/SymbolGeneratorActivity.java | 5 +++++ .../src/style/conversion/property_value.hpp | 6 ++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java index a57c440df4..44f58a54c2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java @@ -5,6 +5,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.mapbox.mapboxsdk.exceptions.ConversionException; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.functions.Function; import com.mapbox.mapboxsdk.utils.ColorUtils; @@ -57,6 +58,31 @@ public class PropertyValue { return !isNull() && !isFunction(); } + /** + * Returns if this is a expression. + * + * @return true if is a expression, false if not + */ + public boolean isExpression() { + return !isNull() && value instanceof Expression; + } + + /** + * Get the expression of the property. + * + * @return the expression value + */ + @Nullable + public Expression getExpression() { + if (isExpression()) { + // noinspection unchecked + return (Expression) value; + } else { + Timber.e("not an expression, try value"); + return null; + } + } + @Nullable public Function getFunction() { if (isFunction()) { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java index 1ef59db9b1..fe0001f38f 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java @@ -269,6 +269,11 @@ public class SymbolGeneratorActivity extends AppCompatActivity implements OnMapR ) ); + // debug log getters + SymbolLayer symbolLayer = mapboxMap.getLayerAs(LAYER_ID); + Timber.e("Property value for %s: %s","iconImage", symbolLayer.getIconImage().getExpression()); + Timber.e("Property value for %s: %s","iconAllowOverlap", symbolLayer.getIconAllowOverlap().getValue()); + new GenerateSymbolTask(mapboxMap, this).execute(featureCollection); } diff --git a/platform/android/src/style/conversion/property_value.hpp b/platform/android/src/style/conversion/property_value.hpp index a58cf975a7..5498faaf0a 100644 --- a/platform/android/src/style/conversion/property_value.hpp +++ b/platform/android/src/style/conversion/property_value.hpp @@ -38,7 +38,11 @@ public: } jni::jobject* operator()(const mbgl::style::CompositeFunction &value) const { - return *convert>(env, value); + return *convert>(env, value); + } + + jni::jobject*operator()(const mbgl::style::expression::Expression &value) const { + return *convert(env, value); } private: -- cgit v1.2.1