summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2018-08-29 18:28:51 +0200
committerTobrun <tobrun@mapbox.com>2018-09-04 18:21:36 +0200
commite4bcd1abed607117b21fa518782a694873d0686b (patch)
treecde30e8ac98d826fe0da834996c326710ded5f3a
parent3f021970ea31a5dadeafd197c1b62f22591aae3d (diff)
downloadqtlocation-mapboxgl-e4bcd1abed607117b21fa518782a694873d0686b.tar.gz
[android] - provide correct expression integration for newly created property values
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java6
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java14
2 files changed, 18 insertions, 2 deletions
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 a38f810f1c..fe6d510a53 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
@@ -46,7 +46,7 @@ public class PropertyValue<T> {
* @return true if this is a expression, false if not
*/
public boolean isExpression() {
- return !isNull() && value instanceof JsonArray;
+ return !isNull() && (value instanceof JsonArray || value instanceof Expression);
}
/**
@@ -57,7 +57,9 @@ public class PropertyValue<T> {
@Nullable
public Expression getExpression() {
if (isExpression()) {
- return Expression.Converter.convert((JsonArray) value);
+ return value instanceof JsonArray
+ ? Expression.Converter.convert((JsonArray) value)
+ : (Expression) value;
} else {
Logger.w(TAG, "not a expression, try value");
return null;
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java
index b38026a572..054d9da8af 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java
@@ -4,6 +4,7 @@ import android.graphics.Color;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
+import com.mapbox.mapboxsdk.style.layers.PropertyValue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -87,6 +88,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.upcase;
import static com.mapbox.mapboxsdk.style.expressions.Expression.var;
import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity;
+import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
@@ -97,6 +99,18 @@ import static org.junit.Assert.assertEquals;
public class ExpressionTest {
@Test
+ public void testPropertyValueIsExpression() {
+ PropertyValue<?> property = lineWidth(Expression.get("width"));
+ assertTrue(property.isExpression());
+ }
+
+ @Test
+ public void testPropertyValueEqualsExpression() {
+ PropertyValue<?> property = lineWidth(Expression.get("width"));
+ assertEquals(Expression.get("width"), property.getExpression());
+ }
+
+ @Test
public void testRgb() throws Exception {
Object[] expected = new Object[] {"rgb", 0f, 0f, 0f};
Object[] actual = rgb(literal(0), literal(0), literal(0)).toArray();